Click here to Skip to main content
15,906,303 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralFile Dialog Problem Pin
San27-Nov-01 20:11
San27-Nov-01 20:11 
GeneralRe: File Dialog Problem Pin
Eugene Pustovoyt27-Nov-01 21:13
Eugene Pustovoyt27-Nov-01 21:13 
QuestionCan somebody help me? Pin
Karavaev Denis27-Nov-01 19:51
Karavaev Denis27-Nov-01 19:51 
AnswerRe: Can somebody help me? Pin
Christian Graus27-Nov-01 23:40
protectorChristian Graus27-Nov-01 23:40 
GeneralRe: Can somebody help me? Pin
Karavaev Denis28-Nov-01 0:03
Karavaev Denis28-Nov-01 0:03 
GeneralRe: Can somebody help me? Pin
Nish Nishant28-Nov-01 0:25
sitebuilderNish Nishant28-Nov-01 0:25 
GeneralRe: Can somebody help me? Pin
Christian Graus28-Nov-01 1:47
protectorChristian Graus28-Nov-01 1:47 
GeneralRe: Can somebody help me? Pin
Christian Graus28-Nov-01 0:31
protectorChristian Graus28-Nov-01 0:31 
Karavaev Denis wrote:
how do you think, if I'll be on this forum if I can't create a dialog box?

Well, you *did* say Unfortunly, I know C++ to bad to compile it myself.. You'd be amazed at some of the questions we get around here. Most are intelligent but some are just out of control.

C1004 means you either didn't put a final bracket, or you didn't include stdafx.h. The missing bracket is at the end. The HANDLE parameter should be a HKEY. Where the code checks if retValue == ERROR_SUCCESS, it should check for != ERROR_NO_MORE_ITEMS. Where it passes in MAX_PATH to RegEnumValues, it should set a DWORD to = MAX_PATH, pass in a pointer to that variable, and reset the variable to MAX_PATH. I think that was all, but my code follows to make sure. This smaple is SCREWED.

#define MAX_VALUE_NAME 255

// QueryKey - enumerates the subkeys of a given key and the associated 
//    values and then copies the information about the keys and values 
//    into a pair of edit controls and list boxes. 
// hDlg - dialog box that contains the edit controls and list boxes 
// hKey - key whose subkeys and values are to be enumerated 
 
VOID QueryKey(HWND hDlg, HKEY hKey) 
{ 
    CHAR     achKey[MAX_PATH]; 
    CHAR     achClass[MAX_PATH] = "";  // buffer for class name 
    DWORD    cchClassName = MAX_PATH;  // length of class string 
    DWORD    cSubKeys;                 // number of subkeys 
    DWORD    cbMaxSubKey;              // longest subkey size 
    DWORD    cchMaxClass;              // longest class string 
    DWORD    cValues;              // number of values for key 
    DWORD    cchMaxValue;          // longest value name 
    DWORD    cbMaxValueData;       // longest value data 
    DWORD    cbSecurityDescriptor; // size of security descriptor 
    FILETIME ftLastWriteTime;      // last write time 
 
    DWORD i, j; 
    DWORD retCode, retValue; 
 
    CHAR  achValue[MAX_VALUE_NAME]; 
    DWORD cchValue = MAX_VALUE_NAME; 
    CHAR  achBuff[80]; 
 
    // Get the class name and the value count. 
    RegQueryInfoKey(hKey,        // key handle 
        achClass,                // buffer for class name 
        &cchClassName,           // length of class string 
        NULL,                    // reserved 
        &cSubKeys,               // number of subkeys 
        &cbMaxSubKey,            // longest subkey size 
        &cchMaxClass,            // longest class string 
        &cValues,                // number of values for this key 
        &cchMaxValue,            // longest value name 
        &cbMaxValueData,         // longest value data 
        &cbSecurityDescriptor,   // security descriptor 
        &ftLastWriteTime);       // last write time 
 
//    SetDlgItemText(hDlg, IDE_CLASS, achClass); 
//    SetDlgItemInt(hDlg, IDE_CVALUES, cValues, FALSE); 
 
    SendMessage(GetDlgItem(hDlg, IDL_LISTBOX), 
        LB_ADDSTRING, 0, (LONG) ".."); 

	DWORD dwLength = MAX_PATH;
	
    // Enumerate the child keys, until RegEnumKeyEx fails. Then 
    // get the name of each child key and copy it into the list box. 

    SetCursor(LoadCursor(NULL, IDC_WAIT)); 
    for (i = 0, retCode = ERROR_SUCCESS; 
            retCode != ERROR_NO_MORE_ITEMS; i++) 
    { 
        retCode = RegEnumKeyEx(hKey, 
                     i, 
                     achKey, 
                     &dwLength, 
                     NULL, 
                     NULL, 
                     NULL, 
                     &ftLastWriteTime); 
        if (retCode != (DWORD)ERROR_NO_MORE_ITEMS) 
        {
            SendMessage(GetDlgItem(hDlg, IDL_LISTBOX), 
                LB_ADDSTRING, 0, (LONG) achKey); 
        }

		dwLength = MAX_PATH;
    } 
    SetCursor(LoadCursor (NULL, IDC_ARROW)); 
 
    // Enumerate the key values. 
    SetCursor(LoadCursor(NULL, IDC_WAIT)); 
 
    if (cValues) 
    {
        for (j = 0, retValue = ERROR_SUCCESS; 
                j < cValues; j++) 
        { 
            cchValue = MAX_VALUE_NAME; 
            achValue[0] = '\0'; 
            retValue = RegEnumValue(hKey, j, achValue, 
                &cchValue, 
                NULL, 
                NULL,    // &dwType, 
                NULL,    // &bData, 
                NULL);   // &bcData 
 
            if (retValue != (DWORD) ERROR_SUCCESS && 
                    retValue != ERROR_INSUFFICIENT_BUFFER) 
            { 
                wsprintf (achBuff, 
                    "Line:%d 0 based index = %d, retValue = %d, " 
                     "ValueLen = %d", 
                     __LINE__, j, retValue, cchValue); 
                MessageBox (hDlg, achBuff, "Debug", MB_OK); 
            } 
 
            achBuff[0] = '\0'; 
 
            // Add each value to a list box. 
            if (!lstrlen(achValue)) 
                lstrcpy(achValue, "<NO NAME>"); 
            wsprintf(achBuff, "%d) %s ", j, achValue); 
            SendMessage(GetDlgItem(hDlg,IDL_LISTBOX2), 
                LB_ADDSTRING, 0, (LONG) achBuff); 
        } 
	}
	SetCursor(LoadCursor(NULL, IDC_ARROW)); 
} 


and in OnPaint:

CDialog::OnPaint();
HKEY key;
DWORD result;
RegCreateKeyEx(HKEY_CURRENT_USER, _T("Software"), NULL,
	NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &key, &result);

ASSERT(REG_OPENED_EXISTING_KEY == result);

QueryKey(m_hWnd, key);
RegCloseKey(key);








Christian

After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001

Sonork ID 100.10002:MeanManOz
I live in Bob's HungOut now

GeneralRe: Can somebody help me? Pin
Karavaev Denis28-Nov-01 1:04
Karavaev Denis28-Nov-01 1:04 
GeneralRe: Can somebody help me? Pin
Christian Graus28-Nov-01 1:48
protectorChristian Graus28-Nov-01 1:48 
QuestionIs it safe to handle window messages in a MFC window class derived class? Pin
Nish Nishant27-Nov-01 19:10
sitebuilderNish Nishant27-Nov-01 19:10 
AnswerRe: Is it safe to handle window messages in a MFC window class derived class? Pin
Oliver Anhuth28-Nov-01 0:38
Oliver Anhuth28-Nov-01 0:38 
GeneralRe: Is it safe to handle window messages in a MFC window class derived class? Pin
Nish Nishant28-Nov-01 4:50
sitebuilderNish Nishant28-Nov-01 4:50 
QuestionHow to handle Scroll Bar Poblems Pin
binnu27-Nov-01 18:39
binnu27-Nov-01 18:39 
QuestionHow to handle Scroll Bar Poblems Pin
binnu27-Nov-01 18:39
binnu27-Nov-01 18:39 
GeneralToolTips with variables Pin
Steve L.27-Nov-01 15:59
Steve L.27-Nov-01 15:59 
GeneralRe: ToolTips with variables Pin
Eugene Pustovoyt27-Nov-01 19:40
Eugene Pustovoyt27-Nov-01 19:40 
GeneralAlgorithm for Key Generator Pin
Sam C27-Nov-01 13:00
Sam C27-Nov-01 13:00 
GeneralDesktop patterns and wallpapers retrieval Pin
Benoit Legris27-Nov-01 11:01
Benoit Legris27-Nov-01 11:01 
GeneralRe: Desktop patterns and wallpapers retrieval Pin
Christian Graus27-Nov-01 16:50
protectorChristian Graus27-Nov-01 16:50 
GeneralRe: Desktop patterns and wallpapers retrieval Pin
Nish Nishant27-Nov-01 18:06
sitebuilderNish Nishant27-Nov-01 18:06 
GeneralFOUND :-) Re: Desktop patterns and wallpapers retrieval Pin
Nish Nishant27-Nov-01 18:40
sitebuilderNish Nishant27-Nov-01 18:40 
Generalwallpapers retrieval Pin
Nish Nishant27-Nov-01 18:54
sitebuilderNish Nishant27-Nov-01 18:54 
GeneralCTreeCtrl question Pin
Vu Nguyen27-Nov-01 10:37
Vu Nguyen27-Nov-01 10:37 
GeneralRe: CTreeCtrl question Pin
Brad Bruce27-Nov-01 11:51
Brad Bruce27-Nov-01 11:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.