Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to print out value into the edit box 1

Status
Not open for further replies.

Amulet

Programmer
Sep 29, 2002
19
MY
hi ...
i have this value of this length stored in the REG_BINARY in the registry ... it is this long :
00 00 00 00 00 00 00 00 00 00 .

i cannot display the whole value into the edit box because it is too long, please give suggestions on how to display the complete value into the edit box.. Thank you.
 
Normally, a 29 char string can be displayed in an editbox. Do you have a fixed length string variable attached to your editbox?
How do you try to display that value?
 
hi I'm really new with programming.

I created this program to retrieve a value from a registry by opening a
key, and the

display that value into the edit box. The problem is the value(string)
is
too long (00

00 00 00 00 00 00 00 00 00 ).

here's the code:

********open key*********
#define MY_BUFSIZE 64
char buffer[600];
long lRet;
const MAXLEN = 256;

RegOpenKeyEx(......)
....

lret = RegQueryValueEx(hKey,TEXT("KeyName"),
NULL,NULL,(LPBYTE)szProductType,&dwBufLen);

sprint(buffer,"%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x",
szProductType[0],szProductType[1],szProductType[2],szProductType[3],szProduct

Type[4],szProductType[5],szProductType[6],szProductType[7],szProductType[8],sz

ProductType[9],

m_txtType.SetWindowText(buffer);

****retrieve and display value into the edit box*******


DWORD dwRc=0;
HKEY hKey;
char lpRegKey[MAXLEN];
DWORD dwfLen= MY_BUFSIZE;
lpRegKey[0] = NULL;
strcat(lpRegKey, CALAISREG);
strcat(lpRegKey, "\\");
strcat(lpRegKey, lpKeyName);

dwRc = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
TEXT(lpRegKey),
0,
KEY_ALL_ACCESS,
&hKey);

if (dwRc != NO_ERROR) {
return E_UNEXPECTED;
}


RegQueryValueEx(hKey, "ProductType", 0, NULL,(LPBYTE)szProductType,

&dwBufLen);

CString cProductType;

cProduct.Format(_T("%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x"),

szProductType[0],szProductType[1],szProductType[2],szProductType[3],szProduct

Type[4],szProductType[5],szProductType[6],szProductType[7],szProductType[8],sz

ProductType[9],

m_txtType.SetWindowText(cProductType);

****************************************

This code works, but it only display up to 8 bytes( 00 00 00 00 00 00
00 00
).. how do

i make it display the whole value? is it because of buffer problem?
how do i make it work?
is there any other way to print out the value into the edit box? please
show me.

Suggestions and advices are really appreciated. Thanks.
 
Is m_txtType a CEdit control?
The code you use to display the value has to work. The problem must be something else. Do you use the default settings for the edit control properties(in the resource editor)?
Is your editbox long enough to visualize the whole data?
Have you tried to display in it another long string? Do a test like this:
......
Code:
CString szTemp="00 00 00 00 00 00 00 00 00 00";
// or any other 'long' string
m_txtType.SetWindowText(szTemp);
.......
If it works this way, the problem is not with the edit box, but somewhere in retrieving the data. Have you checked if your buffer contains the whole data you want?

Another way to display the text in the edit box:

Code:
SetDlgItemText(IDC_OF_YOUR_EDITBOX,szTemp);

where IDC_OF_YOUR_EDITBOX is the resource ID of of the editbox. If you use this method you don't need a CEdit variable associated to your control.
 
dear branyesz,

thanx a lot it's working now!! :D
 
dear branyesz,

what if i need to display different strings on the edit box?
i have listed 13 products on the listbox, when i click on the first product(in the listbox), the product's supplier's name will be displayed on the edit box beside it, and the same thing goes when i click on the second product, third, etc.
do i have to use for loop to make the program display the supplier's name for each product on every click?
can u show me how?

i tried using switch and replacesel, but that doesn't work and there were plenty of errors(i have to revise the code).
 
hi there...
i already had the solution for the supplier's name, but unfortunately the numbers(like barcode) are read wrongly(based on the first question). magic numbers/alphabets appears(example: 00 00 00 00 00 00 00 00 cc cc ).
some barcodes are correct, but some barcodes appears with the cc or aa .
where did i go wrong?
 
Maybe the buffer you display is not initialized with the default values (0) before you fill it with the numbers.
Can you show me the code for filling the buffer with the values and displaying it in the editbox?
 
hi there ... here it is.
i realized that some barcodes are longer(10bytes)
like 00 00 00 00 00 00 00 00 00 00
but some are shorter(8bytes)
like 00 00 00 00 00 00 00 00
and there rest of the two bytes appeared to be cc cc in the edit box.
how do i terminate the shorter strings or each string with a null? how
will the program know which barcodes are shorter?
do i have to rewrite everything now?
please help.

****************on OpenKey***********
dwBufLen = MY_BUFSIZE;
DWORD dwRc=0;
BYTE szKeyName[MY_BUFSIZE];
BYTE szBar[MY_BUFSIZE];

dwRc = RegOpenKeyEX(etc etc etc ...)
....
.....
****
/////get supplier's name

RegQueryValueEx(hKey, TEXT("lpRegKey"), 0, NULL, (LPBYTE)szKeyName,
&dwBufLen);

CString szTemp = "F&N";

CListBox *lbProductsNames = (CListBox*) GetDlgItem(IDC_LIST_CARDS);

int iSelected = lbProductsNames->GetCurSel();
lbProductsNames->GetText(iSelected, szTemp);

m_txtName.SetWindowText(szTemp);

UpdateData(FALSE);

///////get barcodes
RegQueryValueEx(hKey, "Bar", 0, NULL, (LPBYTE)szBar, &dwBufLen);

CString cBar;

cBar.Format(_T("%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%"),
szBar[0], szBar[1], szBar[2], szBar[3], szBar[4], szBar[5], szBar[6],
szBar[7]),szBar[8],szBar[9],;

m_txtBar.SetWindowText(cATR);

// Close the registry key.
RegCloseKey( hKey );
return S_OK;
}


void CRegistryProductDlg::OnButtonSelect()
{
// TODO: Add your control notification handler code here


CListBox *lbptr = (CListBox *)GetDlgItem(IDC_LIST_PRODUCT);


int iListIndex;
long lResult = 0;
char cKeyName,cBar;

iListIndex = lbptr->GetCurSel();

if(iListIndex==LB_ERR) {
MessageBox("No Selection.Please select a product.", "Select",
MB_OK|MB_ICONEXCLAMATION);
}
else {
lbptr->GetText(iListIndex, cKeyName);

lResult = OpenKey(cKeyName, cBar);
if (lResult != NO_ERROR){
MessageBox("Open key failed", "Error", MB_OK);
}
else{
HKEY hKey;
TCHAR szProductType[MY_BUFSIZE]; //#define MY_BUFSIZE 64
DWORD dwBufLen = MY_BUFSIZE;
LONG lRet;
char buffer[150];

if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,
TEXT("KeyName"),
0,
KEY_ALL_ACCESS,
&hKey)!= ERROR_SUCCESS)
return;

lRet = RegQueryValueEx(hKey,
TEXT("KeyName"),
NULL,
NULL,
(LPBYTE)szProductType,
&dwBufLen);

sprintf(buffer, "%2x %2x %2x %2x %2x %2x %2x %2x%2x %2x",
szProductType[0], szProductType[1], szProductType[2],
szProductType[3], szProductType[4], szProductType[5],
szProductType[6], szProductType[7], szProductType[8],
szProductType[9]);

//i tried to replace the sprintf with for loop
int len = strlen(szProductType), k = 0;
for(int i = 0; i < len; i++)
{
k += sprintf(buffer+k, &quot;%2x&quot;, szProductType);
}
m_txtProduct.SetWindowText(buffer);

RegCloseKey(hKey);

if(lRet!= ERROR_SUCCESS) return ;
}

}
}


 
Hello, Amulet

The RegQueryValueEx function returns in its last parameter the size of the data actually read (in bytes). So you just have to check this value (in this case dwBufLen) and you know if the barcode is 8 or 10 bytes long.
Try the following modification in the code:
.........
Code:
lRet = RegQueryValueEx(hKey,
                TEXT(&quot;KeyName&quot;),
                NULL,
                NULL,
                (LPBYTE)szProductType,
                &dwBufLen)
//i tried to replace the sprintf with for loop
//int len = strlen(szProductType), k = 0;
k = 0;
for(int i = 0; i < dwBufLen; i++)
{ 
   k += sprintf(buffer+k, &quot;%2x &quot;, szProductType[i]);
}
// replace the last space char with null
buffer[3*dwBufLen-1]=0;
// or buffer[3*dwBufLen-1]='\0'; it is the same
// or buffer[strlen(buffer)-1]=0;
m_txtProduct.SetWindowText(buffer);

Tell me if it helps
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top