Board index » cppbuilder » TCanvas.CreateHandle

TCanvas.CreateHandle


2003-12-15 09:54:33 AM
cppbuilder66
hi there
how come TCanvas.CreateHandle is a empty procedure?
Anyway... which is the EASY way to TextExtent a string without have any canvas.
I'tried
TCanvas *c = new TCanvas();
c->Font->Name = "Tahoma";
c->Font->Size = 10;
/* Raise exceptio here! */
/* since VCL graphics.pas source code @ line .... well I forget (method TCanvas.CreateHandle())
is an empty procedure so FHandle property still be the same as the constructed.... say Nil. */
c->TextWidth( AnsiString( "my_string" ) );
delete c;
So I've try to use CreateCompatibleDC based on some hWnd... but I don't know if its that the correct way OR EVEN LOOSSING MEMORY.
thanks in advnace.
 
 

Re:TCanvas.CreateHandle

"KonZa" <konza---nospamplease---operamail.com>wrote in message
Quote
how come TCanvas.CreateHandle is a empty procedure?
Because TCanvas can be used as a base class for other classes that may have
specialized Handles for their own purposes. TCanvas itself has no concept
of how it will be used, so it is the calling code's responsibility to fill
in the Handle property as needed. If you look at TBitmapCanvas or
TControlCanvas, for example, you will see that they override CreateHandle()
to provide specialized handles when needed.
Quote
which is the EASY way to TextExtent a string without have any canvas.
You cannot do that at all. You must have a Canvas of some kind available,
since you need to take into account the specific properties of the
particular device that the string is going to be rendered to. There is no
point in determining the pixel dimensions of a string if you are not going
to display the string on a pixel-based device in the first place, such as
the screen or an image.
Quote
So I've try to use CreateCompatibleDC based on some hWnd... but
I don't know if its that the correct way
What *EXACTLY* are you trying to accomplish? Why are you trying to
determine the string's dimensions in the first place?
Gambit
 

Re:TCanvas.CreateHandle

On Sun, 14 Dec 2003 18:09:04 -0800, Remy Lebeau (TeamB) < XXXX@XXXXX.COM >wrote:
Thanks. Now I'm recalling windows semantics... ;-)
Thanks agains for interesting in my issue.
I'm have subclassed some Windows private window class (for instance TrayClockWClass) and I've manage the WM_PAINT message so far but I need to resize that window to fit some long text (string) so I need to messure how low in pixel that would be.
Since the Canvas is created in the WM_PAINT handler because I get the HDC from there from ::BeginPaint(...) sutff APIs and the resise issue is in another part of the code I need to know for advance how long in pixel would it take.
I dunno if I mixing don't-know-how-window-progrmaming but then I don't know how to messuere that.
Well .... thanks
 

{smallsort}

Re:TCanvas.CreateHandle

"KonZa" <konza---nospamplease---operamail.com>wrote in message
Quote
I need to resize that window to fit some long text (string) so I
need to messure how low in pixel that would be.
If you have an HWND for the desired window that you want to draw text to,
then simply use GetDC() or GetWindowDC() to get the HDC for the window, and
then you can assign the HDC to the TCanvas's Handle property. Or forget the
TCanvas altogether and just call GetTextExtentPoint32() directly.
Gambit