Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Button with Canvas

843 views
Skip to first unread message

Erik

unread,
Nov 27, 2012, 5:42:16 PM11/27/12
to
Anyone know how to get access to the Canvas on a Button please?
(Don't want BitBtn with imagelists and images - just a vanilla flavoured
canvas!)
Reckon it's got to be there somewhere to put the Caption on . . .

Erik.


Peter

unread,
Nov 28, 2012, 2:42:13 AM11/28/12
to
A standard TButton is just a wrapper for the Windows pushbutton
control, it is completely drawn by Windows, not by VCL code.

The Windows button control has support for "owner-drawing", which is
actually used by TBitBtn internally. To enable this feature the button
has to use the BS_OWNERDRAW window style. Windows then sends
WM_MEASUREITEM and WM_DRAWITEM messages to the button's parent window.
The VCl containers are designed to send these messages back to the
button as CN_MEASUREITEM and CN_DRAWITEM, respectively. These are the
messages you would have to handle in a custom button, and you would do
all drawing inside the handler for the CN_DRAWITEM message.

If you have a Delphi version that includes the source code, look at
buttons.pas, find the source for TBitBtn.CreateParams (that is where
you set the button style) and TBitBtn.CNMeasureItem and
TbitBtn.CNDrawItem, that is where the two messages are handled.

--
Peter Below

JJ

unread,
Nov 28, 2012, 2:54:11 AM11/28/12
to
Not all controls provide a Canvas. So, you'll need to create it using a hDC
that is retrieved from GetWindowDC or GetDC. You'll likely need to handle
WM_PAINT and possibly WM_NCPAINT messages too.

Erik

unread,
Nov 30, 2012, 4:42:12 AM11/30/12
to
Many thanks, Peter. That explains why I was sweating trying to find things
in the tButton code.
If I get lazy and don't want quite that amount of work, I might just have
small tImage components
and click on them instead! I will read those bits for mine own exucation
with great interest, however.
Erik.

"Peter" <no...@nomail.please> wrote in message
news:xn0i645z...@news.online.de...

Erick Engelke

unread,
Nov 30, 2012, 4:16:19 PM11/30/12
to
On Fri, 30 Nov 2012, Erik wrote:

> Many thanks, Peter. That explains why I was sweating trying to find things
> in the tButton code.

I haven't looked yet, people have described the behaviour with the
VLC, would this be different in a firemonkey app?

Erick

Peter

unread,
Dec 1, 2012, 5:13:17 AM12/1/12
to
Firemonkey controls are completely drawn by code in the Delphi run-time
library/VCL.

--
Peter Below
0 new messages