代码语言:javascript复制
#include <afxwin.h>
#include "resource.h"//引用是必须的,不然菜单不会出现
class MyFrameWindow:public CFrameWnd
{
public:
afx_msg void OnPaint()
{
CPaintDC paintDC(this);
paintDC.TextOut(0,0,"这是我的第一个窗口程序");
}
afx_msg void OnFileExit()
{
PostMessage(WM_CLOSE);
}
BOOL PreCreateWindow(CREATESTRUCT& cs)
{
cs.hMenu = LoadMenu(NULL,MAKEINTRESOURCE(IDR_MAINMENU));
return CFrameWnd::PreCreateWindow(cs);
}
DECLARE_MESSAGE_MAP()
};
BEGIN_MESSAGE_MAP(MyFrameWindow,CFrameWnd)
ON_WM_PAINT()
ON_COMMAND(ID_40003,OnFileExit)
END_MESSAGE_MAP()
class HellowApp:public CWinApp
{
public:
HellowApp()
:CWinApp("HelloWorld")
{}
BOOL InitInstance()
{
HICON hIcon;
hIcon = LoadIcon(IDIGNORE);
CFrameWnd *MyFrame = new MyFrameWindow;
m_pMainWnd = MyFrame;
MyFrame->Create(NULL,(LPCSTR)"Hellow");
MyFrame->SetIcon(hIcon,FALSE);//设置窗口的小图标
MyFrame->SetIcon(hIcon,TRUE);//设置窗口的大图标
MyFrame->ShowWindow(SW_SHOW);
return TRUE;
}
}HellowWorld;
程序运行如图: