C++之CWnd窗口框架實例。本站提示廣大學習愛好者:(C++之CWnd窗口框架實例)文章只能為提供參考,不一定能成為您想要的結果。以下是C++之CWnd窗口框架實例正文
本文實例講述了CWnd窗口框架,分享給年夜家供年夜家參考。詳細剖析以下:
.h頭文件代碼以下:
#include <afxwin.h>
class CMyApp:public CWinApp
{
public:
virtual BOOL InitInstance();
};
//CMainWindow
class CMainWindow:public CWnd
{
public:
CMainWindow();
~CMainWindow();
protected:
afx_msg void OnNcDestroy( );
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnDestroy( );
DECLARE_MESSAGE_MAP()
};
.cpp源文件代碼以下:
#include "ReadBMP.h"
#include "resource.h"
CMyApp theApp;
BOOL CMyApp::InitInstance()
{
m_pMainWnd = new CMainWindow;
m_pMainWnd->ShowWindow(m_nCmdShow);
return TRUE; //必需前往TRUE,不然不會進入新聞輪回,界面會直接加入
}
//CMainWindow
BEGIN_MESSAGE_MAP(CMainWindow, CWnd)
ON_WM_CREATE()
END_MESSAGE_MAP()
//結構函數
CMainWindow::CMainWindow()
{
LPCTSTR lpszClassName = ::AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW, ::LoadCursorA(NULL, IDC_ARROW), (HBRUSH)(COLOR_3DFACE+1), theApp.LoadIcon(IDI_MAIN));
CreateEx(WS_EX_CLIENTEDGE, lpszClassName, "xxx", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL);
}
//析構函數
CMainWindow::~CMainWindow()
{
}
//新聞映照函數
int CMainWindow::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
//OutputDebugString("oncreate");
//設置菜單
HMENU hMenu = ::LoadMenuA(theApp.m_hInstance, (LPCSTR)IDR_MENU);
::SetMenu(m_hWnd, hMenu);
return 0;
}
void CMainWindow::OnNcDestroy( )
{
delete this;
}
void CMainWindow::OnDestroy()
{
}
願望本文所述對年夜家的C++法式設計有所贊助。