: Is there a better way of getting the dialog handle, than using
GetActiveWindow()?
:
: Thanks again for your help, I'm grateful!
:
Well, if you pass an HWND which came into your dialog procedure in every function you write then you get your HDLG everywhere without calling 'GetActiveWindow()' - it can cause problems when you do some background processing in your dialog, but in some moment you switch to another task - it will give you the HWND of the window in that task instead of your dialog...
void InitControls (HWND hDlg)
{
}
void WmCommand (HWND hDlg, WORD wControlID, WORD wNotification)
{
}
BOOL CALLBACK MyDlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp)
{
switch (msg) {
case WM_INITDIALOG:
InitControls (hDlg);
break;
case WM_COMMAND:
WmCommand (hDlg, LOWORD (wp), HIWORD (wp));
break;
default:
return FALSE;
}
return TRUE;
}
Another way is to make it global for only this source file when it comes in WM_INITDIALOG:
static HWND st_hDlg;
BOOL CALLBACK MyDlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp)
{
...
case WM_INITDIALOG:
st_hDlg = hDlg;
break;
...
}
But it can cause problems in case you have two of these dialogs running as modeless...