MFC幾個常用函數:OnCreate和OnInitialUpDate,GetActiveFrame和MDIGetActive,Invalidate、SetModifiedFlage、UpdateAll

來源:互聯網
上載者:User

把用常用的都整理一下,不然好亂。

一、OnCreate和OnInitialUpDate

參考:http://www.cnblogs.com/mingfei200169/articles/666567.html

ONCREATE只是產生VIEW的基本結構和變數而在OnInitialUpDate()中,主要初始化視圖中控制項等,對各個變數進行初始化操作。

例子。我們要在視圖中添加一個button和combobox控制項則

OnCreate函數中寫法如下:int CFormView::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CView::OnCreate(lpCreateStruct) == -1)  return -1;  // TODO: Add your specialized creation code here CRect rect(20,20,100,50); m_ctrlButton.Create("Button1",WS_CHILD|WS_VISIBLE,rect,this,NULL); //建立按扭控制項 CFont *pFont=CFont::FromHandle((HFONT)::GetStockObject(ANSI_VAR_FONT)); CRect rect1(150,20,350,100); m_combobox.Create(WS_CHILD|WS_VISIBLE|CBS_SIMPLE|CBS_NOINTEGRALHEIGHT|WS_VSCROLL,rect1,this,NULL); return 0;}OnInitialUpDate中寫法void CFormView::OnInitialUpdate() { CView::OnInitialUpdate();  // TODO: Add your specialized code here and/or call the base class //初始化下拉式方塊控制項 m_combobox.AddString("Mondy"); m_combobox.AddString("Tuesday"); m_combobox.AddString("Wednesday"); m_combobox.AddString("Thursday"); m_combobox.AddString("Saturday"); m_combobox.AddString("Sunday");}

這裡一點非常重要:OnCreate()是產生結構的,而OnInitialUpDate是對結構進行初始化。兩個一個相當於硬體一個相當於軟體,功能和作用完全不同。但是是相互密切聯絡。

二、GetActiveFrame和MDIGetActive

參考:http://blog.csdn.net/zhuxiufenghust/article/details/7039879

The CMDIFrameWnd class provides the functionality of a Windows multiple document interface (MDI) frame window, along with members for managing the window. 

CMDIFrameWnd功能的類提供了一個Windows多重文件介面(MDI)架構視窗,連同會員管理視窗。

The CMDIChildWnd class provides the functionality of a Windows multiple document interface (MDI) child window, along with members for managing the window.

CMDIChildWnd功能的類提供了一個Windows多重文件介面(MDI)子視窗,連同會員管理視窗。
注意了:一個是提供多重文件介面的架構視窗,一個是多重文件介面的子視窗。

三、Invalidate、SetModifiedFlag、UpdateAllViews

參考:http://zhidao.baidu.com/question/50593960.html

1:Invalidate

該函數的作用是使整個視窗客戶區無效,如果無效視窗要進行顯示或者處理(即變成當前視窗),那麼視窗的客戶區無效意味著需要重繪。因此,這個機制和人是一樣的,只處理需要的,有用的。

2:SetModifieldFlag

設定髒點,表明內容是否已經被修改(汙染),常常在判斷是否儲存的時候有用。

3:UpdateAllViews

當更新了Doc類的內容,一般都用這個把更新的內容可視化。


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.