• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            浪跡天涯

            唯有努力...
            努力....再努力...

            如何更改屬性頁(yè)向?qū)ы?yè)的字體

            前段時(shí)間,一個(gè)底層開(kāi)發(fā)的同事寫(xiě)一個(gè)MFC工具,在想實(shí)現(xiàn)設(shè)置屬性頁(yè)字體時(shí)遇到了困難,問(wèn)我該如何實(shí)現(xiàn)?根據(jù)多年的經(jīng)驗(yàn),想當(dāng)然的以為很簡(jiǎn)單,只需在資源里,更改對(duì)話(huà)框的字體即可,試了試不行;那就CreateFont,然后SetFont,可是無(wú)論怎么弄,程序運(yùn)行后,屬性頁(yè)的字體依然如故!在網(wǎng)上搜索也沒(méi)有找到好的解決辦法,最后折騰許久,終于找到一篇文章,最終把這個(gè)問(wèn)題解決了。
              
            文章:http://support.microsoft.com/default.aspx?scid=kb;en-us;142170
            示例下載:http://download.microsoft.com/download/vc60pro/samp40/1/win98/en-us/prpfont.exe

            概要

            PRPFONT 說(shuō)明如何為您 CPropertyPages 在資源編輯器, 并在運(yùn)行時(shí)設(shè)置所需字體, 設(shè)置要和一切正常大小相同表的字體。 所有這是一個(gè)類(lèi)稱(chēng)為 CMySheet 中完成。 調(diào)用 ChangeDialogFont() 函數(shù)進(jìn)行調(diào)整窗口以及設(shè)置字體工作。 CPropertySheet::BuildPropPageArray() 被覆蓋以便不重置網(wǎng)頁(yè)中字體。

            更多信息

            在 VisualC++ 的版本低于 4.0, MFC 必須自己實(shí)現(xiàn) CPropertySheet。 對(duì)于您 CPropertySheet 通過(guò)資源編輯器中設(shè)置首 CPropertyPage 您對(duì)話(huà)框資源的字體可能設(shè)置字體。 在運(yùn)行時(shí), 表將使用字體設(shè)置并一切根據(jù)字體大小。 開(kāi)頭 VisualC++4.0, MFC 使用 Windows 95 PropertySheet 控件。 此控件將始終使用系統(tǒng)字體來(lái)表。 這是設(shè)計(jì)使然。 MFC 還將強(qiáng)制頁(yè)以用作表相同字體。 這樣調(diào)用 BuildPropPageArray() 函數(shù)中。 因?yàn)檫@是無(wú)出處函數(shù), 它可能更改或?qū)?lái)的 MFC 版本中被刪除。

            CMySheet 將使用的首活動(dòng) CPropertyPage 字體來(lái)設(shè)置字體和 CPropertySheet 和其子窗口大小。 CPropertyPages 與資源編輯器中指定字體顯示。

            具體步驟:
            1、新建類(lèi)CMySheet,繼承自CPropertySheet
            2、在.cpp文件中大概實(shí)現(xiàn)如下。
            3、修改.h文件。
            4、使用這個(gè)CMySheet,更改資源中的屬性頁(yè),則程序運(yùn)行后,設(shè)置的字體有效。

            #define WM_RESIZEPAGE WM_APP+1

            enum { CDF_CENTER, CDF_TOPLEFT, CDF_NONE };

            // helper function which sets the font for a window and all its children
            // and also resizes everything according to the new font
            void ChangeDialogFont(CWnd* pWnd, CFont* pFont, int nFlag)
            {
             CRect windowRect;

             // grab old and new text metrics
             TEXTMETRIC tmOld, tmNew;
             CDC * pDC = pWnd->GetDC();
             CFont * pSavedFont = pDC->SelectObject(pWnd->GetFont());
             pDC->GetTextMetrics(&tmOld);
             pDC->SelectObject(pFont);
             pDC->GetTextMetrics(&tmNew);
             pDC->SelectObject(pSavedFont);
             pWnd->ReleaseDC(pDC);

             long oldHeight = tmOld.tmHeight+tmOld.tmExternalLeading;
             long newHeight = tmNew.tmHeight+tmNew.tmExternalLeading;

             if (nFlag != CDF_NONE)
             {
              // calculate new dialog window rectangle
              CRect clientRect, newClientRect, newWindowRect;

              pWnd->GetWindowRect(windowRect);
              pWnd->GetClientRect(clientRect);
              long xDiff = windowRect.Width() - clientRect.Width();
              long yDiff = windowRect.Height() - clientRect.Height();
             
              newClientRect.left = newClientRect.top = 0;
              newClientRect.right = clientRect.right * tmNew.tmAveCharWidth / tmOld.tmAveCharWidth;
              newClientRect.bottom = clientRect.bottom * newHeight / oldHeight;

              if (nFlag == CDF_TOPLEFT) // resize with origin at top/left of window
              {
               newWindowRect.left = windowRect.left;
               newWindowRect.top = windowRect.top;
               newWindowRect.right = windowRect.left + newClientRect.right + xDiff;
               newWindowRect.bottom = windowRect.top + newClientRect.bottom + yDiff;
              }
              else if (nFlag == CDF_CENTER) // resize with origin at center of window
              {
               newWindowRect.left = windowRect.left -
                   (newClientRect.right - clientRect.right)/2;
               newWindowRect.top = windowRect.top -
                   (newClientRect.bottom - clientRect.bottom)/2;
               newWindowRect.right = newWindowRect.left + newClientRect.right + xDiff;
               newWindowRect.bottom = newWindowRect.top + newClientRect.bottom + yDiff;
              }
              pWnd->MoveWindow(newWindowRect);
             }

             pWnd->SetFont(pFont);

             // iterate through and move all child windows and change their font.
             CWnd* pChildWnd = pWnd->GetWindow(GW_CHILD);

             while (pChildWnd)
             {
              pChildWnd->SetFont(pFont);
              pChildWnd->GetWindowRect(windowRect);

              CString strClass;
              ::GetClassName(pChildWnd->m_hWnd, strClass.GetBufferSetLength(32), 31);
              strClass.MakeUpper();
              if(strClass==_T("COMBOBOX"))
              {
               CRect rect;
               pChildWnd->SendMessage(CB_GETDROPPEDCONTROLRECT,0,(LPARAM) &rect);
               windowRect.right = rect.right;
               windowRect.bottom = rect.bottom;
              }

              pWnd->ScreenToClient(windowRect);
              windowRect.left = windowRect.left * tmNew.tmAveCharWidth / tmOld.tmAveCharWidth;
              windowRect.right = windowRect.right * tmNew.tmAveCharWidth / tmOld.tmAveCharWidth;
              windowRect.top = windowRect.top * newHeight / oldHeight;
              windowRect.bottom = windowRect.bottom * newHeight / oldHeight;
              pChildWnd->MoveWindow(windowRect);
              
              pChildWnd = pChildWnd->GetWindow(GW_HWNDNEXT);
             }
            }
            /////////////////////////////////////////////////////////////////////////////
            // CMySheet

            IMPLEMENT_DYNAMIC(CMySheet, CPropertySheet)

            CMySheet::CMySheet(UINT nIDCaption, CWnd* pParentWnd, UINT iSelectPage)
             :CPropertySheet(nIDCaption, pParentWnd, iSelectPage)
            {
            }

            CMySheet::CMySheet(LPCTSTR pszCaption, CWnd* pParentWnd, UINT iSelectPage)
             :CPropertySheet(pszCaption, pParentWnd, iSelectPage)
            {
            }

            CMySheet::~CMySheet()
            {
             if (m_fntPage.m_hObject)
              VERIFY (m_fntPage.DeleteObject ());
            }

            BEGIN_MESSAGE_MAP(CMySheet, CPropertySheet)
             //{{AFX_MSG_MAP(CMySheet)
             //}}AFX_MSG_MAP
             ON_MESSAGE (WM_RESIZEPAGE, OnResizePage) 
            END_MESSAGE_MAP()

            /////////////////////////////////////////////////////////////////////////////
            // CMySheet message handlers

            void CMySheet::BuildPropPageArray()
            {
             CPropertySheet::BuildPropPageArray();

             // get first page
             CPropertyPage* pPage = GetPage (0);
             ASSERT (pPage);
             
             // dialog template class in afxpriv.h
             CDialogTemplate dlgtemp;
             // load the dialog template
             VERIFY (dlgtemp.Load (pPage->m_psp.pszTemplate));
             // get the font information
             CString strFace;
             WORD wSize;
             VERIFY (dlgtemp.GetFont (strFace, wSize));
             if (m_fntPage.m_hObject)
              VERIFY (m_fntPage.DeleteObject ());
             // create a font using the info from first page
             VERIFY (m_fntPage.CreatePointFont (wSize*10, strFace));
            }

            BOOL CMySheet::OnInitDialog()
            {
             CPropertySheet::OnInitDialog();

             // get the font for the first active page
             CPropertyPage* pPage = GetActivePage ();
             ASSERT (pPage);

             // change the font for the sheet
             ChangeDialogFont (this, &m_fntPage, CDF_CENTER);
             // change the font for each page
             for (int iCntr = 0; iCntr < GetPageCount (); iCntr++)
             {
              VERIFY (SetActivePage (iCntr));
              CPropertyPage* pPage = GetActivePage ();
              ASSERT (pPage);
              ChangeDialogFont (pPage, &m_fntPage, CDF_CENTER);
             }

             VERIFY (SetActivePage (pPage));

             // set and save the size of the page
             CTabCtrl* pTab = GetTabControl ();
             ASSERT (pTab);

             if (m_psh.dwFlags & PSH_WIZARD)
             {
              pTab->ShowWindow (SW_HIDE);
              GetClientRect (&m_rctPage);

              CWnd* pButton = GetDlgItem (ID_WIZBACK);
              ASSERT (pButton);
              CRect rc;
              pButton->GetWindowRect (&rc);
              ScreenToClient (&rc);
              m_rctPage.bottom = rc.top-2;
             }
             else
             {
              pTab->GetWindowRect (&m_rctPage);
              ScreenToClient (&m_rctPage);
              pTab->AdjustRect (FALSE, &m_rctPage);
             }

             // resize the page 
             pPage->MoveWindow (&m_rctPage);

             return TRUE;
            }

            BOOL CMySheet::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
            {
             NMHDR* pnmh = (LPNMHDR) lParam;

             // the sheet resizes the page whenever it is activated so we need to size it correctly
             if (TCN_SELCHANGE == pnmh->code)
              PostMessage (WM_RESIZEPAGE);
             
             return CPropertySheet::OnNotify(wParam, lParam, pResult);
            }

            LONG CMySheet::OnResizePage (UINT, LONG)
            {
             // resize the page
             CPropertyPage* pPage = GetActivePage ();
             ASSERT (pPage);
             pPage->MoveWindow (&m_rctPage);

             return 0;
            }

            BOOL CMySheet::OnCommand(WPARAM wParam, LPARAM lParam)
            {
             // the sheet resizes the page whenever the Apply button is clicked so we need to size it correctly
             if (ID_APPLY_NOW == wParam ||
              ID_WIZNEXT == wParam ||
              ID_WIZBACK == wParam)
              PostMessage (WM_RESIZEPAGE);
             
             return CPropertySheet::OnCommand(wParam, lParam);
            }

            posted on 2008-01-25 17:42 浪跡天涯 閱讀(5653) 評(píng)論(10)  編輯 收藏 引用 所屬分類(lèi): C++

            評(píng)論

            # re: 如何更改屬性頁(yè)向?qū)ы?yè)的字體 2008-01-30 09:21 追夢(mèng)時(shí)代

            學(xué)習(xí)了,謝謝樓主  回復(fù)  更多評(píng)論   

            # re: 如何更改屬性頁(yè)向?qū)ы?yè)的字體 2008-07-25 00:02 cuckoo321

            寫(xiě)的很不錯(cuò)。請(qǐng)問(wèn)大俠,如何更改屬性頁(yè)的標(biāo)題字體和字號(hào)?  回復(fù)  更多評(píng)論   

            # re: 如何更改屬性頁(yè)向?qū)ы?yè)的字體 2008-07-28 08:56 浪擊天涯

            你可以試試這樣行嗎?

            怎樣改變標(biāo)題欄的寬度:

            方法一:

            NONCLIENTMETRICS ncm;
            ncm.cbSize = sizeof( NONCLIENTMETRICS );

            ::SystemParametersInfo( SPI_GETNONCLIENTMETRICS,
            sizeof( NONCLIENTMETRICS ),
            &ncm,
            0
            );

            ncm.lfCaptionFont.lfHeight = -300;
            ::SystemParametersInfo( SPI_SETNONCLIENTMETRICS,
            sizeof( NONCLIENTMETRICS ),
            &ncm,
            SPIF_SENDCHANGE
            );
             

            方法二:

            case WM_NCCALCSIZE:
            {
            BOOL bSpecial=FALSE;
            int nEdgeWidth =3;
            int nBarHeight =CAPTIONHEIGHT+3;
            int nBottomEdge =3;

            if(!(BOOL)wParam)
            {
            RECT rtSave;
            CopyRect(&rtSave,(LPRECT)lParam);
            // ::CallWindowProcA(lpwndinfo->pWndProc,hWnd,uMsg,wParam,lParam);


            if(lpwndinfo->bIM ==TRUE)
            {
            int imbarheight =17;
            rtSave.left+=nEdgeWidth;
            rtSave.top+=imbarheight+3;
            rtSave.right-=nEdgeWidth;
            rtSave.bottom-=nBottomEdge;
            }
            else
            {
            rtSave.left+=nEdgeWidth;
            rtSave.top+=nBarHeight;
            rtSave.right-=nEdgeWidth;
            rtSave.bottom-=nBottomEdge;
            }
            CopyRect((LPRECT)lParam,&rtSave);

            *lResult=0;
            ::ReleaseDC(hWnd,hDC);
            return TRUE;
            }
            else
            {
            RECT rtSave;
            LPRECT prtClt;
            LPNCCALCSIZE_PARAMS pNC;
            pNC=(LPNCCALCSIZE_PARAMS)lParam;

            prtClt=&(pNC->rgrc[0]);
            CopyRect(&rtSave,prtClt);
            CopyRect( &(pNC->rgrc[2]), &(pNC->rgrc[1]));

            if(bSysDlg)
            {
            (pNC->rgrc[2]).left +=nEdgeWidth;
            (pNC->rgrc[2]).right -=nEdgeWidth;
            }
            else
            {
            if(lpwndinfo->bIM ==TRUE)
            {
            int imbarheight =17;
            (pNC->rgrc[2]).left +=nEdgeWidth;
            (pNC->rgrc[2]).top +=imbarheight+3;
            (pNC->rgrc[2]).right -=nEdgeWidth;
            (pNC->rgrc[2]).bottom -=nBottomEdge;

            rtSave.left+=nEdgeWidth;
            rtSave.top+=imbarheight+3;
            rtSave.right-=nEdgeWidth;
            rtSave.bottom-=nBottomEdge;
            }
            else
            {
            (pNC->rgrc[2]).left+=nEdgeWidth;
            (pNC->rgrc[2]).top+=nBarHeight;
            (pNC->rgrc[2]).right-=nEdgeWidth;
            (pNC->rgrc[2]).bottom-=nBottomEdge;
            // Result=::CallWindowProcA(lpwndinfo->pWndProc,hWnd,uMsg,wParam,lParam);
            //prtClt=&(pNC->rgrc[0]);
            rtSave.left+=nEdgeWidth;
            rtSave.top+=nBarHeight;
            rtSave.right-=nEdgeWidth;
            rtSave.bottom-=nBottomEdge;
            }
            }
            CopyRect(prtClt,&rtSave);
            *lResult=0;
            ::ReleaseDC(hWnd,hDC);
            return TRUE;
            }
            break;
            }   回復(fù)  更多評(píng)論   

            # re: 如何更改屬性頁(yè)向?qū)ы?yè)的字體 2008-08-19 16:41 勤奮的人

            你好 用了你的方法可以實(shí)現(xiàn)更改字體了;
            但是出現(xiàn)了新的問(wèn)題
            就是編輯框沒(méi)辦法輸入中文了;都是亂碼
            請(qǐng)問(wèn)這個(gè)能解決嗎?  回復(fù)  更多評(píng)論   

            # re: 如何更改屬性頁(yè)向?qū)ы?yè)的字體 2008-08-19 16:50 浪跡天涯

            我試了,我這是可以輸入中文,而且顯示也不是亂碼的。  回復(fù)  更多評(píng)論   

            # re: 如何更改屬性頁(yè)向?qū)ы?yè)的字體 2008-08-19 18:19 勤奮的人

            終于找到什么原因了 我做的是PROE二次開(kāi)發(fā) 不知道為什么 創(chuàng)建的非模式對(duì)話(huà)框里 用編輯框或者組合框鍵盤(pán)輸入 中文 總是顯示亂碼 創(chuàng)建的模式對(duì)話(huà)框就不會(huì)!還在摸索中! 不過(guò)仍然很感謝你! 我才知道不是程序問(wèn)題!  回復(fù)  更多評(píng)論   

            # re: 如何更改屬性頁(yè)向?qū)ы?yè)的字體 2008-08-19 18:26 浪跡天涯

            呵,客氣!
            輸入中文亂碼的問(wèn)題,有可能是和字符集設(shè)置有關(guān),具體原因我也沒(méi)碰見(jiàn)過(guò)。  回復(fù)  更多評(píng)論   

            # re: 如何更改屬性頁(yè)向?qū)ы?yè)的字體 2008-09-13 11:24 RSW

            按照上面的方法,無(wú)法修改某些窗口的大小(比如,文本框),有時(shí)還感覺(jué)它變小了,而且對(duì)于靜態(tài)文本框文字輸入很多的話(huà),有部分不能顯示。
            不知道有沒(méi)有解決辦法  回復(fù)  更多評(píng)論   

            # re: 如何更改屬性頁(yè)向?qū)ы?yè)的字體 2008-09-13 12:01 RSW

            我把窗口調(diào)小一點(diǎn),窗口就可以完整顯示了。^_^
            調(diào)大了好像部分被什么東西遮擋了。
              回復(fù)  更多評(píng)論   

            # re: 如何更改屬性頁(yè)向?qū)ы?yè)的字體 2008-09-16 09:18 浪跡天涯

            這可能是你屬性頁(yè)顯示范圍太小,調(diào)大顯示范圍即可!  回復(fù)  更多評(píng)論   

            <2008年9月>
            31123456
            78910111213
            14151617181920
            21222324252627
            2829301234
            567891011

            導(dǎo)航

            統(tǒng)計(jì)

            常用鏈接

            留言簿(22)

            隨筆分類(lèi)(30)

            隨筆檔案(29)

            文章分類(lèi)

            搜索

            積分與排名

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            日韩亚洲国产综合久久久| 久久精品国产男包| 国产成人久久精品麻豆一区| 中文字幕一区二区三区久久网站| 久久亚洲精品视频| 久久99精品久久久久久秒播| 亚洲午夜福利精品久久| 亚洲精品第一综合99久久| 国产亚洲美女精品久久久2020| 欧美牲交A欧牲交aⅴ久久 | 综合久久给合久久狠狠狠97色 | 久久夜色精品国产欧美乱| 久久99精品久久久久久hb无码| 99久久中文字幕| 久久最新免费视频| 国内精品伊人久久久久AV影院| 久久se精品一区二区影院 | 精品久久久无码人妻中文字幕| 国产三级久久久精品麻豆三级| 久久久久久综合一区中文字幕| 青春久久| 久久er热视频在这里精品| 久久久久久免费视频| 久久久久亚洲av无码专区喷水| 久久综合狠狠综合久久激情 | 伊人久久久AV老熟妇色| 99久久成人18免费网站| 亚洲伊人久久精品影院 | 无码国内精品久久人妻| 国产69精品久久久久99尤物| 久久久久亚洲AV无码专区首JN| 国产精品久久99| 97精品依人久久久大香线蕉97| 久久国产精品二国产精品| 久久精品国产亚洲AV嫖农村妇女 | 久久综合欧美成人| 亚洲国产精品无码成人片久久| 久久人人爽人人爽AV片| 国产精品久久精品| 人妻精品久久无码专区精东影业| 欧美亚洲日本久久精品|