欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

歡迎來到入門教程網(wǎng)!

C語言

當前位置:主頁 > 軟件編程 > C語言 >

VC++中的字體設置方法詳解

來源:本站原創(chuàng)|時間:2020-01-10|欄目:C語言|點擊: 次

VC++中static text字體改變
窗口都有2個和字體有關的函數(shù):
CWnd::GetFont()和SetFont(CFont*, BOOL);
1)CFont* pFont = m_static.GetFont();

2)LOGFONT LogFont;
pFont->GetLogFont(&LogFont);

3)對LogFont直接操縱修改里面的字體選項
 
//如LogFont.lfUnderline = 1;設置下劃線
 LogFont.lfHeight=30;       //字體大小設置
 strcpy(LogFont.lfFaceName, "楷體_GB2312");  //字體設置

4)pFont->Detach();
第四步的目的是將pFont里裝有的HFONT解除關聯(lián),否則pFont無法調(diào)用緊接的Create函數(shù)。

5)pFont->CreateFontIndirect(&LogFont);
m_static.SetFont(pFont);

6)pFont->Detach();
必須再一次解除在pFont里裝載的HFONT,原因是第5步已經(jīng)將HFONT賦給了m_static。pFont的任務已完成,不應該持有HFONT資源,它也不能去銷毀HFONT,因為m_static在使用這個HFONT,所以必須是Detach()來解除關聯(lián)。

VC++中字體顏色的改變
在OnCtlColor函數(shù)中如下代碼:

復制代碼 代碼如下:

 HBRUSH CDlg_SignIn::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
 HBRUSH hbr = CDialogEx::OnCtlColor(pDC, pWnd, nCtlColor);
 // TODO:  Change any attributes of the DC here
   if(nCtlColor == CTLCOLOR_STATIC)
       {
       if(pWnd->GetDlgCtrlID()== IDC_REGARD)
           {
               pDC->SetTextColor(RGB(255,0,0));
               pDC->SetBkColor(RGB(251, 247, 200));//設置文本背景色
               pDC->SetBkMode(TRANSPARENT);//設置背景透明                  
           }
       }
 // TODO:  Return a different brush if the default is not desired
 return hbr;


其他控件的宏定義為:
CTLCOLOR_BTN 按鈕控件
CTLCOLOR_DLG 對話框
CTLCOLOR_EDIT 編輯框
CTLCOLOR_LISTBOX 列表控件
CTLCOLOR_MSGBOX 消息控件
CTLCOLOR_SCROLLBAR 滾動條控件
CTLCOLOR_STATIC 靜態(tài)控件

VC中動態(tài)改變控件和對話框字體.
1
VC的對話框字體設置對所有控件都有效,你不能單獨地改變某個靜態(tài)文本的字體。對于你的問題,需要首先用CreateFont來建立一個字體對象,然后調(diào)用控件的SetFont,就可以了。

例子:
1、改靜態(tài)文體的ID,如:IDC_STATIC1
2、添加一個Edit控件,建立一個關聯(lián)的控件m_editControl。
3、在OnInitDialog中添加如下代碼:
復制代碼 代碼如下:

CFont * f;
     f = new CFont;
     f->CreateFont(16, // nHeight
     0, // nWidth
     0, // nEscapement
     0, // nOrientation
     FW_BOLD, // nWeight
     TRUE, // bItalic
     FALSE, // bUnderline
     0, // cStrikeOut
     ANSI_CHARSET, // nCharSet
     OUT_DEFAULT_PRECIS, // nOutPrecision
     CLIP_DEFAULT_PRECIS, // nClipPrecision
     DEFAULT_QUALITY, // nQuality
     DEFAULT_PITCH | FF_SWISS, // nPitchAndFamily
     _T("Arial")); // lpszFac   
     GetDlgItem(IDC_STATIC1)->SetFont(f);
     CWnd *cWnd = GetDlgItem(IDC_STATIC1);
     cWnd->SetFont(&font);
     cWnd->SetWindowTextW(L"設置需要的內(nèi)容");

需要注意的是,這里我們使用的是CFont指針,而不是普通的CFont局部變量, 在非MFC程序,首先用CreateFont來建立一個字體句柄,然后再用SendMessage發(fā)給控件WM_SETFONT消息,將建立的字體句柄賦值過去,就可以了。 

2 但是整個對話框或窗口的字體的大小,使用對話框或窗口的SetFont()函數(shù)卻沒有任何的作用.可以在初始化時遍歷每個控件分別設置來處理,但這里說另一種使用回調(diào)函數(shù)的簡單方法:
:調(diào)用系統(tǒng)的API:::EnumChildWindows(). ,傳入回調(diào)函數(shù)和重新定義的字體.(第一個參數(shù)不用管啊,本來就有啊)

1)在文檔視圖結構中CMainFrame::OnCreate().中調(diào)用::EnumChildWindows(). 實現(xiàn)所有窗口和子窗口字體改變

2) 在對話框的OnInitDialog(). 中調(diào)用::EnumChildWindows(). 改變對話窗上的所有控件.
回調(diào)函數(shù)如下:

復制代碼 代碼如下:

/ lParam is a pointer to CFont object
BOOL __stdcall SetChildFont(HWND hwnd, LPARAM lparam)
{
CFont *pFont = (CFont*)lparam;
CWnd *pWnd = CWnd::FromHandle(hwnd);
pWnd->SetFont(pFont);
return TRUE;
}

使用1:
復制代碼 代碼如下:

BOOL CAboutDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
::EnumChildWindows(m_hWnd, ::SetChildFont, (LPARAM)g_Font.GetFont());
return TRUE;  // return TRUE unless you set the focus to a control
  // EXCEPTION: OCX Property Pages should return FALSE
}

使用2:
復制代碼 代碼如下:

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
 if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
 if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
{
TRACE0("Failed to create toolbar\n");
 return -1;      // fail to create
}
if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
{
 TRACE0("Failed to create status bar\n");
return -1;      // fail to create
 }
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);
::EnumChildWindows(m_hWnd, ::SetChildFont, (LPARAM)g_Font.GetFont());
return 0;
}
(很好用,不像mfc中的那個垃圾setfont(),設置了對話框的沒有一點反應!)

3 如何在mfc中實現(xiàn),當系統(tǒng)的字體變大的時候,對話框上面的字體也相應的變大?
復制代碼 代碼如下:

//IconFont
    LOGFONT logFont;
    int  size = sizeof(LOGFONT);
    bool isGood = SystemParametersInfo(SPI_GETICONTITLELOGFONT,size,&logFont,0);
    if(isGood == true)
{
 CFont * f;
f = new CFont;
const LOGFONT* pFont = new LOGFONT(logFont);
f->CreateFontIndirectW(pFont);
 //::EnumChildWindows(m_hWnd, ::SetChildFont, (LPARAM)f);
}
//other Font
NONCLIENTMETRICS ncm = new NONCLIENTMETRICS();               
bool isGood = SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), ref ncm, 0);
if (isGood == true)
{
LOGFONT logFont2;
//logFont2=ncm.lfntCaptionFont);//CaptionFont
 //logFont2 =ncm.lfntSMCaptionFont;//CaptionFont_Small
//logFont2 = ncm.lfntMenuFont;//MenuFont
//logFont2 = ncm.lfntStatusFont;//StatusFont
 logFont2 = ncm.lfntMessageFont;//MessageFont
CFont * f;
 f = new CFont;
const LOGFONT* pFont = new LOGFONT(logFont2);
 f->CreateFontIndirectW(pFont);
 //::EnumChildWindows(m_hWnd, ::SetChildFont, (LPARAM)f);
 }

以上是取得系統(tǒng)字體的大小,然后再調(diào)用上面的第二種方法。
窗體上的所有字體都會跟著系統(tǒng)字體的大小改變。

上一篇:C語言中auto,register,static,const,volatile的區(qū)別詳細解析

欄    目:C語言

下一篇:簡單說說STL的內(nèi)存管理

本文標題:VC++中的字體設置方法詳解

本文地址:http://mengdiqiu.com.cn/a1/Cyuyan/4138.html

網(wǎng)頁制作CMS教程網(wǎng)絡編程軟件編程腳本語言數(shù)據(jù)庫服務器

如果侵犯了您的權利,請與我們聯(lián)系,我們將在24小時內(nèi)進行處理、任何非本站因素導致的法律后果,本站均不負任何責任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權所有