IonicWind Software

Aurora Compiler => GUI => Topic started by: Bruce Peaslee on January 28, 2006, 01:18:21 PM

Title: Use of GetTextSize() in a subclassed dialog
Post by: Bruce Peaslee on January 28, 2006, 01:18:21 PM
I use the function GetTextSize() successfully in a subclassed window to help me center text. When I want to get text information in a subclassed dialog, all I get are zeroes.
Title: Re: Use of GetTextSize() in a subclassed dialog
Post by: Parker on January 28, 2006, 01:30:15 PM
That function has to look up the information from a window's device context (DC). And seeing as you can't draw to dialogs, I don't think they have a DC.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/fontext_8smq.asp
However, you can create your own DC and set its font information using CreateFont or CreateFontIndirect. Remember to free it once you're done.
Title: Re: Use of GetTextSize() in a subclassed dialog
Post by: Parker on January 28, 2006, 02:03:57 PM
This seems to do something at least
#define LF_FACESIZE 32
struct LOGFONT
{
unsigned int lfHeight;
unsigned int lfWidth;
unsigned int lfEsapement;
unsigned int lfOrientation;
unsigned int lfWeight;
byte lfItalic;
byte lfUnderline;
byte lfStrikeOut;
byte lfCharSet;
byte lfOutPrecision;
byte lfClipPrecision;
byte lfQuality;
byte lfPitchAndFamily;
dstring lfFaceName[LF_FACESIZE];
}

DECLARE IMPORT,GetTextExtentPoint32 alias GetTextExtentPoint32A(
hdc as unsigned int,
lpszStr as STRING,
cbString as INT,
lpSize as POINT
),INT;

declare import, CreateFontIndirect alias CreateFontIndirectA(
LOGFONT *lf
),unsigned int;

declare import, DeleteObject(
unsigned int hObject
),int;

declare import, DeleteDC(
unsigned int hDC
),int;

declare import, CreateCompatibleDC(
unsigned int hDC
),unsigned int;

declare import, CreateCompatibleBitmap(
unsigned int hDC,
int nWidth,
int nHeight
),unsigned int;

declare import, ZeroMemory alias RtlZeroMemory(
void *Destination,
unsigned int Length
);

declare import, MulDiv(
int nNumber,
int nNumerator,
int nDenominator
),int;

declare import, SelectObject(
unsigned int hdc,
unsigned int hgdiobj
),unsigned int;

declare import, GetDeviceCaps(
unsigned int hdc,
int nIndex
),int;

global sub main()
{
LOGFONT lf;
POINT pt;
unsigned int hFont, hBitmap, hDC;

hDC = CreateCompatibleDC(0);
hBitmap = CreateCompatibleBitmap(hDC, 100, 100);

ZeroMemory(&lf, len(LOGFONT));
// Fill the members of lf that you want
lf.lfFaceName = "Courier New";
lf.lfHeight = -MulDiv(10, GetDeviceCaps(hDC, 90 /*LOGPIXELSY*/), 72);
lf.lfWeight = 100;
lf.lfQuality = 1; /*DRAFT_QUALITY*/
lf.lfPitchAndFamily = 0; /*DRAFT_PITCH*/
hFont = CreateFontIndirect(&lf);

// Set 'lf' as the DC's font
SelectObject(hDC, hFont);

GetTextExtentPoint32(hDC, "Hello", len("Hello"), pt);
writeln("x: " + str$(pt.x,0) + " - y: " + str$(pt.y,0));

DeleteObject(hBitmap);
DeleteDC(hDC);
DeleteObject(hFont);

do{}until (GetKey() <> "");
}


Try it with your dialog and let me know if it works ;)
Title: Re: Use of GetTextSize() in a subclassed dialog
Post by: Bruce Peaslee on January 28, 2006, 04:22:17 PM
It works, but not for want I want.ÂÃ,  ;)

This is a better explanation of what I am trying to do. I am putting a static control on a dialog into which I will write some text. I want to resize the static control depending on how much text (how high). If I know the font size, I can compute the size based on the number of lines. I know how to set the control's font but not how to get it. Another way is to use GetTextSize, but I can't make it work for a dialog control. Your example works well, but requires knowledge of the font.

I'm trying to make my class as generic as possible so I want to avoid setting the control's font.
Title: Re: Use of GetTextSize() in a subclassed dialog
Post by: Bruce Peaslee on January 28, 2006, 05:52:11 PM
Quote from: peaslee on January 28, 2006, 04:22:17 PM
I'm trying to make my class as generic as possible so I want to avoid setting the control's font.

Oops - I hadn't thought this through. I'm either setting font or the programmer would be (if the class is given that capability), so I will know its size. I'm still curious about the answer, but if I had been thinking clearly, the question would never have come up.ÂÃ,  ÂÃ, :-[
Title: Re: Use of GetTextSize() in a subclassed dialog
Post by: Parker on January 28, 2006, 07:21:41 PM
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/windows/windowreference/windowmessages/wm_getfont.asp
You can send a WM_GETFONT message to that control, or you can get its DC. Maybe a pControl->GetTextSize() call? The control is derived from window so you can do that.