WM_KEYDOWN event not being called

Asked

Viewed 37 times

0

I am developing a simple C++ program just for testing with a graphical interface but it is not calling the WM_KEYDOWN event, the program is based on dialog. The graphical interface was created through Resedit. Could someone tell me why? Below is the main code of it:

#include <windows.h>
#include <commctrl.h>
#include "resource.

BOOL CALLBACK DlgMain(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch(uMsg)
    {
        case WM_INITDIALOG:
        {
            return TRUE;
        }

        case WM_KEYDOWN: // problema aqui
        {
            if(LOWORD(wParam) == VK_ESCAPE)
            {
                PostMessage(hwndDlg, WM_CLOSE, 0, 0);
            }
            return TRUE;
        }

        case WM_CLOSE:
        {
            if(MessageBox(hwndDlg, "Você deseja realmente sair?", "Confirmação", MB_OKCANCEL | MB_ICONQUESTION) == IDOK) {
                EndDialog(hwndDlg, 0);
            }

            return TRUE;
        }

        case WM_COMMAND:
        {
            switch(LOWORD(wParam))
            {
                case ID_LEAVE:
                {
                    SendMessage(hwndDlg, WM_CLOSE, 0, 0);
                    return TRUE;
                }
            }
            return TRUE;
        }
    }
    return FALSE;
}


int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
    InitCommonControls();
    return DialogBox(hInstance, MAKEINTRESOURCE(DLG_MAIN), NULL, (DLGPROC)DlgMain);
}
  • I just debugged the program, everything works normal but the WM_KEYDOWN event is never even called for any key, would it be any incompatibility of the code generated by Resedit? Because when I create everything by hand (the interface, buttons, class registration, etc.) I don’t have this problem.

  • What mistake it makes ?

  • The missing quotation marks on #include "resource. it was just a typo?

  • Yes, Jefferson. I had changed a few things while I was putting the code here, it was just a typo. Matheus, no error is given, the program compiles and runs normally, just nothing happens when I press the ESC key or any other. The WM_KEYDOWN event is not being called, because in tests here I put so that when this is called, show a message on the screen, no matter the key that was pressed and still does not work.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.