|
You cannot cast a short to a string, you need to use a converter such as sprintf() or similar.
The best things in life are not things.
|
|
|
|
|
In addition, _itoa() and similar functions are also there.
|
|
|
|
|
This code only writes the last registry entry to the ComboBox.
*I want to read all the registry entries and insert it to a ComboBox(DropDown List)*
HKEY phkResult = NULL;
LONG enumresult = 0;
TCHAR valuename[256]={0};
BYTE valuedata[4096]={0};
DWORD valuenamesize = sizeof(valuename);
DWORD valuedatasize = sizeof(valuedata);
if (RegOpenKeyEx(HKEY_CURRENT_USER,
"Software\\MY_PROG_KEY",0,KEY_READ,&phkResult) == ERROR_SUCCESS)
{
CCombo* InsCombo;
InsCombo = (CComboBox*) GetDlgItem(IDC_COMBO1);
int index = 0;
do
{
DWORD valuenamesize = sizeof(valuename);
DWORD valuedatasize = sizeof(valuedata);
enumresult=RegEnumValue(phkResult, index, valuename, &valuenamesize, 0,
NULL,
valuedata,
&valuedatasize);
m_ComboStr1=valuedata;
InsCombo->AddString(m_ComboStr1);
UpdateData(FALSE);
index ++;
m_ComboStr1='\0';
}while (enumresult != ERROR_NO_MORE_ITEMS);
RegCloseKey(phkResult);
}
<div class="modified">modified on Wednesday, June 15, 2011 5:21 AM</div>
|
|
|
|
|
It looks like you're misusing UpdateData() in the loop. Remove it, and handle such things after the loop.
|
|
|
|
|
I did that already, but after moving it outside the loop; ComboBox is not showing any string.
|
|
|
|
|
What is the definition of m_ComboStr1 ; also have you checked (with the debugger) that you are getting a valid string from RegEnumValue() ? I note also that you are redeclaring valuenamesize and valuedatasize within your do loop: this is not correct (even though it will not cause problems in this instance). Other than that the code would seem to be correct.
The best things in life are not things.
|
|
|
|
|
This piece of code as you suggested gives following error. Please Suggest.
Previous case : m_ComboStr1 is variable attached to the ComboBox (CString type)
Note: I'm new to VC++ programming.
error C2664: 'AddString' : cannot convert parameter 1 from 'unsigned char' to 'const char *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
HKEY phkResult = NULL;
LONG enumresult = 0;
TCHAR valuename[256]={0};
BYTE valuedata[4096]={0};
DWORD valuenamesize = sizeof(valuename);
DWORD valuedatasize = sizeof(valuedata);
if (RegOpenKeyEx(HKEY_CURRENT_USER,
"Software\\MY_PROG_KEY",0,KEY_READ,&phkResult) == ERROR_SUCCESS)
{
CComboBox* InsCombo;
InsCombo = (CComboBox*) GetDlgItem(IDC_COMBO1);
int index = 0;
do
{
enumresult=RegEnumValue(phkResult, index, valuename, &valuenamesize, 0,
NULL,
valuedata,
&valuedatasize);
InsCombo->AddString(valuedata[index]);
index ++;
}while (enumresult != ERROR_NO_MORE_ITEMS);
RegCloseKey(phkResult);
}
|
|
|
|
|
Well the message is pretty clear; you are passing a character to a function that expects a string (const char* ). Try changing to something of the order of:
InsCombo->AddString(reinterpret_cast<const char*>(valuedata));
The best things in life are not things.
|
|
|
|
|
I appreciate your help.
The same code worked; as I did a silly mistake I needed to increase the drop down area
Thanks
HKEY phkResult = NULL;
LONG enumresult = 0;
TCHAR valuename[256]={0};
BYTE valuedata[4096]={0};
DWORD valuenamesize = sizeof(valuename);
DWORD valuedatasize = sizeof(valuedata);
if (RegOpenKeyEx(HKEY_CURRENT_USER,
"Software\\MY_PROG_KEY",0,KEY_READ,&phkResult) == ERROR_SUCCESS)
{
CComboBox* InsCombo;
InsCombo = (CComboBox*) GetDlgItem(IDC_COMBO1);
int index = 0;
while(RegEnumValue(phkResult, index, valuename, &valuenamesize, 0,
NULL,
valuedata,
&valuedatasize)!=ERROR_NO_MORE_ITEMS)
{
InsCombo->AddString(reinterpret_cast<const char*>(valuedata));
index ++;
}
}
RegCloseKey(phkResult);
return TRUE;
modified on Wednesday, June 15, 2011 5:20 AM
|
|
|
|
|
Gaurav Paul wrote: InsCombo->AddString(reinterpret_cast<const char*>(valuedata[index]));
You should not be using an offset value (valuedata[index] ) but merely the address of the array (valuedata ) as shown in my previous post.
The best things in life are not things.
|
|
|
|
|
I have done that; actually I posted the old code.
|
|
|
|
|
Am I to assume it is now working successfully?
The best things in life are not things.
|
|
|
|
|
Yes it is! Thanks.
|
|
|
|
|
gaurav.paul wrote: UpdateData(FALSE); I wouldn't go any further until this was removed.
gaurav.paul wrote: m_ComboStr1=valuedata; Why the extra variable? AddString() can be called with valuedata .
gaurav.paul wrote: InsCombo->AddString(m_ComboStr1); What is this returning?
gaurav.paul wrote: m_ComboStr1='\0'; What's the purpose of this? It's unnecessary.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Some people are making such thorough preparation for rainy days that they aren't enjoying today's sunshine." - William Feather
|
|
|
|
|
This piece of code as you suggested gives following error. Please Suggest.
Previous case : m_ComboStr1 is variable attached to the ComboBox (CString type)
Note: I'm new to VC++ programming.
error C2664: 'AddString' : cannot convert parameter 1 from 'unsigned char' to 'const char *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
HKEY phkResult = NULL;
LONG enumresult = 0;
TCHAR valuename[256]={0};
BYTE valuedata[4096]={0};
DWORD valuenamesize = sizeof(valuename);
DWORD valuedatasize = sizeof(valuedata);
if (RegOpenKeyEx(HKEY_CURRENT_USER,
"Software\\MY_PROG_KEY",0,KEY_READ,&phkResult) == ERROR_SUCCESS)
{
CComboBox* InsCombo;
InsCombo = (CComboBox*) GetDlgItem(IDC_COMBO1);
int index = 0;
do
{
enumresult=RegEnumValue(phkResult, index, valuename, &valuenamesize, 0,
NULL,
valuedata,
&valuedatasize);
InsCombo->AddString(valuedata[index]);
index ++;
}while (enumresult != ERROR_NO_MORE_ITEMS);
RegCloseKey(phkResult);
}
|
|
|
|
|
Gaurav Paul wrote: InsCombo->AddString(valuedata[index]); This is not what I suggested. Use:
InsCombo->AddString(valuedata);
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Some people are making such thorough preparation for rainy days that they aren't enjoying today's sunshine." - William Feather
|
|
|
|
|
|
I am using text edit box change event to retrieve data from database.
When user types in partial text and the SQL returns only one record I would like to insert that data back to the edit text box with some modifications.
Inserting the data back generates a change event and puts the program in tailspin.
Is it possible to selectively disable the change event?
Thanks for your help.
Vaclav
-- Modified Monday, June 13, 2011 4:49 PM
|
|
|
|
|
1) Yes, if you sent a specfic format ( like only numbers) to the sql
2) The best way is to use different control to be safer side, since this will avoid problems down the road.
HTH
|
|
|
|
|
I would go for setting a flag in the auto complete function, if that's what you're doing, and checking/clearing it in the event handler.
|
|
|
|
|
Thank you Niklas,
what a simple solution. Perfect KISS!
Vaclav
|
|
|
|
|
i want to draw graph using on paint event in activex control application.
Rajesh
|
|
|
|
|
Just Create a Window derived from CCmdTarget in a OCX of your own.
And now u just have OnPaint inside it.
I hope u got the clue needed?
Величие не Бога может быть недооценена.
|
|
|
|
|
See the CIRC tutorials in MSDN. There is one for MFC and one for ATL. Both of them use WM_PAINT to paint a circle.
|
|
|
|
|
Somewhere on net I saw this code,
struct foo {
unsigned int base:19, rehash:13;
};
May I know what is significance of unsigned int base:19, rehash:13; .
Regards
|
|
|
|