CTabCtrl FONT

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Greetings,

Am trying to change the font of a CTabCtrl I have in my Main Frame Window
(not a Dialog Box).

Since CTabCtrl is based in CWnd, I figured that SetFont() should work.

No luck. And there are no CTabCtrl member functions specifically for
changing the font.

My code looks like this. The Tabs work fine. I just can't change the size.

Any idea what I am doing wrong???

Thanks,

Mike
************************************************
class CMainFrame : public CFrameWnd
{
public:
CTabCtrl myTab;
************************************************
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
CRect r;
GetClientRect(&r);

myTab.Create(TCS_TABS |TCS_BOTTOM|TCS_MULTILINE ,r, this, 2345);

CFont font;
font.CreateFont( 10, 0, 0, 0,FW_NORMAL,0,0,0,0,0,0,0,0, "Arial"));
myTab.SetFont(&font,TRUE);

TC_ITEM T;
T.mask = TCIF_TEXT;
T.pszText = "PLOT 1"; myTab.InsertItem(0, &T );
T.pszText = "PLOT 2"; myTab.InsertItem(1, &T );
T.pszText = "PLOT 3"; myTab.InsertItem(2, &T );
T.pszText = "PLOT 4"; myTab.InsertItem(3, &T );

myTab.ShowWindow(SW_SHOWNORMAL);

return 0;
}
 
CFont font;
font.CreateFont( 10, 0, 0, 0,FW_NORMAL,0,0,0,0,0,0,0,0, "Arial"));
myTab.SetFont(&font,TRUE);

The problem will undoubtedly be because your CFont object gets
destroyed. Make it a member variable of the container of the tab
control so that it exists for the lifetime of the tab control.

Dave
 
Greetings,

Thanks so much for the help Dave. I'm learning as I am going, and there is
so much to learn about C++ programming that it's like trying to find a needle
in a hackstack sometimes. The most obvious things, are the ones that aren't
discussed in articles and Help files, and cause me the most difficulties.

I read all about CTabCtrl, and was frustrated for several days trying to get
it to work until I tried using.... "myTab.ShowWindow(SW_SHOWNORMAL) "

Obviously the authors of the CtabCtrl Help assumed that I would know to do
that.

Same with the Font thing. I assumed that once I told a control what to do,
it kept an copy of that instruction. Didn't know that the instruction info
had to stay alive all the time the control did. Sure enough now it works.

Thanks againt for your timely help and patience with these novice questions.

Mike
 
Back
Top