MFC application With CFrameWnd
It is also possible to write a program without CFrameWnd class.
How is it possible ?
Simple logic behind the scene is
we have to call the AfxRegisterWndClass() fn before calling CreateEx() in CWnd Derived class's
Constructor...
we may replace CFrameWnd as CWnd...
Look at the following program :
#include "afxwin.h"
class CMyApp:public CWinApp
{
public:
virtual BOOL InitInstance();
virtual BOOL ExitInstance();
};
class CMyWnd: public CWnd
{
public:
CMyWnd();
~CMyWnd() { }
protected:
afx_msg void OnPaint();
DECLARE_MESSAGE_MAP()
};CMyApp app;
BOOL CMyApp::InitInstance()
{
m_pMainWnd = new CMyWnd();
m_pMainWnd->ShowWindow(1);
m_pMainWnd->UpdateWindow();
return TRUE;
}
BOOL CMyApp::ExitInstance()
{
return true;
}
BEGIN_MESSAGE_MAP(CMyWnd,CWnd)
ON_WM_PAINT()
END_MESSAGE_MAP()
CMyWnd::CMyWnd()
{
// Register a WNDCLASS
CString strWndClass = AfxRegisterWndClass ( CS_DBLCLKS, NULL, (HBRUSH)::GetStockObject(WHITE_BRUSH) );
//Create a Window
CreateEx (0, strWndClass, _T ("My App"), WS_OVERLAPPEDWINDOW, 0,0,500,500, NULL, NULL);
}
void CMyWnd::OnPaint()
{
CPaintDC dc(this);
CRect rect;
GetClientRect(&rect);
dc.DrawText("sundar",&rect,DT_SINGLELINE);
}
How is it possible ?
Simple logic behind the scene is
we have to call the AfxRegisterWndClass() fn before calling CreateEx() in CWnd Derived class's
Constructor...
we may replace CFrameWnd as CWnd...
Look at the following program :
#include "afxwin.h"
class CMyApp:public CWinApp
{
public:
virtual BOOL InitInstance();
virtual BOOL ExitInstance();
};
class CMyWnd: public CWnd
{
public:
CMyWnd();
~CMyWnd() { }
protected:
afx_msg void OnPaint();
DECLARE_MESSAGE_MAP()
};CMyApp app;
BOOL CMyApp::InitInstance()
{
m_pMainWnd = new CMyWnd();
m_pMainWnd->ShowWindow(1);
m_pMainWnd->UpdateWindow();
return TRUE;
}
BOOL CMyApp::ExitInstance()
{
return true;
}
BEGIN_MESSAGE_MAP(CMyWnd,CWnd)
ON_WM_PAINT()
END_MESSAGE_MAP()
CMyWnd::CMyWnd()
{
// Register a WNDCLASS
CString strWndClass = AfxRegisterWndClass ( CS_DBLCLKS, NULL, (HBRUSH)::GetStockObject(WHITE_BRUSH) );
//Create a Window
CreateEx (0, strWndClass, _T ("My App"), WS_OVERLAPPEDWINDOW, 0,0,500,500, NULL, NULL);
}
void CMyWnd::OnPaint()
{
CPaintDC dc(this);
CRect rect;
GetClientRect(&rect);
dc.DrawText("sundar",&rect,DT_SINGLELINE);
}
Labels: MFC
0 Comments:
Post a Comment
<< Home