I would like to change the font size on the text in edit boxes or/and static text boxes. The only change i have been able to make is through properties of the dialog box where i set the font for all of the items of the dialog box, although i cannot set bold for example, but i would like to set the fonts for the text boxes differently than the whole dialog box. I see no such similar capability in the properties of the text box. Is there a way to do this, either via program code or through the properties of the text box ? Thanks.
Comments
If you want all text boxes to be of a certain font, all labels of another, etc, then you might write some code like this:
[code]
INT WINAPI DialogProc(HWND hDlg, ...
{
switch(message)
{
case WM_INITDIALOG:
{
// enumerate all children
HWND hControl = GetWindow(hDlg, GW_CHILD);
while(hControl != null)
{
// get the class name
TCHAR className[800];
GetClassName(hControl, className, sizeof(className));
// set the font based on class
if(lstrcmpi(className, "edit") == 0)
SendMessage(hControl, WM_SETFONT, hEditBoxFont, 0);
else if(lstrcmpi(className, "static") == 0)
SendMessage(hControl, WM_SETFONT, hStaticFont, 0);
// get next control
hControl = GetWindow(hControl, GWL_HWNDNEXT);
}
[/code]
: I would like to change the font size on the text in edit boxes or/and static text boxes. The only change i have been able to make is through properties of the dialog box where i set the font for all of the items of the dialog box, although i cannot set bold for example, but i would like to set the fonts for the text boxes differently than the whole dialog box. I see no such similar capability in the properties of the text box. Is there a way to do this, either via program code or through the properties of the text box ? Thanks.
:
: via code, you need to send the hFont to the control windows via WM_SETFONT. Check it out in MSDN.
:
: If you want all text boxes to be of a certain font, all labels of another, etc, then you might write some code like this:
:
: [code]
: INT WINAPI DialogProc(HWND hDlg, ...
: {
: switch(message)
: {
: case WM_INITDIALOG:
: {
: // enumerate all children
: HWND hControl = GetWindow(hDlg, GW_CHILD);
: while(hControl != null)
: {
: // get the class name
: TCHAR className[800];
: GetClassName(hControl, className, sizeof(className));
:
: // set the font based on class
: if(lstrcmpi(className, "edit") == 0)
: SendMessage(hControl, WM_SETFONT, hEditBoxFont, 0);
: else if(lstrcmpi(className, "static") == 0)
: SendMessage(hControl, WM_SETFONT, hStaticFont, 0);
:
: // get next control
: hControl = GetWindow(hControl, GWL_HWNDNEXT);
: }
: [/code]
:
:
:
: : I would like to change the font size on the text in edit boxes or/and static text boxes. The only change i have been able to make is through properties of the dialog box where i set the font for all of the items of the dialog box, although i cannot set bold for example, but i would like to set the fonts for the text boxes differently than the whole dialog box. I see no such similar capability in the properties of the text box. Is there a way to do this, either via program code or through the properties of the text box ? Thanks.
: :
:
:
LOGFONT lf={0};
HFONT hFont;
HDC hScreenDC = GetDC (NULL);
int iPixelsPerInch = GetDeviceCaps (hScreenDC, LOGPIXELSY);
int iPointSize=9; // Font will be -> Tahoma,9
strcpy (lf.lfFaceName, "Tahoma");
lf.lfWeight = FW_NORMAL;
lf.lfHeight = -MulDiv (iPointSize, iPixelsPerInch, 72);
ReleaseDC (NULL, hScreenDC);
hFont = CreateFontIndirect (&lf); // <- here is your font handle.
[/code]
: [code]
: LOGFONT lf={0};
: HFONT hFont;
: HDC hScreenDC = GetDC (NULL);
: int iPixelsPerInch = GetDeviceCaps (hScreenDC, LOGPIXELSY);
: int iPointSize=9; // Font will be -> Tahoma,9
:
: strcpy (lf.lfFaceName, "Tahoma");
: lf.lfWeight = FW_NORMAL;
: lf.lfHeight = -MulDiv (iPointSize, iPixelsPerInch, 72);
: ReleaseDC (NULL, hScreenDC);
: hFont = CreateFontIndirect (&lf); // <- here is your font handle.
: [/code]
:
: [code]
: LOGFONT lf={0};
: HFONT hFont;
: HDC hScreenDC = GetDC (NULL);
: int iPixelsPerInch = GetDeviceCaps (hScreenDC, LOGPIXELSY);
: int iPointSize=9; // Font will be -> Tahoma,9
:
: strcpy (lf.lfFaceName, "Tahoma");
: lf.lfWeight = FW_NORMAL;
: lf.lfHeight = -MulDiv (iPointSize, iPixelsPerInch, 72);
: ReleaseDC (NULL, hScreenDC);
: hFont = CreateFontIndirect (&lf); // <- here is your font handle.
: [/code]
:
: : [code]
: : LOGFONT lf={0};
: : HFONT hFont;
: : HDC hScreenDC = GetDC (NULL);
: : int iPixelsPerInch = GetDeviceCaps (hScreenDC, LOGPIXELSY);
: : int iPointSize=9; // Font will be -> Tahoma,9
: :
: : strcpy (lf.lfFaceName, "Tahoma");
: : lf.lfWeight = FW_NORMAL;
: : lf.lfHeight = -MulDiv (iPointSize, iPixelsPerInch, 72);
: : ReleaseDC (NULL, hScreenDC);
: : hFont = CreateFontIndirect (&lf); // <- here is your font handle.
: : [/code]
: :
:
:
[blue]It is done, because the point (Tahoma,9pt) is 1/72 of an inch and with this function we can find how many pixels it will be on our HDC - whatever it is - it can be printer DC...
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/fontext_1wmq.asp[/blue]