1 LRESULT CALLBACK KeyBoardHook(int nCode, WPARAM wParam, LPARAM lParam)
2 {
3 if ((lParam&WS_POPUP) == 0)
4 {
5 CString str;
6 unsigned char ch;
7 if(GetKeyState(VK_CAPITAL))//大小写
8 {
9 ch=(char)wParam;
10 str.Format("%c",ch);
11
12 }
13 else
14 {
15 ch=(char)(wParam+32);
16 str.Format("%c",ch);
17
18 }
19
20 CtestMFCDlg *dlg = (CtestMFCDlg*)AfxGetApp()->GetMainWnd();
21
22 str.Format("%c",ch);
23 dlg->ListBox.AddString(str);
24 }
25 return CallNextHookEx(hk_Myhook,nCode,wParam,lParam);
26 }
1 hk_Myhook = SetWindowsHookEx(WH_KEYBOARD,KeyBoardHook,0,GetCurrentThreadId());