使用WTL写Windows程序简单示例

#include  < atlbase.h >
CComModule _Module;
#include 
< atlwin.h >

class  CMainFrame: public  CWindowImpl < CMainFrame, CWindow, CFrameWinTraits >
{
public:
    BEGIN_MSG_MAP(CMainFrame)
        MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
        MESSAGE_HANDLER(WM_PAINT, OnPaint)
    END_MSG_MAP()

    LRESULT OnPaint(UINT, WPARAM, LPARAM, BOOL
&)
    
{
        PAINTSTRUCT ps;
        RECT rt;
        TCHAR szText[] 
= _T("Hello World!");
        HDC hDC 
= BeginPaint(&ps);
        GetClientRect(
&rt);
        DrawText(hDC, szText, 
-1&rt, DT_CENTER|DT_VCENTER|DT_SINGLELINE);
        EndPaint(
&ps);
        
return 0;
    }

    LRESULT OnDestroy(UINT, WPARAM, LPARAM, BOOL
&)
    
{
        PostQuitMessage(
0);
        
return 0;
    }

}
;

int  WINAPI _tWinMain(HINSTANCE hInst,HINSTANCE hPreInst,LPTSTR, int )
{
    _Module.Init(NULL, hInst);
    CMainFrame main;
    main.Create(NULL, CWindow::rcDefault);
    main.ShowWindow(SW_SHOW);

    MSG msg;
    
while(GetMessage(&msg,0,0,0))
    
{
        TranslateMessage(
&msg);
        DispatchMessage(
&msg);
    }

    _Module.Term();
    
return msg.wParam;
}

你可能感兴趣的:(windows,null)