Qt怎样处理Windows消息
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Qt怎样处理Windows消息相关的知识,希望对你有一定的参考价值。
参考技术A 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.
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;
27. 本回答被提问者采纳
Qt for windows消息循环libqxt分析和wince快捷键处理
Qt for windows消息循环、libqxt分析和wince快捷键处理
利用Qt做windows图形界面开发和MFC相比,个人感觉还是比较简单好用的:首先利用Designer工具搞个ui文件;然后在程序中写几个信号和槽;然后加载ui文件;最后显示界面就搞定了。
在界面开发中,快捷键处理肯定是必不可少的。现在使用的是开源的第三方处理类:libqxt。它提供跨平台的解决方案:win和x11。使用起来也很方便。使用方便并不是万事大吉,我们要有求索精神:“知其然知其所以然”。好了废话不多说开始分析。
Windows下程序设计总是要遵循它自身的机制的,在《windows程序设计》书中给出了详细的说明。下面给出经典的windows程序示例(hello Windows):
#include
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT ("HelloWin") ;
HWND hwnd ;
MSG msg ;
WNDCLASwndclass ;
wndclass.style = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground= (HBRUSH) GetStockObject (WHITE_BRUSH) ;
wndclass.lpszMenuNam = NULL ;
wndclass.lpszClassName= szAppName ;
if (!RegisterClass (&wndclass)) {
MessageBox ( NULL, TEXT ("This program requires Windows NT!"),
szAppName, MB_ICONERROR) ;
return 0 ;
}
hwnd = CreateWindow( szAppName, // window class name
TEXT ("The Hello Program"), // window caption
WS_OVERLAPPEDWINDOW, // window style
CW_USEDEFAULT,// initial x position
CW_USEDEFAULT,// initial y position
CW_USEDEFAULT,// initial x size
CW_USEDEFAULT,// initial y size
http://www.360docs.net/doc/info-dd3b0c3faf45b307e8719777.html
https://wenku.baidu.com/view/dd3b0c3faf45b307e8719777.html
以上是关于Qt怎样处理Windows消息的主要内容,如果未能解决你的问题,请参考以下文章
Qt for windows消息循环libqxt分析和wince快捷键处理