入口函数
#include"window.h"
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
window wnd;
CRect rt(0, 0, 512, 512);
wnd.Create(NULL, rt, _T("window"), WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX);
wnd.CenterWindow();
wnd.SetTimer(1, 100);
// 显示并更新窗口
wnd.ShowWindow(nCmdShow);
wnd.UpdateWindow();
MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}
window类
#include"common.h"
#define USER_PAINT (WM_USER+1)
class window :public CWindowImpl<window>
{
public:
window();
~window();
BEGIN_MSG_MAP(window)
MESSAGE_HANDLER(WM_TIMER, OnTimer)
MESSAGE_HANDLER(USER_PAINT, OnPaint)
MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
END_MSG_MAP()
LRESULT OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
LRESULT OnPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
LRESULT OnTimer(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
};
common.h文件
#include <atlstr.h>
#include <atltypes.h>
#include <atlimage.h>
#include <atlbase.h>
#include <atlwin.h>