I am having problems obtaining the owner (parent) of my BrowseForFolder dialog box from within my dialog box callback function. The callback function's hwnd parameter is the handle of the BrowseForFolder dialog box, so I tried using GetParent(hwnd) to obtain the parent of the dialog box but it does not seem to be working.
I made sure to set the hwndOwner member of the BROWSEINFO struct:
setting its owner to the current window.
bi.hwndOwner = hwnd;
bi.pidlRoot = NULL;
bi.pszDisplayName = displayName;
Here is my simple callback function:
I believed that calling GetParent on hwnd would give me the handle for the parent window in which I had called SHBrowseForFolder (the window containing the IDC_GAMEPATHEDIT control I am trying to send a message to); however it did not work at all. To rule out any other conflicts, I passed the parent window handle to the callback function through the lpData param instead and used (HWND)lpData in place GetParent(hwnd), and that worked perfectly. Also, I have used GetParent() successfully in many other dialog boxes.
BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData)
HWND hGamePathEdit = GetDlgItem(GetParent(hwnd), IDC_GAMEPATHEDIT);
char path[SendMessage(hGamePathEdit, WM_GETTEXTLENGTH, 0, 0) + 1];
SendMessage(hGamePathEdit, WM_GETTEXT, (WPARAM)sizeof(path), (LPARAM)path);
SendMessage(hwnd, BFFM_SETSELECTION, (WPARAM)TRUE, (LPARAM)path);
So I guess my question is, why does calling GetParent from within the BrowseForFolder dialog box callback function not return me the handle to the window that initiated the dialog box? What am I doing wrong here??