[lazarus] Developing win32

Mattias Gaertner nc-gaertnma at netcologne.de
Sat Nov 30 03:46:54 EST 2002


On Fri, 29 Nov 2002 21:44:39 +0100
"Vincent Snijders" <vslist at zonnet.nl> wrote:

> Hi,
> 
> Lately I have been lookint at the win32 interface, trying to make it work
> a bit better.
> 
> I have never done any low level win32 api programming, so I am a bit in
> the dark. Still I want to share with you two things which trouble me a
> lot. Maybe some of you can help me a bit further.
> 
> Firstly it is not clear what messages the LCL is expecting from an
> interface object and what messages the an interface object is suposed to
> handle. The only way is to look at the gtk interface and put some (a lot)
> writelns to see what it does. An example is the the LM_DESTROY message
> from the interface to the LCL. When you run lazarus (with gtk on linux) it
> only seems to be sent for TPage object and not for TForm.

This is because the LCL+gtk does not need any LM_Destroy messages sent back
from the interface. But you are right, they should be sent for
compatibility.


> If you happen to do so on
> win32 you get into problems for freeing the form twice (once on the
> LM_DESTROY message and once when Application.Free is called).

This was a bug in the LCL. Fixed.


> I think it
> would be great if there were a document which specified what messages the
> LCL expects and sends.

It would be cool to have any docs at all.
I'm currently improving the lazarus synedit and hope to write a little help
browser, so that we can finally start the online help for lazarus.
To your question:
I don't know the winapi either. When I implemented a message, I looked what
the VCL does with it. Therefore many messages are VCL compatible, but not
really win32 compatible.


> Secondly I have problems writing a good windowproc.
> For example I have this window procedure to handle windows messages (see
> below). It only works if I comment out the assert, I don't understand why.
> If I don't comment out the assert in, I get an access violation when I
> create a window which uses this windowproc. Do I use the right calling
> convention (stdcall)? Are there some RTL-functions I may not use in a
> windowproc? Or is there somewhere else some memory corruption which shows
> up here. I just don't know enough of the win32 api. Very frustating.
> 
> function WindowProc(Window: HWnd; Msg: UInt; WParam: WParam; LParam:
> LParam): LResult; stdcall;
> var
>   LMessage: TLMessage;
>   LCLObject: TObject;
>   CallDefWindowProc: boolean;
> begin
>   Assert(False,
>     Format('Trace:WindowProc - Window Value: $%S-%d; Msg Value: %S;
>     WParam:
> $%S; LParam: $%S',
> 	[IntToHex(Window, 4), Window, WM_To_String(Msg), IntToHex(WParam,
> 	4), IntToHex(LParam, 	4)]));
>   CallDefWindowProc := true;
>   case Msg of
>     WM_CLOSE:
>     Begin
>       Assert(False, 'Trace:WindowProc - Got WM_CLOSE');
>       LMessage.Msg := LM_CLOSEQUERY;
>       LCLObject := TObject(GetProp(Window, 'Lazarus'));
>       Result := DeliverMessage(LCLObject,LMessage);
>       CallDefWindowProc := false;
>     End;
>   end;
>   if CallDefWindowProc
>     then Result := DefWindowProc(Window, Msg, WParam, LParam);
> end;
> 
> 
> Hope somebody can give me some pointers in the right direction.

Good luck.

Mattias






More information about the Lazarus mailing list