Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating a new CheckBox with self drawing method ???

Status
Not open for further replies.

iCounter

Programmer
Feb 10, 2004
6
0
0
RO
I was working on a package of controls for Builder and i'm stuck with creating a new CheckBox with my own drawing.
I've tried :
class XCheckBox : public TCustomCheckBox
{
....
};
but is not working, the class TCustonCheckBox do not include Canvas, and I can't draw the control.

I need to create a Canvas for the control, and i tried and it didn't work.

Sorry for my English !! :)))
 
Try to declare the Canvas method the same way Borland does in in TGraphicControl. The source code is in Delphi, but you should be able to 'translate' it into C++.
 
A two part process should suffice.

1) Overload the WinProc() procedure within your class and capture the Paint message. Something like:

XCheckBox::WinProc(TMessage &AMsg)
{
. . . .
// Pass the messages on to the default window procedure.
TCheckBox::WndProc(AMsg);
. . . .
if (AMsg.Msg == WM_PAINT)
{
std::auto_ptr<TCanvas> canvas(new TCanvas());
canvas->Handle = GetDC(Handle);
DoSomethingWithCheckBox(*canvas);
ReleaseDC(Handle, canvas->Handle);
}
}

2) Use a custom method to manipulate TCanvas functionality (in this example the DoSomethingWithCheckBox(*canvas) method). Use TRect objects to manipulate regions specific to the intended portions of the TCheckbox component.

-----------------------------------
Wisdom doesn't always come with age. Sometimes age comes alone.
(you're never too old to learn)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top