Board index » delphi » how to catch WM_DRAWITEM and WM_MEASURE_ITEM of a Form or Menu from within a component

how to catch WM_DRAWITEM and WM_MEASURE_ITEM of a Form or Menu from within a component

To All Delphi Users,

Problem:
=========

[Q] how to catch WM_DRAWITEM and WM_MEASUREITEM of a Form or Menu from
within a component.

I have tried to catch these messages from within my WndProc procedure in
my component, but these
messages never get trapped there.  

I am although able to trap WM_INITMENU from within that WndProc
procedure (which overrides my
forms WndProc).

I am able to trap the WM_DRAWITEM and WM_MEASUREITEM event in the form
itself by declaring
a WM_DRAWITEM and WM_MEASUREITEM messages in the private portion of the
form, but this is
not what I want.

Any solution would be greatly appreciated.  

P.S. : Some piece of code might also be nice :)

Daniel Lortie
dlor...@nt.com

 

Re:how to catch WM_DRAWITEM and WM_MEASURE_ITEM of a Form or Menu from within a component


My quick answer is.... you can't very easily.
It needs to be a windowed control, and NOT a component, beause you need to
know whenever your form recreates its HWND so you can re-override its
wndproc.

If I were you I would create a new form based on TForm, and override the
wndproc normally.
Its much the best way, unless you want heavy wizardry.

As for a code snippet:

TMyFlashyForm=class(TForm)
Protected
  Procedure WndProc(.....); override;
end;

And then edit your .pas file for all your forms so instead of

TForm1=class(TForm)

you have

TForm1=class(TMyFlashyForm)

ask if you need more specific stuff.

--
Sam Liddicott                   |   Nothing I say is to be attributed as |
Campbell Scientific Ltd.        | a company statement or representation. |
Campbell Park, 80 Hathern Road, *----------------------------------------+
Shepshed, Leic. United Kingdom. LE12 9AL        Phone: +44 (0) 1509 601141
Email: s...@campbellsci.co.uk                    Fax:   +44 (0) 1509 601091

Daniel Lortie <dlor...@nt.com> wrote in article <334429ED.2...@nt.com>...

Quote
> To All Delphi Users,

> Problem:
> =========

> [Q] how to catch WM_DRAWITEM and WM_MEASUREITEM of a Form or Menu from
> within a component.

> I have tried to catch these messages from within my WndProc procedure in
> my component, but these
> messages never get trapped there.  

> I am although able to trap WM_INITMENU from within that WndProc
> procedure (which overrides my
> forms WndProc).

> I am able to trap the WM_DRAWITEM and WM_MEASUREITEM event in the form
> itself by declaring
> a WM_DRAWITEM and WM_MEASUREITEM messages in the private portion of the
> form, but this is
> not what I want.

> Any solution would be greatly appreciated.  

> P.S. : Some piece of code might also be nice :)

> Daniel Lortie
> dlor...@nt.com

Other Threads