Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: VCL Message Map Question


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 1 - Last Post: Sep 15, 2017 5:39 PM Last Post By: Remy Lebeau (Te... Threads: [ Previous | Next ]
Michael Thomason

Posts: 14
Registered: 9/6/10
VCL Message Map Question  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 15, 2017 5:19 PM
All:

If you have a form with a BEGIN_MESSAGE_MAP and END_MESSAGE_MAP component defined, at what point is the "message map" active? For example, if I make a call to PostMessage in the OnCreate, Constructor, etc. before the form is shown the message does not appear to be received -- and this makes sense as you are "creating" the form.

My main form is not hidden and I am work around with a timer but I'm very curious about VCL at what point the form would be ready to receive messages.

I am also aware of "Perform" and this seems to work much earlier than PostMessage.

Hope this makes sense.

Edited by: Michael Thomason on Sep 15, 2017 5:19 PM
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: VCL Message Map Question [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 15, 2017 5:39 PM   in response to: Michael Thomason in response to: Michael Thomason
Michael Thomason wrote:

If you have a form with a BEGIN_MESSAGE_MAP and END_MESSAGE_MAP
component defined, at what point is the "message map" active?

Immediately. All it does is override the virtual Dispatch() method (to
put a switch statement inside of it to call class methods for each
handled message). Dispatch() receives any message that the Form's
WndProc() passes down to a base class WndProc(), and that
TControl::WndProc() does not discard as internally handled.

For example, if I make a call to PostMessage in the OnCreate,
Constructor, etc. before the form is shown the message does not
appear to be received

Yes, it is, as long as the Form's window does not get recreated before
the message comes out of the message queue.

My main form is not hidden and I am work around with a timer but
I'm very curious about VCL at what point the form would be ready to
receive messages.

As soon as it is created. But you have to watch out for recreations.
If that is proving to be troulesome, use the OnShow event instead, or
even OnPaint, to post your startup message when the Form is made
visible onscreen. Or, use AllocateHWnd() to create a persistent HWND
you can post messages to. Or post them to Application.Handle and then
use Application.OnMessage or Application.HookMainWindow() to receive
them.

I am also aware of "Perform" and this seems to work much earlier than
PostMessage.

Perform() directly calls the Form's WindowProc procedure (which points
to the WndProc() method by default). It doesn't go through the message
queue (or the Win32 API) at all.

--
Remy Lebeau (TeamB)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02