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;
}
|