Win32 Modal Dialog Box

I've made this custom control (as I often do) but this thing relies on WM_CHAR and it appears that modal dialog boxes don't translate messages because the custom control doesn't get WM_CHAR when in one. I looked around and couldn't find any solutions or similar problems, but a test-bed reveals this is not a problem specific to my project. Thanks for any help in advance.

P.S. Yes, I realise what is causing the problem; modal dialog boxes have their own message loop (they must in order to suspend the calling thread) and this loop must simply not call TranslateMessage. I'm hoping to learn why, and how to fix it. =)


Answer this question

Win32 Modal Dialog Box

  • kmccaa

    Are you sure that your control has the focus
    ry to check the complete situation with spy++. Who receives the message when pressing some characters.

  • Vaine

    So either the focus is on the wrong window, or your window is subclassed, or PreTranslateMessage (if you have one, and working with MFC) is eating it.

  • jcribbs

    I guess you need handle WM_GETDLGCODE like the following to get WM_CHAR


    case WM_GETDLGCODE:
       if(lParam){
        LPMSG lpmsg = (LPMSG)lParam;
        if( lpmsg->message == WM_CHAR){
         return DLGC_WANTCHARS;
        }
       }
       return 0;

     


    See http://support.microsoft.com/kb/q83302/ for detail.

  • rmtuckerphx

    Sorry, I should have tested it with Spy++ before making a thread.  Hmph... It looks like it does indeed receive WM_CHAR messages but my WndProc isn't getting them.

  • Fantasiiio

    Sorry! Than I have no idea any more.
    The standard Modal Dialog message loop translates messages, otherwise a edit control in your dialog wouldn't work. I hope it works :-)

  • Rohan Singh

    Thanks for the responce, Martin. I am not subclassing this control, the focus is on it, and I would never degrade myself to using MFC. Who marked it as answer Possible causes of the problem is not an answer.

    If it didn't have focus then Spy++ wouldn't get the messages.

  • MechGuru

    So if you are using the plain api, your WindowProc should be in GetWindowLong GWL_WNDPROC. Just check this. If not another routine took control over your window by subclassing it.

    Spy++ can tell you about the window proc, too.



  • Friction

     Martin Richter wrote:

    So if you are using the plain api, your WindowProc should be in GetWindowLong GWL_WNDPROC. Just check this. If not another routine took control over your window by subclassing it.

    Spy++ can tell you about the window proc, too.

    WM_CHAR is the only message it is not receiving. That is why I jumped to the assumption that the modal dialog box's message loop isn't translating messages. :\  And it is only in modal dialog boxes. If I swap DialogBox with CreateDialog my custom control is flawless.

    I have trouble believing that something is subclassing all modal dialogs and not calling the replaced WndProc on WM_CHAR messages just to mess with me.

  • wishme

    Thanks daemon, that did it. It seems odd that this was necessary, according to WM_GETDLGCODE's documentation the dialog should process WM_CHAR by default.

    Thanks for the input reguardless Martin.

  • Imran Koradia

    I have unmarked the answer post to reopen the issue.

    BTW, sometimes pointing the person posting the issue to the possible causes of the problem is actually an answer since it directs him/her where to investigate. It is just not the case for this post.

    Thanks,
      Ayman Shoukry
      VC++ Team

  • Win32 Modal Dialog Box