Skip to content

Instantly share code, notes, and snippets.

@aosoft
Last active August 27, 2022 17:07
Show Gist options
  • Save aosoft/52995c3727f796d65c29b7985a89593a to your computer and use it in GitHub Desktop.
Save aosoft/52995c3727f796d65c29b7985a89593a to your computer and use it in GitHub Desktop.
AtlWindow.cpp
#define _ATL_NO_AUTOMATIC_NAMESPACE
#include <atlbase.h>
ATL::CAtlWinModule _Module;
#include <atlwin.h>
class Window : public ATL::CWindowImpl<Window>
{
public:
DECLARE_WND_CLASS(_T("AtlWindow"));
BEGIN_MSG_MAP(Window)
MESSAGE_HANDLER(WM_CREATE, OnCreate)
MESSAGE_HANDLER(WM_CLOSE, OnClose)
MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
MESSAGE_HANDLER(WM_MOVE, OnMove)
MESSAGE_HANDLER(WM_SIZE, OnSize)
END_MSG_MAP()
private:
LRESULT OnCreate(UINT msg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
return 0;
}
LRESULT OnClose(UINT msg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
DestroyWindow();
bHandled = true;
return 0;
}
LRESULT OnDestroy(UINT msg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
PostQuitMessage(0);
bHandled = true;
return 0;
}
LRESULT OnMove(UINT msg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
return 0;
}
LRESULT OnSize(UINT msg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
return 0;
}
protected:
virtual void OnFinalMessage(_In_ HWND /*hWnd*/) override
{
delete this;
}
};
int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
_In_opt_ HINSTANCE hPrevInstance,
_In_ LPWSTR lpCmdLine,
_In_ int nCmdShow)
{
auto* w = new Window();
w->Create(nullptr, ATL::CWindow::rcDefault, _T(""), WS_OVERLAPPEDWINDOW);
w->ShowWindow(SW_SHOW);
MSG msg;
while (GetMessage(&msg, NULL, 0, 0) != 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
_Module.Term();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment