改變 static 字體大小的設定 , 

可以利用  pWnd->GetDlgCtrlID() 來取得目前控件 ID 來判斷要改變字型大小的物件

 

// 設定 Dialog 中的 WM_CTLCOLOR 

HBRUSH CT400Dlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{

if (pWnd->GetDlgCtrlID()==IDC_TEST2)
{
CFont Font;
CString css;


css.Format("Arial");
 
Font.CreatePointFont(160,css);
pDC->SelectObject(&Font);
}


// TODO:  Return a different brush if the default is not desired
return hbr;
}

 

或是繼承 Static 自己改寫的 CMystatic 中 , 做成可改變大小的功能

 

 

CMyStatic m_test3;   //繼承 static 自行改寫的 class , CMyStatic , 只有部份程式碼 , 看看邏輯就好 ,

 

void CT400Dlg::OnBnClickedButton1()
{
m_test3.SetWindowText("This is test");
m_test3.SetMyFontSize(180);     // <-------就像這樣用
}

 

// class 部份程式如下

class CMyStatic : public CStatic
{
DECLARE_DYNAMIC(CMyStatic)


public:
CMyStatic();
virtual ~CMyStatic();
afx_msg HBRUSH CtlColor(CDC* pDC, UINT nCtlColor);
void SetMyFontSize(UINT nS);

protected:
DECLARE_MESSAGE_MAP()

UINT  nSize;

};


void CMyStatic::SetMyFontSize(UINT nS)
{
nSize = nS;
RedrawWindow();
}

 


HBRUSH CMyStatic::CtlColor(CDC* pDC, UINT nCtlColor)
{


CFont Font;
CString css;
css.Format("Arial");

Font.CreatePointFont(nSize,css);
pDC->SelectObject(&Font);


return (HBRUSH)m_brushBack.GetSafeHandle();
}

 

 

 

 

 

 

 

 

other :

 

//note : from msdn

//========================================

BOOL CreatePointFont(
   int nPointSize,
   LPCTSTR lpszFaceName,
   CDC* pDC = NULL 
);

 

Parameters

nPointSize

Requested font height in tenths of a point. (For instance, pass 120 to request a 12-point font.)

lpszFaceName

CString or pointer to a null-terminated string that specifies the typeface name of the font. The length of this string must not exceed 30 characters. The Windows EnumFontFamilies function can be used to enumerate all currently available fonts. If lpszFaceName is NULL, the GDI uses a device-independent typeface.

pDC

Pointer to the CDC object to be used to convert the height in nPointSize to logical units. If NULL, a screen device context is used for the conversion.

 

 

Example

// The code fragment shows how to create a font object,
// select the font object into a DC (device context) for text
// drawing, and finally delete the font object.

CClientDC dc(this);

CFont font;
VERIFY(font.CreatePointFont(120, "Arial", &dc));

// Do something with the font just created...
CFont* def_font = dc.SelectObject(&font);
dc.TextOut(5, 5, "Hello", 5);
dc.SelectObject(def_font);

// Done with the font. Delete the font object.
font.DeleteObject();

 

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 echo 的頭像
    echo

    程式筆記本

    echo 發表在 痞客邦 留言(1) 人氣()