Reputation: 5841
The VCL TMessage
class provides the Message
, WParam
and LParam
members, but a window message has more members:
typedef struct tagMSG {
HWND hwnd;
UINT message;
WPARAM wParam;
LPARAM lParam;
DWORD time;
POINT pt;
DWORD lPrivate;
} MSG, *PMSG, *NPMSG, *LPMSG;
Where are the hwnd
, time
, pt
and lPrivate
members? I'm in specially need of the time
parameter.
Is there a way to access the original message that TMessage
is constructed from (or any other means to get the time
parameter)?
I'm handling my messages in TComponent::WndProc(Winapi::Messages::TMessage &Message)
.
Upvotes: 1
Views: 232
Reputation: 597860
Where are the
hwnd
,time
,pt
andlPrivate
members?
There aren't any such members in TMessage
.
MSG
is the structure that the Win32 API uses in a message loop to retrieve messages from a message queue, via the GetMessage()
and PeekMessage()
functions, prior to dispatching them to window procedures via DispatchMessage()
. The time
, pt
, and lPrivate
values are not delivered to a window procedure, however a window procedure can retrieve the time
and pt
values via the GetMessageTime()
and GetMessagePos()
functions, respectively (the lPrivate
value is not accessible).
TMessage
is the structure that the VCL uses in window procedures that are created by the RTL's MakeObjectInstance()
function. This function allows classes, like the VCL's TWinControl
and TTimer
, to use non-static virtual WndProc()
methods as Win32 window procedures.
In a standard Win32 window procedure, there are only 4 parameters available - hWnd
, uMsg
, wParam
and lParam
. An RTL-based window procedure ignores the hWnd
(as it already knows exactly which object method to call), copies the uMsg
, wParam
and lParam
values into a TMessage
, calls the target WndProc()
method passing it the TMessage
, and then returns the TMessage::Result
value back to the OS.
I'm in specially need of the
time
parameter. Is there a way to access the original message that TMessage is constructed from (or any other means to get the time parameter)?
If the message comes from the message queue of the thread that is calling your WndProc()
, you can use the Win32 API GetMessageTime()
function. Or, you can use the Win32 API SetWindowsHookEx()
function to install a WH_GETMESSAGE
hook into the thread's message queue.
If your component's WndProc()
is called in the main UI thread specifically, you can alternatively use the VCL's TApplication::OnMessage
or TApplicationEvents::OnMessage
events, which receive a copy of the original MSG
structure. Your component can use a private TApplicationEvents
object to hook the OnMessage
event.
However, a window procedure can receive both queued messages and non-queued messages, so if the message does not come from the calling thread's message queue at all, then there is simply no time
(or pt
) value available to retrieve for it, as non-queued messages do not go through the MSG
structure to begin with.
I'm handling my messages in TComponent::WndProc(Winapi::Messages::TMessage &Message).
TComponent
does not have a WndProc()
method. Perhaps you are thinking of TWinControl::WndProc()
instead?
Upvotes: 3