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

移动开发
本文介绍的是QT源码解析之Qt处理Windows消息的,基本属于代码实现,并没有多少内容,先来看内容。

 

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

bool QApplication::winEventFilter ( MSG * )  
  • 1.

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

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

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消息

/* translates a Win32 event to a SPW_InputEvent. */  
int SPW_TranslateEventWin32(MSG * msg, SPW_InputEvent * sbEvent)  
{  
  SiSpwEvent spwEvent;  
  SiGetEventData eventdata;  
  if (Spw_DeviceHandle != SI_NO_HANDLE) {  
    SiGetEventWinInit (&eventdata, msg->message, msg->wParam, msg->lParam);  
    if (SiGetEvent (Spw_DeviceHandle, 0, &eventdata, &spwEvent) == SI_IS_EVENT) {  
      int i;  
      switch(spwEvent.type) {  
        case SI_MOTION_EVENT:  
          sbEvent->type = SPW_InputMotionEvent;        
          for(i=0; i<6; i++) {  
            sbEvent->sData[i] = (short)spwEvent.u.spwData.mData[i];  
          }    
          break;  
        case SI_BUTTON_EVENT:  
          sbEvent->type = SPW_InputButtonPressEvent;  
          sbEvent->buttonState.pressed = (SiButtonPressed(&spwEvent) != SI_NO_BUTTON);  
          sbEvent->buttonState.released = (SiButtonReleased(&spwEvent) != SI_NO_BUTTON);  
          break;  
      }  
      return TRUE;  
    }  
  }  
  return FALSE;  

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.

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

责任编辑:zhaolei 来源: 互联网
相关推荐

2011-06-23 11:16:39

Qt Excel

2011-06-23 13:25:42

QT 源码 窗口

2011-06-23 15:10:39

Qt 窗体

2011-06-23 14:05:32

Qt 事件机制

2011-06-23 14:40:13

Qt 信号

2011-06-23 13:38:27

QT 元对象 信号

2011-06-29 17:39:04

Qt 发布 编译

2011-06-27 09:47:43

2011-06-27 09:02:18

Qt UDP 网络

2011-06-08 15:27:24

QT QT 4.5 编译

2011-06-09 15:18:07

QT 编译

2011-09-09 17:59:26

QT Widget

2011-07-01 15:04:49

Qt 内省

2011-06-27 10:15:22

Qt 网络 TCP

2011-06-28 16:18:24

Qt QObject

2011-06-27 10:28:45

Qt 网络 TCP

2011-06-20 13:05:53

Qt 4.7 Qt Quick

2011-08-30 16:08:24

Qt4.7Qt Quick

2011-06-16 11:28:48

Qt QApplicati

2011-06-22 15:50:45

QT 线程
点赞
收藏

51CTO技术栈公众号