Example of CWnd window frame in C++

  • 2020-04-02 02:52:03
  • OfStack

The example of this article about the CWnd window frame, to share with you for your reference. Specific analysis is as follows:

. H header file code is as follows:

#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 source file code is as follows:

#include "ReadBMP.h"  
#include "resource.h" 
 
CMyApp theApp; 
BOOL CMyApp::InitInstance() 

    m_pMainWnd = new CMainWindow; 
    m_pMainWnd->ShowWindow(m_nCmdShow); 
    return TRUE; //You must return TRUE, or you will not enter the message loop and the interface will simply exit & NBSP; < br / > } 
 
//CMainWindow 
BEGIN_MESSAGE_MAP(CMainWindow, CWnd) 
ON_WM_CREATE() 
END_MESSAGE_MAP() 
//Constructor & NBSP; < br / > 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); 

//Destructor & NBSP; < br / > CMainWindow::~CMainWindow() 

 

//Message mapping function & NBSP; < br / > int CMainWindow::OnCreate(LPCREATESTRUCT lpCreateStruct) 

    //OutputDebugString("oncreate"); 
    //Setup menu & menu; < br / >     HMENU hMenu = ::LoadMenuA(theApp.m_hInstance, (LPCSTR)IDR_MENU); 
    ::SetMenu(m_hWnd, hMenu); 
    return 0; 

 
void CMainWindow::OnNcDestroy( ) 

    delete this; 

void CMainWindow::OnDestroy() 

     
}

Hope that the article described in the C++ programming to help you.


Related articles: