I am developing on a Symbol PocketPC running
Windows CE. Although it is not documented, the SetWindowsHookEx API call
exists and can be used. Following is the code fragment which I
used;
extern "C"
{
typedef LRESULT
(CALLBACK* HOOKPROC)(int code, WPARAM wParam, LPARAM lParam);
typedef struct tagKBDLLHOOKSTRUCT
{
DWORD vkCode; // virtual key
code
DWORD scanCode; // scan code
DWORD
flags; // flags
DWORD time; // time
stamp for this message
DWORD dwExtraInfo; // extra info from
the driver or keybd_event
} KBDLLHOOKSTRUCT,
*PKBDLLHOOKSTRUCT;
HHOOK WINAPI SetWindowsHookExW( int
idHook, HOOKPROC lpfn, HINSTANCE hmod, DWORD dwThreadId
);
BOOL WINAPI UnhookWindowsHookEx( HHOOK hhk );
LRESULT
WINAPI CallNextHookEx( HHOOK hhk, int nCode, WPARAM wParam, LPARAM lParam
);
LRESULT CALLBACK KeyboardProc( int code, WPARAM wParam, LPARAM
lParam );
#define SetWindowsHookEx
SetWindowsHookExW
}
HHOOK hKeyboardHook = 0;
#define HC_ACTION 0
#define
APP1_KEY 0xC1
#define APP2_KEY 0xC2
#define
APP3_KEY 0xC3
#define APP4_KEY 0xC4
#define
APP5_KEY 0xC5
//Notification Code
LRESULT CALLBACK
KeyboardProc( int code, WPARAM wParam, LPARAM lParam
)
{
PKBDLLHOOKSTRUCT pKeyStruct =
(PKBDLLHOOKSTRUCT)lParam;
LRESULT lResult =
0;
if ((AfxGetMainWnd()->m_hWnd !=
NULL) &&
(code ==
HC_ACTION) &&
(wParam ==
WM_KEYDOWN) )
{
switch(pKeyStruct->vkCode
)
{
case APP1_KEY:
case
APP2_KEY:
case APP3_KEY:
case
APP4_KEY:
case APP5_KEY:
lResult =
1;
break;
}
}
if (0 == lResult)
lResult =
CallNextHookEx(hKeyboardHook, code, wParam, lParam);
// Return true if hook was handled, false to pass it
on
return lResult;
}
void
MyCEView::OnInitialUpdate()
{
CView::OnInitialUpdate();
hKeyboardHook = SetWindowsHookExW(
WH_KEYBOARD_LL,
(HOOKPROC) KeyboardProc, // address of hook
procedure
NULL, // handle to application
instance
0 );
}
BOOL
MyCEView::DestroyWindow()
{
if (0 !=
hKeyboardHook)
UnhookWindowsHookEx(hKeyboardHook);
return
CView::DestroyWindow();
}
Hope this helps!
Jeff Armstrong
Acres Gaming