九阴真经字体变大物品的字体颜色是如何划分的?

如何改变控件的字体和字体颜色
我的图书馆
如何改变控件的字体和字体颜色
CWnd::SetFontCFont
CWnd::SetFont
This method sets the current font of the window to the specified font.
void SetFont(
CFont* pFont,
BOOL bRedraw = TRUE );
Parameters
Specifies the new font.
If TRUE, redraw the CWnd object.
Requirements
&&Windows CE versions: 1.0 and later&&Header file: Declared in Afxwin.h&&Platform: H/PC Pro, Palm-size PC, Pocket PC
与此函数对应的还有CFont::GetFont
CWnd::GetFont
This method retrieves the current font for this window.
CFont* GetFont( )
Return Value
Returns a pointer to a CFont that contains the current font.
The pointer may be temporary and should not be stored for later use.
Requirements
&&Windows CE versions: 1.0 and later&&Header file: Declared in Afxwin.h&&Platform: H/PC Pro, Palm-size PC, Pocket PC
Protected:
&&&& CFont m_fntOk;//ok
&&&& CFont m_fntC//cancel字体
BOOL CCtrlFontDlg::OnInitDialog()
CDialog::OnInitDialog();
m_fntOk.CreateFont(MulDiv(8,GetDC()-&GetDeviceCaps(LOGPIXELSY),72),0,0,0,FW_NORMAL,0,0,0,ANSI_CHARSET,OUT_STROKE_PRECIS,CLIP_STROKE_PRECIS,DRAFT_QUALITY,VARIABLE_PITCH|FF_SWISS,_T(“Arial”));
CWnd *pWnd=GetDlgItem(IDOK);
pWnd-.SetFont(&m_fntOk);
m_fntCancel.CreateFont(12,10,10,10,FW_NORMAL,FALSE,FALSE,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH|SWISS,””);
pWnd=GetDlgItem(IDCANCEL);
pWnd-&SetFont(&m_fntCancel);
//IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX&0xFFF0)==IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX&0xF000);
CMenu* pSysMenu=GetSystemMenu(FALSE);
If(pSysMenu!=NULL)
CString strAboutM
strAboutMenu.LoadString(IDS_ABOUTBOX);
if(!strAboutMenu.IsEmpty())
pSysMenu-&AppendMenu(MF_AEPARATOR);
pSysMenu-&AppendMenu(MF_STRING,IDM_ABOUTBOX,strAboutMenu);
//Set the icon for this dialog. The framework does this automatically
//when the application’s main window is not a dialog
SetIcon(m_hIcon,TRUE);
SetIcon(m_hIcon,FALSE);
Return TRUE;
MFCCWnd::OnCtlColorWM_CTLCOLOR
CWnd::OnCtlColor
This method is called by the framework when a child control is about to be drawn. Most controls send this message to their parent, usually a dialog box, to prepare the pDC for drawing the control using the correct colors.
afx_msg HBRUSH OnCtlColor(
CWnd* pWnd,
UINT nCtlColor );
Parameters
Contains a pointer to the display context for the child window. May be temporary.
Contains a pointer to the control asking for the color. May be temporary.
Contains one of the following values, specifying the type of control: (指定控件的类型)
·CTLCOLOR_BTN&&&Button control (按钮控件)
·CTLCOLOR_DLG&&&Dialog box (对话框)
·CTLCOLOR_EDIT&&&Edit control (编辑控件)
·CTLCOLOR_LISTBOX&&&List-box control (列表控件)
·CTLCOLOR_MSGBOX&&&Message box (消息框)
·CTLCOLOR_SCROLLBAR&&&Scroll-bar control (滚动条控件)
·CTLCOLOR_STATIC&&&Static control (静态控件)
Return Value
OnCtlColor must return a handle to the brush that is to be used for painting the control background.
To change the text color, call the SetTextColor method with the desired red, green, and blue (RGB) values.
To change the background color of a single-line edit control, set the brush handle in both the CTLCOLOR_EDIT and CTLCOLOR_MSGBOX message codes, and call the CDC::SetBkColor method in response to the CTLCOLOR_EDIT code.
OnCtlColor will not be called for the list box of a drop-down combo box because the drop-down list box is actually a child of the combo box and not a child of the window. To change the color of the drop-down list box, create a CComboBox with an override of OnCtlColor that checks for CTLCOLOR_LISTBOX in the nCtlColor parameter. In this handler, the SetBkColor method must be used to set the background color for the text.
This method is called by the framework to allow your application to handle a Windows CE message. The parameters passed to your method reflect the parameters received by the framework when the message was received. If you call the base-class implementation of this method, that implementation will use the parameters originally passed with the message and not the parameters you supply to the method.
// This OnCtlColor handler will change the color of a static control
// with the ID of IDC_MYSTATIC. The code assumes that the CMyDialog
// class has an initialized and created CBrush member named m_brush.
// The control will be painted with red text and a background
// color of m_brush.
HBRUSH CZilchDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
&&// Call the base class implementation first! Otherwise, it may
&&// undo what we are trying to accomplish here.
&&HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
&&// Are we painting the IDC_MYSTATIC control? We can use
&&// CWnd::GetDlgCtrlID() to perform the most efficient test.
&&if (pWnd-&GetDlgCtrlID() == IDC_MYSTATIC)
&&&&// Set the text color to red.
&&&&pDC-&SetTextColor(RGB(255, 0, 0));
&&&&// Set the background mode for text to transparent
&&&&// so background will show thru.
&&&&pDC-&SetBkMode(TRANSPARENT);
&&&&// Return handle to our CBrush object.
&&&&hbr = m_
MySTATICIDC_STATIC1
HBRUSH CMyDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
&&&&&& HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
&&&&&& // TODO: Change any attributes of the DC here
&&&&&& if(nCtlColor==CTLCOLOR_STATIC)
&&&&&&&&&&&&& pDC-&SetTextColor(RGB(255,0,0));//
&&&&&&&&&&&&& pDC-&SetBkColor(RGB(0,0,255));//
&&&&&& // TODO: Return a different brush if the default is not desired
IDIDC_STATIC1
if(pWnd-&GetDlgCtlID()==IDC_STATIC1)
pDC-&SetTextColor(RGB(255,0,0));//
pDC-&SetBkMode(TRANSPARENT);//
return (HBRUSH)::GetStockObject(BLACK_BRUSH);//
TA的最新馆藏[转]&[转]&[转]&[转]&
喜欢该文的人也喜欢

参考资料

 

随机推荐