Thread: WM_KEYDOWN and VK_ESCAPE

  1. #1
    Registered User dalek's Avatar
    Join Date
    May 2003
    Posts
    135

    WM_KEYDOWN and VK_ESCAPE

    Hey.

    Anyone know why I might not be recieving WM_KEYDOWN or WM_CHAR messages when I press the escape key? Even with completely stripped down windows procedure (i.e. only processing the WM_KEYDOWN and WM_DESTROY messages, I am having the same problem. Also - I can get a WM_KEYUP message.. WTF?
    Code:
    LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
    	switch(msg)
    	{
    		
    	case WM_KEYDOWN:
    		{
    			OutputDebugString(TEXT("WM_KEYDOWN\n"));
    		}
    		return 0;
    
    	case WM_KEYUP:
    		{
    			OutputDebugString(TEXT("WM_KEYUP\n"));
    		}
    		return 0;
    
    	case WM_DESTROY:
    		PostQuitMessage(0);
    		return 0;
    
    	default:
    		return DefWindowProc(hwnd, msg, wParam, lParam);
    	}
    }

  2. #2
    Registered User dalek's Avatar
    Join Date
    May 2003
    Posts
    135
    Goddam it. It has something to do with IsDialogMessage - does anyone know what this does with the WM_CHAR and WM_KEYDOWN messages? I can't seem to find it documented anywhere..

  3. #3
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    A rough idea of how a winapi function is implemented can sometimes be obtained from the WINE version. Here is the identifier search page and here is the code for IsDialogMessageW.

  4. #4
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    >>It has something to do with IsDialogMessage<<

    The ESC key, like the TAB key, is one of the keys for which IsDialogMessage provides default keyboard handling: it's sent as a command notification with an id of IDCANCEL. For example,
    Code:
    case WM_COMMAND:
      {
      if (LOWORD(wParam)==IDCANCEL)
        {
        /* ESC key has been pressed*/
        }
      }
    will trap the ESC keypress.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  5. #5
    Registered User dalek's Avatar
    Join Date
    May 2003
    Posts
    135
    Thanks for that - I was wondering what was going on - particularly since I was getting WM_KEYUP messages.

Popular pages Recent additions subscribe to a feed