How to handle message of multiple keys pressed

I know the title may be a little bit confusing but what i want to do is to make the program do something when the user presses for eg. alt + F4 how do i go about it?

Btw. I know how to handle messages of separate keys pressed is it any similar?
I only have a brief moment now (maybe someone can fill in the details), but here is an old, old Windows CE program of mine I dug up quick that reports the ALT + DELETE key sequence. Check out the WM_KEYDOWN and WM_SYSKEYDOWN messages...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//Program Shows How To Trap Delete Key And Alt+DELETE Key Sequence. 
#include <windows.h>
#define IDC_BUTTON1   1025
#define IDC_BUTTON2   1026

LRESULT CALLBACK WindowProcedure(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
{
 HWND hButton1,hButton2;
 HINSTANCE hIns;
  
 switch(msg)
 {
  case WM_CREATE:
    hIns=((LPCREATESTRUCT)lParam)->hInstance;
    hButton1=CreateWindow(L"button",L"Click Me",WS_CHILD|WS_VISIBLE,70,40,150,30,hwnd,(HMENU)IDC_BUTTON1,hIns,0);
    hButton2=CreateWindow(L"button",L"Exit",WS_CHILD|WS_VISIBLE,70,90,150,30,hwnd,(HMENU)IDC_BUTTON2,hIns,0);
    return 0;
  case WM_COMMAND:
    switch(LOWORD(wParam))
    {
     case IDC_BUTTON1:
       MessageBox(hwnd,L"You Clicked The Button",L"Message",MB_OK);
       break;
     case IDC_BUTTON2:
       SendMessage(hwnd,WM_CLOSE,0,0);
       break;
    }
    return 0;
  case WM_KEYDOWN:
    if(wParam==VK_DELETE)
       MessageBox(hwnd,L"You Clicked The Delete Key!",L"Delete!",MB_OK);
    return 0;
  case WM_SYSKEYDOWN:
    if((lParam&0x20000000)&&wParam==VK_DELETE)
        MessageBox(hwnd,L"Alt + Delete Key!",L"Delete!",MB_OK);
    return 0;
  case WM_CLOSE:
    PostQuitMessage(0);
    return 0;
 }

 return DefWindowProc(hwnd,msg,wParam,lParam);
}

int __stdcall WinMain(HINSTANCE hIns,HINSTANCE hPrevIns,LPTSTR lpszArgument,int iShow)
{
 wchar_t szClassName[]=L"WindowsApp";
 WNDCLASS wincl;
 DWORD dwStyle;
 MSG messages;
 HWND hWnd; 
 RECT rc;

 wincl.hInstance=hIns;
 wincl.lpszClassName=szClassName;
 wincl.lpfnWndProc=WindowProcedure;
 wincl.style=CS_DBLCLKS;
 wincl.hIcon=NULL;
 wincl.hCursor=LoadCursor(NULL,IDC_ARROW);
 wincl.lpszMenuName=NULL;
 wincl.cbClsExtra=0;
 wincl.cbWndExtra=0;
 wincl.hbrBackground=(HBRUSH)COLOR_BACKGROUND;
 RegisterClass(&wincl);
 dwStyle=WS_OVERLAPPED|WS_SYSMENU|WS_VISIBLE;
 SystemParametersInfo(SPI_GETWORKAREA,0,&rc,0);
 hWnd=CreateWindow(szClassName,L"Windows App",dwStyle,0,0,rc.right,rc.bottom,HWND_DESKTOP,0,hIns,0);
 ShowWindow(hWnd,iShow);
 while(GetMessage(&messages,NULL,0,0))
 {
  TranslateMessage(&messages);
  DispatchMessage(&messages);
 }

 return messages.wParam;
}


Last edited on
The best way is to use accelerators --

http://msdn.microsoft.com/en-us/library/ms645526(v=VS.85).aspx

especially if you're going to do a number of different keys.
Topic archived. No new replies allowed.