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.
/* 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消息的内容介绍完了,希望本文对你有帮助。