Leandro Caniglia
Leandro Caniglia

Reputation: 14858

Proper way of using the time in MSG

I'm writing a logging feature that registers socket events. The problem I'm having is that even though I have the time of the event in the MSG structure that I get when I call PeekMessage, the subsequent call to DispatchMessage will end up being handled by WindowProc, which does not receive the time as a parameter.

The "solution" I'm using to log times consists in detecting socket events in the main loop of my Windows application where PeekMessage occurs.

Which would be the proper way to do this? I would rather prefer not having to add logging specific logic to an otherwise general routine.

Upvotes: 0

Views: 354

Answers (1)

Remy Lebeau
Remy Lebeau

Reputation: 596307

Use GetMessageTime() in your socket message handler:

Retrieves the message time for the last message retrieved by the GetMessage() function. The time is a long integer that specifies the elapsed time, in milliseconds, from the time the system was started to the time the message was created (that is, placed in the thread's message queue).

Compared to the time field of the MSG structure:

The time at which the message was posted.

Upvotes: 2

Related Questions