Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. What does this qt_GetMessageHook(Qt5.6.3) do?
Forum Updated to NodeBB v4.3 + New Features

What does this qt_GetMessageHook(Qt5.6.3) do?

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 192 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lidada
    wrote on last edited by Lidada
    #1

    Read processEvents() source code in qeventdispatcher_win.cpp, I don't understand the meaning of qt_GetMessageHook(); For example Create a timer (sendPostedEventsWindowsTimerId), I think even without this timer, the peekmessage() in processEvents() in the next cycle can send WM_QT_SENDPOSTEDEVENTS

    LRESULT QT_WIN_CALLBACK qt_GetMessageHook(int code, WPARAM wp, LPARAM lp)
    {
        QEventDispatcherWin32 *q = qobject_cast<QEventDispatcherWin32 *>(QAbstractEventDispatcher::instance());
        Q_ASSERT(q != 0);
    
        if (wp == PM_REMOVE) {
            if (q) {
                MSG *msg = (MSG *) lp;
                QEventDispatcherWin32Private *d = q->d_func();
                const int localSerialNumber = d->serialNumber.load();
                static const UINT mask = inputTimerMask();
                if (HIWORD(GetQueueStatus(mask)) == 0) {
                    // no more input or timer events in the message queue, we can allow posted events to be sent normally now
                    if (d->sendPostedEventsWindowsTimerId != 0) {
                        // stop the timer to send posted events, since we now allow the WM_QT_SENDPOSTEDEVENTS message
                        KillTimer(d->internalHwnd, d->sendPostedEventsWindowsTimerId);
                        d->sendPostedEventsWindowsTimerId = 0;
                    }
                    (void) d->wakeUps.fetchAndStoreRelease(0);
                    if (localSerialNumber != d->lastSerialNumber
                        // if this message IS the one that triggers sendPostedEvents(), no need to post it again
                        && (msg->hwnd != d->internalHwnd
                            || msg->message != WM_QT_SENDPOSTEDEVENTS)) {
                        PostMessage(d->internalHwnd, WM_QT_SENDPOSTEDEVENTS, 0, 0);
                    }
                } else if (d->sendPostedEventsWindowsTimerId == 0
                           && localSerialNumber != d->lastSerialNumber) {
                    // start a special timer to continue delivering posted events while
                    // there are still input and timer messages in the message queue
                    d->sendPostedEventsWindowsTimerId = SetTimer(d->internalHwnd,
                                                                 SendPostedEventsWindowsTimerId,
                                                                 0, // we specify zero, but Windows uses USER_TIMER_MINIMUM
                                                                 NULL);
                    // we don't check the return value of SetTimer()... if creating the timer failed, there's little
                    // we can do. we just have to accept that posted events will be starved
                }
            }
        }
    #ifdef Q_OS_WINCE
        return 0;
    #else
        return q->d_func()->getMessageHook ? CallNextHookEx(0, code, wp, lp) : 0;
    #endif
    }
    
    
    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved