How to get the current control from a Dialogbox?

Hi,

I am using WM_NEXTDLGCTL notification to try to get the current control info, the code looks like this:

LRESULT CALLBACK Settings (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_NEXTDLGCTL:
{
CurrentCtl = LOWORD(wParam);
}
break;
.
.
.
.
.

But it didn't work... it seems the dialog procedure doesn't receive this WM_NEXTDLGCTL message..... I just want to know how to get the current control from a dialog box...

Thanks in advance..




Answer this question

How to get the current control from a Dialogbox?

  • steve_h

    Thanks for the reply. But actually, there is no dialog functions related to this functionality, instead, we could use GetFocus(), which is Windows functions to get the current focus....

    Thanks


  • KAAU

    Hi,

    GetFocus returns the handle to the window that has keyboard focus. But this may be a window other that one of the controls on the dialog box, especially if your application has modeless dialogs, but since you plan to update on WM_NEXTDLGCTL message, I think you shall be fine :).

    Thanks.



  • RayClark096

    Hi,

    A look at the methods supported for a default dialog box, suggests that there are no methods exposed to know the currecttly selected control. I don't the way in which you want to use this infromation, but if you must determine the control that has the current focus before you get the WM_NEXTDLGCTL, you can consider handling WM_GETDLGCODE in your control, as this message gets delivered to you control in for any input. You can store the current control ID in some variable that can be accessed from elsewhere.

    If we you can share the reason why you want to do this, we may come up with some other implementation.

    Hopt this helps.

    Thanks



  • sydes141

    Thanks for the reply, but this is not what I meant...for GetDlgItem, you will have to specify which control you want and it is not dynamic....

    I mean, when we use the down key to move to the next dialog control, how can we get the current control ID or Handle assuming we dont know which one is the current control

    Thanks


  • Krad

    Use GetDlgItem function instead. For more details, http://msdn.microsoft.com/library/default.asp url=/library/en-us/winui/winui/windowsuserinterface/windowing/dialogboxes/dialogboxreference/dialogboxfunctions/getdlgitem.asp

    I hope it helps.



  • How to get the current control from a Dialogbox?