[lazarus] More Native Win32 stuff(Pascal,canyouhelphere?)

Michael A. Hess mhess at miraclec.com
Tue Aug 10 16:41:05 EDT 1999


OK I did some digging in the Windows API when I got home and here is
what I have found.

First off you will be handling this exactly the same way we are doing it
for GTK. The only difference is that you are going to be calling the
Windows API.

If you look in the current gtkint unit you will see that in
IntSendMessage3 (this will eventually be the only routine for handling
messages) the LM_Create message calls CreateComponent passing it the
Sender value. This is the Pointer to the TObject that is requesting
creation. In our example it is a Form (aka window).

Now if you look in the CreateComponent routine you see that it next
determines what it needs to create by looking at the CompStyle found in
the TControl Class which is what Sender represents. Again we assume in
this case that this is csForm since we want to create a Form (aka
window).

It is in this csForm section where you will to the actual call to the
Windows API (CreateWindow or CreateWindowEx) to make the window. Now as
the API states before this returns it sends the WM_CREATE message to the
Windows Procedure. Well the Windows Procedure is the callback handler
from Windows. This is what you need to define in the WNDCLASS structure
for the CLASS (window class) that you are creating. This Window
Procedure routine will be located within the win32int unit.

You will need to have it point to a procedure that matches that which
Windows expects to be calling. In the API it looks like this:

LRESULT CALLBACK WindowProc(

    HWND  hwnd,	// handle of window
    UINT  uMsg,	// message identifier
    WPARAM  wParam,	// first message parameter
    LPARAM  lParam 	// second message parameter
   );	

but you will have to adjust the types to match what is setup in Free
Pascal.
 
Now when this procedure receives the message which in this case is
WM_CREATE, you actually want to send:

TObject().Dispatch(LM_CREATE);

Which will call any

    procedure DoCreate(var msg); message LM_CREATE;

that has been setup for the control and that will in turn call a
OnCreate TNotifyEvents that have been established for this control.

To do this you will need to case the WindowProc callback to determine
which message is sent and translate it to the appropriate LM_XXX
message.

OK, now after all of that, here is the only part that you have to get
cute about. You need to be able to determine WHICH LCL control needs to
receive the Dispatch. In GTK you are able to pass a pointer to user
specific data that can be anything you wish. It is in this data, that
gets passed to the callback, were we placed the pointer to Self. This is
then how we call the correct Dispatch by doing.

TObject(data).Dispatch(LM_XXX);

were data was the passed value containing "Self".

In Windows it passes back the HWND for the control. That doesn't relate
to the LCL control at all. You will have to figure out a way to relate
the HWND value to the control created by the LCL. At this point I'm not
exactly sure how to do that but it should be possible all the same.
Either you need to relate HWND or you need to find a way to pass
additional information, the "Self" value, back to the callback routine.


Now have I made things clearer or have I just muddied the water more?

:-)

-- 
==== Programming my first best destiny! ====

Michael A. Hess      Miracle Concepts, Inc.
mhess at miraclec.com   http://www.miraclec.com






More information about the Lazarus mailing list