资源描述:
《windows程序设计(第五版)源代码a(chap06)》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、chap06-KeyView1/*--------------------------------------------------------KEYVIEW1.C--DisplaysKeyboardandCharacterMessages(c)CharlesPetzold,1998--------------------------------------------------------*/#includeLRESULTCALLBACKWndProc(HWND,UINT,WPARAM,LPARAM);intWINA
2、PIWinMain(HINSTANCEhInstance,HINSTANCEhPrevInstance,PSTRszCmdLine,intiCmdShow){staticTCHARszAppName[]=TEXT("KeyView1");HWNDhwnd;MSGmsg;WNDCLASSwndclass;wndclass.style=CS_HREDRAW
3、CS_VREDRAW;wndclass.lpfnWndProc=WndProc;wndclass.cbClsExtra=0;wndclass.cbWndExtra=0;wndclass.hIns
4、tance=hInstance;wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);wndclass.lpszMenuName=NULL;wndclass.lpszClassName=szAppName;if(!RegisterClass(&wndclass)){MessageBox(NULL,TEXT
5、("ThisprogramrequiresWindowsNT!"),szAppName,MB_ICONERROR);return0;}hwnd=CreateWindow(szAppName,TEXT("KeyboardMessageViewer#1"),WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL);ShowWindow(hwnd,iCmdShow);UpdateWindow(hwnd);w
6、hile(GetMessage(&msg,NULL,0,0)){TranslateMessage(&msg);DispatchMessage(&msg);}returnmsg.wParam;}LRESULTCALLBACKWndProc(HWNDhwnd,UINTmessage,WPARAMwParam,LPARAMlParam){staticintcxClientMax,cyClientMax,cxClient,cyClient,cxChar,cyChar;staticintcLinesMax,cLines;staticPMSGpmsg;st
7、aticRECTrectScroll;staticTCHARszTop[]=TEXT("MessageKeyChar")TEXT("RepeatScanExtALTPrevTran");staticTCHARszUnd[]=TEXT("______________")TEXT("________________________");staticTCHAR*szFormat[2]={TEXT("%-13s%3d%-15s%c%6u%4d%3s%3s%4s%4s"),TEXT("%-13s0x%04X%1s%c%6u%4d%3s%3s%4s%4s"
8、)};staticTCHAR*szYes=TEXT("Yes");staticTCHAR*szNo=TEXT("No");staticTCHAR*szDown=TEXT("Down");staticTCHAR*szUp=TEXT("Up");staticTCHAR*szMessage[]={TEXT("WM_KEYDOWN"),TEXT("WM_KEYUP"),TEXT("WM_CHAR"),TEXT("WM_DEADCHAR"),TEXT("WM_SYSKEYDOWN"),TEXT("WM_SYSKEYUP"),TEXT("WM_SYSCHA
9、R"),TEXT("WM_SYSDEADCHAR")};HDChdc;inti,iType;PAINTSTRUCTps;TCHARszBuffer[1