在MFC中使用自訂視窗類別

來源:互聯網
上載者:User
1、在 CYourApp::InitInstance中註冊視窗類別
WNDCLASS wc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wc.hCursor = LoadCursor(IDC_ARROW);
wc.hIcon = NULL;
wc.hInstance = AfxGetInstanceHandle();
wc.lpfnWndProc = ::DefWindowProc; // 注意指定視窗過程
wc.lpszClassName = _T("MyWnd_class"); // 指定視窗類別
wc.lpszMenuName = NULL;
wc.style = 0;
AfxRegisterClass(&wc);

2、編寫.h檔案類的定義
#ifndef MY_WND
#define MY_WND

class CMyWnd : public CWnd
{
public:
    // 建構函式、解構函式等公有介面的聲明
protected:
    // 各訊息處理函數的聲明
    DECLARE_MESSAGE_MAP()
};

#endif

3、編寫.cpp檔案類的實現
#include "stdafx.h"
#include "MyWnd.h"

// 建構函式、解構函式等函數的實現

BEGIN_MESSAGE_MAP(CMyWnd, CWnd)
    // 各訊息分流器
END_MESSAGE_MAP()

// 各訊息分流器的實現

4、在主程式碼的適當地方調用 Create或 CreateEx建立視窗。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.