urgent: modeless dialog doesn't get focus

Hello everyone,
I am developping a win32 application for smartphone that needs to open a modeless dialog to display information.
The dialog is showing up, but the problem is that it seems not to have the focus.
Indeed I can't use its menubar, nor can I edit or go to my textfileds on the dialog.

Please help!



Answer this question

urgent: modeless dialog doesn't get focus

  • DirtyHowi

    Thank you for your reply but I think we posted at the same time so that you couldn't see my second post.
    I've read that SetFocus( ) was not the appropriate code and that we had to do a PostMessage.
    Unfortunatly, this doesn't help....


  • vessel

    The fuction SetFocus (HWND hWnd) might be what you need. You pass the handle of the dialog in the hWnd argument. If your modeless dialog has a procedure, you can put that call at the end of the WM that initailizes your dialog's variables.
  • barontufsap

    I have tried everything according to the documentation and others forums.
    Here's the end of the WM_INITDIALOG message treatment in the DLGPROC function:

    PostMessage(hDlg,WM_NEXTDLGCTL,(WPARAM)GetDlgItem(hDlg,IDC_RESPONSE_STATE),(LPARAM)TRUE);
    PostMessage(hDlg,WM_NEXTDLGCTL,(WPARAM)GetWindow(hDlg,IDC_RESPONSE_STATE),(LPARAM)TRUE);
    SetFocus(GetDlgItem(hDlg,IDC_RESPONSE_STATE));
    SetFocus(GetWindow(hDlg,IDC_RESPONSE_STATE));

    return FALSE;




  • Antony Kancidrowski

    I must say that returning TRUE of FALSE doesn't change anything in my case.


  • Marius_m

    "The dialog box procedure should return TRUE to direct the system to set the keyboard focus to the control given by hwndFocus. Otherwise, it should return FALSE to prevent the system from setting the default keyboard focus. "

    return TRUE and you'll be all set.


  • urgent: modeless dialog doesn't get focus