I ran into some rather odd behavior using SetFont. Here's the code in question:
#autodefine "off"
#define IDC_LABEL_HOSTNAME 1
#define IDC_EDIT_HOSTNAME 2
#define IDC_LABEL_HOSTPORT 3
#define IDC_EDIT_HOSTPORT 4
#define IDC_BUTTON_VIEWPAGE 5
#define IDC_LABEL_FILENAME 6
#define IDC_EDIT_FILENAME 7
#define IDC_EDIT_FILEVIEW 8
#define IDC_LABEL_STATUS 9
class CPageViewDlg:dialog
{
declare OnInitDialog(),int;
declare OnClose(),int;
declare OnControl(int nID, int nNotifyCode, unsigned int hControl),int;
// Member variables
CEdit* m_editHostName;
CEdit* m_editHostPort;
CEdit* m_editFileName;
CEdit* m_editFileView;
CButton* m_btnViewPage;
CStatic* m_labelStatus;
}
global sub main()
{
CPageViewDlg dlg;
dlg.Create(0,0,471,336,0x80CA0080,0,"Test Program",0);
dlg.AddControl(CTSTATIC,"Server:",12,15,50,20,0x5000010B,0x0,IDC_LABEL_HOSTNAME);
dlg.AddControl(CTEDIT,"www.ionicwind.com",63,11,214,22,0x50810000,0x200,IDC_EDIT_HOSTNAME);
dlg.AddControl(CTSTATIC,"Port:",289,15,30,20,0x5000010B,0x0,IDC_LABEL_HOSTPORT);
dlg.AddControl(CTEDIT,"80",320,11,48,22,0x50812000,0x200,IDC_EDIT_HOSTPORT);
dlg.AddControl(CTDEFBUTTON,"View",387,10,70,24,0x5001000B,0x0,IDC_BUTTON_VIEWPAGE);
dlg.AddControl(CTSTATIC,"File:",13,41,40,20,0x5000010B,0x0,IDC_LABEL_FILENAME);
dlg.AddControl(CTEDIT,"/",62,39,305,22,0x50810000,0x200,IDC_EDIT_FILENAME);
dlg.AddControl(CTEDIT,"",14,71,443,238,0x50B00004,0x200,IDC_EDIT_FILEVIEW);
dlg.AddControl(CTSTATIC,"",15,311,441,20,0x5000010B,0x0,IDC_LABEL_STATUS);
dlg.DoModal();
return;
}
CPageViewDlg::OnClose(),int
{
CloseDialog(1);
return true;
}
CPageViewDlg::OnInitDialog(),int
{
m_editHostName = GetControl(IDC_EDIT_HOSTNAME);
m_editHostPort = GetControl(IDC_EDIT_HOSTPORT);
m_editFileName = GetControl(IDC_EDIT_FILENAME);
m_editFileView = GetControl(IDC_EDIT_FILEVIEW);
m_btnViewPage = GetControl(IDC_BUTTON_VIEWPAGE);
m_labelStatus = GetControl(IDC_LABEL_STATUS);
// Calling SetFont causes the font for the other dialog
// controls to change to what looks like Arial 10pt Bold
m_editFileView->SetFont("Courier New", 9, 400);
CenterWindow();
return true;
}
CPageViewDlg::OnControl(int nID, int nNotifyCode, unsigned int hControl),int
{
select nID
{
case IDC_BUTTON_VIEWPAGE:
if(nNotifyCode = 0)
{
MessageBox(this, "IDC_BUTTON_VIEWPAGE", "Clicked");
}
}
return true;
}
If you comment out the call to SetFont, then everything looks fine. However, trying to change the font of one of the edit controls (in this case, a multiline edit control with scrollbars) causes the font to change for every other control on the dialog.
No it doesn't. Try this:
#autodefine "off"
#define IDC_LABEL_HOSTNAME 1
#define IDC_EDIT_HOSTNAME 2
#define IDC_LABEL_HOSTPORT 3
#define IDC_EDIT_HOSTPORT 4
#define IDC_BUTTON_VIEWPAGE 5
#define IDC_LABEL_FILENAME 6
#define IDC_EDIT_FILENAME 7
#define IDC_EDIT_FILEVIEW 8
#define IDC_LABEL_STATUS 9
class CPageViewDlg:cdialog
{
declare OnInitDialog(),int;
declare OnClose(),int;
declare OnControl(int nID, int nNotifyCode, unsigned int hControl),int;
// Member variables
CEdit* m_editHostName;
CEdit* m_editHostPort;
CEdit* m_editFileName;
CEdit* m_editFileView;
CButton* m_btnViewPage;
CStatic* m_labelStatus;
}
global sub main()
{
CPageViewDlg dlg;
dlg.Create(0,0,471,336,0x80CA0080,0,"Test Program",0);
dlg.AddControl(CTSTATIC,"Server:",12,15,50,20,0x5000010B,0x0,IDC_LABEL_HOSTNAME);
dlg.AddControl(CTEDIT,"www.ionicwind.com",63,11,214,22,0x50810000,0x200,IDC_EDIT_HOSTNAME);
dlg.AddControl(CTSTATIC,"Port:",289,15,30,20,0x5000010B,0x0,IDC_LABEL_HOSTPORT);
dlg.AddControl(CTEDIT,"80",320,11,48,22,0x50812000,0x200,IDC_EDIT_HOSTPORT);
dlg.AddControl(CTDEFBUTTON,"View",387,10,70,24,0x5001000B,0x0,IDC_BUTTON_VIEWPAGE);
dlg.AddControl(CTSTATIC,"File:",13,41,40,20,0x5000010B,0x0,IDC_LABEL_FILENAME);
dlg.AddControl(CTEDIT,"/",62,39,305,22,0x50810000,0x200,IDC_EDIT_FILENAME);
dlg.AddControl(CTEDIT,"x\ny\nz",14,71,443,238,0x50B00004,0x200,IDC_EDIT_FILEVIEW);
dlg.AddControl(CTSTATIC,"",15,311,441,20,0x5000010B,0x0,IDC_LABEL_STATUS);
dlg.DoModal();
return;
}
CPageViewDlg::OnClose(),int
{
CloseDialog(1);
return true;
}
CPageViewDlg::OnInitDialog(),int
{
m_editHostName = GetControl(IDC_EDIT_HOSTNAME);
m_editHostPort = GetControl(IDC_EDIT_HOSTPORT);
m_editFileName = GetControl(IDC_EDIT_FILENAME);
m_editFileView = GetControl(IDC_EDIT_FILEVIEW);
m_btnViewPage = GetControl(IDC_BUTTON_VIEWPAGE);
m_labelStatus = GetControl(IDC_LABEL_STATUS);
// Calling SetFont causes the font for the other dialog
// controls to change to what looks like Arial 10pt Bold
m_editFileView->SetFont("Courier New",20, 400);
CenterWindow();
return true;
}
CPageViewDlg::OnControl(int nID, int nNotifyCode, unsigned int hControl),int
{
select nID
{
case IDC_BUTTON_VIEWPAGE:
if(nNotifyCode = 0)
{
MessageBox(this, "IDC_BUTTON_VIEWPAGE", "Clicked");
}
}
return true;
}
Eh? All it looks like you did is change it to a 20pt font size. And I get exactly the same behavior.
Here's how it looks with "This is a test" added to the multiline textbox and the SetFont method commented out:
(http://proteus.catalyst.com/~mike/images/screen1.jpg)
Here's how it looks with SetFont used:
(http://proteus.catalyst.com/~mike/images/screen2.jpg)
Regardless of whatever values are passed to SetFont for a given control, there's no way that should be affecting the fonts used when drawing the other other controls on a dialog.
Oh, and using the code exactly as you posted it, this is what I get:
(http://proteus.catalyst.com/~mike/images/screen3.jpg)
This is on Windows XP SP2 with themes enabled. It's a stock system, no custom interface changes (ie: no WindowBlinds or anything like that running). I'm using the latest build of the compiler.
I've wasn't able to get SetFont working with a control, but if you look at the gui.inc file, the last parameter is one for a control ID, so I ended up using code like this
for (i = 1; i <= 6; i++)
{
SetFont(wnd, "FontName", extra_params, i);
}
I don't remember the number of params offhand, but until it is fixed you can use that way.
SetFont in a derived class won't work in OnInitDialog currently. It defaults to setting the font of the dialog. Mainly because I tried to automatically determine whether it was being called from a control class by testing certain conditions. Unfortunately one of those conditions isn't set when OnInitDialog is called.
I have to make SetFont a virtual method so I can override it in the control class instead.
For now use the method parker mentions.
dlg.SetFont("Arial",12,400,0,id)
Where 'id' is the id of the control you want to set up.
Thanks, will do. :)