QEventDispatcherWin32 笔记

本文详细介绍了QEventDispatcherWin32在Win32程序中的作用,包括事件循环、定时器、Socket Notifier和Win Event Notifier的处理。在Qt中,事件循环由QEventLoop::exec()启动,QEventDispatcherWin32负责处理Windows底层的消息,如通过WH_GETMESSAGE钩子函数和qt_GetMessageHook()。同时,文章提到了Qt事件队列的管理,包括注册和注销定时器、Socket Notifier以及Win Event Notifer的相关函数。
摘要由CSDN通过智能技术生成

额,还是从一个window程序的基本结构看起吧

Win32程序基本结构

  • 注册窗口类别 RegisterClass

  • 创建窗口 CreateWindow

  • 启动由GetMessage和DispatchMessage构成的事件循环

  • 被注册的回调函数 WndProc 负责相应各类事件

#include <windows.h>

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
        PSTR szCmdLine, int iCmdShow)
{
    static TCHAR szAppName[] = TEXT("Hello");
    HWND   hwnd;
    MSG    msg;
    WNDCLASS wndclass;
    //fill wndclass
    wndclass.lpfnWndProc  = WndProc;
    ...
    RegisterClass(&wndclass);
    hwnd = CreateWindow( .... );      // creation parameters
    ShowWindow(hwnd, iCmdShow);
    UpdateWindow(hwnd);
    while(GetMessage(&msg, NULL, 0, 0))  {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    return msg.wParam;
}

LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    HDC hdc;
    PAINTSTRUCT ps;
    RECT rect;
    switch(message) {
        case WM_CREATE:
            return 0;
        case WM_PAINT:
            ...
            return 0;
        case WM_DESTROY:
            PostQuitMessage(0);
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值