自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

QT源碼解析之Qt處理Windows消息

移動(dòng)開(kāi)發(fā)
本文介紹的是QT源碼解析之Qt處理Windows消息的,基本屬于代碼實(shí)現(xiàn),并沒(méi)有多少內(nèi)容,先來(lái)看內(nèi)容。

 

QT中如何處理Windows消息是本文要介紹的內(nèi)容,先來(lái)看代碼實(shí)現(xiàn)。

  1. bool QApplication::winEventFilter ( MSG * )  

消息程序在每次接受到消息時(shí)調(diào)用這個(gè)函數(shù)。如果你想處理Qt不處理的窗口消息msg,請(qǐng)重新實(shí)現(xiàn)這個(gè)函數(shù)。 

  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;  

小結(jié):QT源碼解析之Qt處理Windows消息的內(nèi)容介紹完了,希望本文對(duì)你有幫助。

責(zé)任編輯:zhaolei 來(lái)源: 互聯(lián)網(wǎng)
相關(guān)推薦

2011-06-23 11:16:39

Qt Excel

2011-06-23 13:25:42

QT 源碼 窗口

2011-06-23 14:05:32

Qt 事件機(jī)制

2011-06-23 15:10:39

Qt 窗體

2011-06-23 14:40:13

Qt 信號(hào)

2011-06-23 13:38:27

QT 元對(duì)象 信號(hào)

2011-06-29 17:39:04

Qt 發(fā)布 編譯

2011-06-27 09:02:18

Qt UDP 網(wǎng)絡(luò)

2011-07-01 15:04:49

Qt 內(nèi)省

2011-09-09 17:59:26

QT Widget

2011-06-27 09:47:43

2011-06-08 15:27:24

QT QT 4.5 編譯

2011-06-09 15:18:07

QT 編譯

2011-06-27 10:28:45

Qt 網(wǎng)絡(luò) TCP

2011-06-28 16:18:24

Qt QObject

2011-06-20 13:05:53

Qt 4.7 Qt Quick

2011-06-27 10:15:22

Qt 網(wǎng)絡(luò) TCP

2011-06-27 09:15:21

QT Creator

2011-07-01 14:39:08

Qt Quick

2011-06-16 11:28:48

Qt QApplicati
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)