First, let me say to Borje Hagsten, you did a good job on
the Oval Button code.
There are a few things you need to change to make the button
code work properly though.
First, you "never" use Global variables for tracking data for a
custom control. You need to add some "extra" window bytes when you
register the control class. These bytes (4 per Long) are used to
store unique data for each "instance" of the control window.
Things like handles to Bitmaps, MemDCs, Brushes and regions should
be stored in those extra bytes using SetWindowLong. You create all
the GDI resources in the WM_CREATE message, put their handles in the
extra bytes using SetWindowLong, retrieve the handles when you need
them (ie. WM_PAINT) using GetWindowLong and then destroy the resources
in WM_DESTROY.
Using "Global" variables for tracking unique data per instance of
a custom control, will cause serious problems with how your control
works. I noticed in your code (I tested it), the buttons would
respond to mouse clicks a few times and then stop responding.
I'll post a sample custom control's source code below to demonstrate
how to use the extra window bytes. (The control doesn't do much, but
simply demonstrates the proper design techniques for custom controls)
For more info on writing custom controls, get the book :
Windows Custom Controls
by William Smith and Robert Ward
Published by : R & D Publications, Inc. (USA)
The book is for Windows 3.1, but the basic concepts haven't
changed.
------------------
the Oval Button code.
There are a few things you need to change to make the button
code work properly though.
First, you "never" use Global variables for tracking data for a
custom control. You need to add some "extra" window bytes when you
register the control class. These bytes (4 per Long) are used to
store unique data for each "instance" of the control window.
Things like handles to Bitmaps, MemDCs, Brushes and regions should
be stored in those extra bytes using SetWindowLong. You create all
the GDI resources in the WM_CREATE message, put their handles in the
extra bytes using SetWindowLong, retrieve the handles when you need
them (ie. WM_PAINT) using GetWindowLong and then destroy the resources
in WM_DESTROY.
Using "Global" variables for tracking unique data per instance of
a custom control, will cause serious problems with how your control
works. I noticed in your code (I tested it), the buttons would
respond to mouse clicks a few times and then stop responding.
I'll post a sample custom control's source code below to demonstrate
how to use the extra window bytes. (The control doesn't do much, but
simply demonstrates the proper design techniques for custom controls)
For more info on writing custom controls, get the book :
Windows Custom Controls
by William Smith and Robert Ward
Published by : R & D Publications, Inc. (USA)
The book is for Windows 3.1, but the basic concepts haven't
changed.
------------------
Comment