Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

message Hook API

83 views
Skip to first unread message

lily

unread,
Nov 3, 2002, 5:13:29 AM11/3/02
to
Hello,

I want use message hook in Pocket PC, but it seems that
WinCE API do not support message hook, how can I do it?

Thanks and Regards

lily

Jeff Armstrong

unread,
Nov 4, 2002, 4:11:49 PM11/4/02
to
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
 

Jeff Armstrong

unread,
Nov 4, 2002, 6:27:16 PM11/4/02
to
BTW, only a few of the hook-related defines are implemented.

#define WH_JOURNALRECORD 0
#define WH_JOURNALPLAYBACK 1
#define WH_KEYBOARD_LL 20

See http://www.cegadgets.com/wincedevfaq.htm for details;

Jeff Armstrong

Acres Gaming

"lily" <f18...@sohu.com> wrote in message
news:3c5a01c28321$a838cf50$37ef2ecf@TKMSFTNGXA13...

0 new messages