QT源码解析之Qt处理Windows消息
创始人
2024-08-01 14:31:44
0

 

QT中如何处理Windows消息是本文要介绍的内容,先来看代码实现。

  1. bool QApplication::winEventFilter ( MSG * )  

消息程序在每次接受到消息时调用这个函数。如果你想处理Qt不处理的窗口消息msg,请重新实现这个函数。 

  1. bool MainWindow::winEvent(MSG* pMsg)  
  2. {  
  3.  if ( pMsg->message == WM_COPYDATA )  
  4.  {  
  5.   COPYDATASTRUCT* pCopyDataStruct;  
  6.   POSTERS_REC_STRUCT* pRec;  
  7.   unsigned char* odapMsgPtr[MAX_POSTERS_SIZE];  
  8.   QString str;  
  9.   pCopyDataStruct = (COPYDATASTRUCT*) pMsg->lParam;  
  10.   switch (pCopyDataStruct->dwData)  
  11.   {  
  12.   case VALID_REC1 :  
  13.   case VALID_REC2 :  
  14.    {  
  15.     (void)memcpy(odapMsgPtr, pCopyDataStruct->lpData, pCopyDataStruct->cbData);  
  16.     if (odapMsgPtr != NULL)  
  17.     {  
  18.      pRec = (POSTERS_REC_STRUCT *)odapMsgPtr;  
  19.      class_data1 = pRec->var1;  
  20.      class_data2 = pRec->var2;  
  21.     }  
  22.    }  
  23.   }  
  24.   return true;  
  25.  }  
  26.  else  
  27.   return false;  
  28. }  
  29. Some Code on the web gives another example  
  30. #ifdef HAVE_WIN32_API  
  31.   virtual bool winEventFilter(MSG * msg) {  
  32.     SPW_InputEvent sbEvent;  
  33.     if (SPW_TranslateEventWin32(msg, &sbEvent)) {  
  34.       QWidget * focus = this->focusWidget();  
  35.       if (!focus) focus = this->activeWindow();  
  36.       if (focus) {  
  37.         QCustomEvent qevent((QEvent::Type)SoQtInternal::SPACEBALL_EVENT,  
  38.                             (void *)&sbEvent);  
  39.         QApplication::sendEvent(focus, &qevent);  
  40.       }  
  41.     }  
  42. #if (QT_VERSION >= 0x040000)  
  43.     long result = 0;  
  44.     return QApplication::winEventFilter(msg, &result);  
  45. #else  
  46.     return QApplication::winEventFilter(msg);  
  47. #endif 

The QSystemTrayIcon class provides an icon for an application in the system tray.
Modern operating systems usually provide a special area on the desktop, called the system tray or notification area, where long-running applications can display icons and short messages.

QT源码解析之Qt处理Windows消息

  1. /* translates a Win32 event to a SPW_InputEvent. */  
  2. int SPW_TranslateEventWin32(MSG * msg, SPW_InputEvent * sbEvent)  
  3. {  
  4.   SiSpwEvent spwEvent;  
  5.   SiGetEventData eventdata;  
  6.   if (Spw_DeviceHandle != SI_NO_HANDLE) {  
  7.     SiGetEventWinInit (&eventdata, msg->message, msg->wParam, msg->lParam);  
  8.     if (SiGetEvent (Spw_DeviceHandle, 0, &eventdata, &spwEvent) == SI_IS_EVENT) {  
  9.       int i;  
  10.       switch(spwEvent.type) {  
  11.         case SI_MOTION_EVENT:  
  12.           sbEvent->type = SPW_InputMotionEvent;        
  13.           for(i=0; i<6; i++) {  
  14.             sbEvent->sData[i] = (short)spwEvent.u.spwData.mData[i];  
  15.           }    
  16.           break;  
  17.         case SI_BUTTON_EVENT:  
  18.           sbEvent->type = SPW_InputButtonPressEvent;  
  19.           sbEvent->buttonState.pressed = (SiButtonPressed(&spwEvent) != SI_NO_BUTTON);  
  20.           sbEvent->buttonState.released = (SiButtonReleased(&spwEvent) != SI_NO_BUTTON);  
  21.           break;  
  22.       }  
  23.       return TRUE;  
  24.     }  
  25.   }  
  26.   return FALSE;  

小结:QT源码解析之Qt处理Windows消息的内容介绍完了,希望本文对你有帮助。

相关内容

热门资讯

如何允许远程连接到MySQL数... [[277004]]【51CTO.com快译】默认情况下,MySQL服务器仅侦听来自localhos...
如何利用交换机和端口设置来管理... 在网络管理中,总是有些人让管理员头疼。下面我们就将介绍一下一个网管员利用交换机以及端口设置等来进行D...
施耐德电气数据中心整体解决方案... 近日,全球能效管理专家施耐德电气正式启动大型体验活动“能效中国行——2012卡车巡展”,作为该活动的...
Windows恶意软件20年“... 在Windows的早期年代,病毒游走于系统之间,偶尔删除文件(但被删除的文件几乎都是可恢复的),并弹...
20个非常棒的扁平设计免费资源 Apple设备的平面图标PSD免费平板UI 平板UI套件24平图标Freen平板UI套件PSD径向平...
德国电信门户网站可实时显示全球... 德国电信周三推出一个门户网站,直观地实时提供其安装在全球各地的传感器网络检测到的网络攻击状况。该网站...
着眼MAC地址,解救无法享受D... 在安装了DHCP服务器的局域网环境中,每一台工作站在上网之前,都要先从DHCP服务器那里享受到地址动...
为啥国人偏爱 Mybatis,... 关于 SQL 和 ORM 的争论,永远都不会终止,我也一直在思考这个问题。昨天又跟群里的小伙伴进行...