进程内钩子 处理之一

 

 

HHOOK g_hKeyboard = NULL;

 

 

 

LRESULT CALLBACK KeyBoadProc(int code, WPARAM wParam, LPARAM lParam)
{
    //!< f6=alt
  if ( (VK_F6 == wParam) && (1 == ( lParam >> 29 & 1 )))
 {
       //!<重新初始化设备,再开始
  theApp.m_pLVScanView->OnStopCapture();
  SLEEP_RESCAN;
  LSCAN_Main_ReleaseAll(TRUE);
  theApp.m_nDeviceInited = -1;
  //VERIFY( ::AfxBeginThread( ThreadInitializeDevice, theApp.m_pLVScanView, THREAD_PRIORITY_NORMAL,
  // 0x100000, STACK_SIZE_PARAM_IS_A_RESERVATION ) != NULL );

  theApp.m_pLVScanView->OnBeginCapture();

  return 1;
 }
 else
 {
  return CallNextHookEx( g_hKeyboard , code,  wParam, lParam );
 }

}

 

 

 

void GfPoliceLVScanView::OnInitialUpdate()

{

g_hKeyboard = SetWindowsHookEx(WH_KEYBOARD, KeyBoadProc, NULL, GetCurrentThreadId() );

}

 

 

GfPoliceLVScanView::~GfPoliceLVScanView()
{
 UnhookWindowsHookEx(g_hKeyboard);

}

 

ps:控件中无法响应消息传递,可调用钩子函数来处理键盘等其他消息。

 

你可能感兴趣的:(c/c++,VS2005/MFC)