ATL은 Win32api에 C++의 템플릿 인터페이스와 람다를 장착한 wrapper 라이브러리이다.
//main.cpp
#include "Precompiled.h"
typedef LRESULT(*message_callback) (HWND, WPARAM, LPARAM);
struct message_handler
{
UINT message;
message_callback handler;
};
static message_handler s_handler[] =
{
{
WM_PAINT, [](HWND window, WPARAM, LPARAM) -> LRESULT
{
PAINTSTRUCT ps;
BeginPaint(window, &ps);
OutputDebugString(L"PAINT");
EndPaint(window, &ps);
return 0;
}
},
{
WM_DESTROY, [](HWND indow, WPARAM, LPARAM) -> LRESULT
{
PostQuitMessage(0);
return 0;
}
}
};
int __stdcall _tWinMain(HINSTANCE module, HINSTANCE, PWSTR, int) {
WNDCLASS wc = {};
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.hCursor = LoadCursor(nullptr, IDC_ARROW);
wc.hInstance = module;
wc.lpszClassName = L"Window";
wc.lpfnWndProc =
[](HWND window, UINT message, WPARAM wparam, LPARAM lparam)->LRESULT
{
for (auto h = s_handler; h != s_handler + _countof(s_handler); ++h)
{
if (message == h->message)
{
return h->handler(window, wparam, lparam);
}
}
return DefWindowProc(window, message, wparam, lparam);
};
RegisterClass(&wc);
auto hwnd =
CreateWindow(wc.lpszClassName, L"Title", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
nullptr, nullptr, module, nullptr);
MSG message;
BOOL result;
while (result = GetMessage(&message, 0, 0, 0))
{
if (-1 != result)
{
DispatchMessage(&message);
}
}
}
//Precompiled.h
#pragma once
#define NOMINMAX
#include <atlbase.h>
#include <atlwin.h>
#pragma warning(disable: 4706)
'삽질' 카테고리의 다른 글
Vector Identity (0) | 2022.07.21 |
---|---|
좌표계 (0) | 2022.07.15 |
분산 문제 (0) | 2022.07.12 |
[C++/WinRT] Core 데스크탑 앱 "Hello World" example (0) | 2021.01.06 |
ATL + Direct2D (0) | 2020.11.12 |