Click to See Complete Forum and Search --> : Get Dialog Box ID


Gyannea
July 20th, 2005, 02:44 PM
I am trying to get the ID of a dialog box inside the callback function. I figured the following should work:

Upon entry to the dialog callback function:

dlgidd = GetWindowLong(hwindow, GWL_ID); // Get the dialog ID number
if(dlgidd == 0)
{
radioID = GetLastError();
}

But I get the error "Invalid window handle". It happens even if I put it after the WM_INITDIALOG message. I have no problem setting a value (the 'hwindow' value seems okay for the SetWindowLong() function).

Any ideas? I must be doing something VERY stupid!!

I am passing different dialog box templates and I thought this would be a good way to get the ID without placing it as a parameter.

Thanks,

Brian

NoHero
July 20th, 2005, 05:14 PM
Toplevel windows cannot have an ID. A resource ID for dialogs is only used to identify the dialog inside the resource section of an application.

Although GetDlgCtrlID may return a value if hwndCtl is a handle to a top-level window, top-level windows cannot have identifiers and such a return value is never valid.


Check GetDlgCtrlID (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/dialogboxes/dialogboxreference/dialogboxfunctions/getdlgctrlid.asp) on MSDN.
And please use Code Tags next time you post code!

Gyannea
July 21st, 2005, 05:41 AM
RATS! Not what I wanted to hear. Thanks for the info, though!

Brian

Q_leo
July 24th, 2005, 07:36 PM
I think the judgement sentence "dlgidd == 0" is incorrect. The dialog box ID could be 0, like the id of the menu. If you wanna get the handle of the dialog box, you should use the function GetDlgItem();