Thread: wm_keydown and dialogs

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    380

    wm_keydown and dialogs

    Hi,
    I'm new to Windows progamming and was wondering if
    someone could please post or show an example on how to use wm_keydown with dialogs?

    Thank you

    Here's my attempt:
    Code:
    #include <windows.h>
    #include "calc.h"
    
    BOOL CALLBACK CalcDialogProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
    	switch(msg)
    	{
    		case WM_INITDIALOG:
    		return TRUE;
    
    
    		case WM_COMMAND:
    			switch(LOWORD(wParam))
    			{
    			}
    			break;
       	case WM_KEYDOWN:
    		switch(LOWORD(wParam))
    			{
    				case 1:
    				MessageBox(hWnd,"message","title", MB_OK);
        	SendDlgItemMessage(hWnd,IDC_PUSHBUTTON1,WM_KEYDOWN,0,0);
    
    				break;
    			}
    		return TRUE;
    
    
    		case WM_CLOSE:
    				EndDialog(hWnd, 0);
    				return TRUE;
    	}
    
    	return FALSE;
    }
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
    	 LPSTR lpCmdLine, int nCmdShow)
    {
    	DialogBoxParam(GetModuleHandle(NULL), MAKEINTRESOURCE(DIALOG_1),
    			NULL, (DLGPROC)CalcDialogProc, 0);
    
    	return 0;
    }
    Don't you dare hit me on the head, you know I'm not normal.
    A Stooge Site
    Green Frog Software

  2. #2
    Registered User
    Join Date
    Dec 2002
    Posts
    119
    Are you looking for something like this?

    Code:
    case WM_KEYDOWN:
          switch(LOWORD(wParam))
         {
              case 49:          
              case VK_NUMPAD1:                
                       SendDlgItemMessage(hWnd, IDC_PUSHBUTTON1, BM_CLICK, 0, 0);
              break;
              case 50:
              case VK_NUMPAD2:
                       SendDlgItemMessage(hWnd, IDC_PUSHBUTTON2, BM_CLICK, 0, 0);
              break;
              default:
              break;
         }
    break;
    If you speak or are learning Spanish, check out this Spanish and English Dictionary, it is a handy online resource.
    What happens is not as important as how you react to what happens. -Thaddeus Golas

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    380
    I think am. Am I suppose to replace my wm_keydown section with yours?
    Don't you dare hit me on the head, you know I'm not normal.
    A Stooge Site
    Green Frog Software

  4. #4
    Registered User
    Join Date
    Dec 2002
    Posts
    119
    Yep, that'd probably be a pretty good place to start if you want to see what the code does...
    If you speak or are learning Spanish, check out this Spanish and English Dictionary, it is a handy online resource.
    What happens is not as important as how you react to what happens. -Thaddeus Golas

Popular pages Recent additions subscribe to a feed