추가된 파일 설명
- ChileWin.h : 전처리기 추가,
#include "Windows.h"
추가 - Window class : 윈도우 등록과 생성 메시지처리 담당
조금 설명이 필요한 부분
LRESULT CALLBACK Window::HandleMsgSetup( HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam ) noexcept
{
// use create parameter passed in from CreateWindow() to store window class pointer at WinAPI side
if( msg == WM_NCCREATE )
{
// extract ptr to window class from creation data
const CREATESTRUCTW* const pCreate = reinterpret_cast<CREATESTRUCTW*>(lParam);
Window* const pWnd = static_cast<Window*>(pCreate->lpCreateParams);
// set WinAPI-managed user data to store ptr to window class
// GWLP_USERDATA유저 데이터를 win32내에 저장할수 있는데 핸들값을 저장해둠
SetWindowLongPtr( hWnd,GWLP_USERDATA,reinterpret_cast<LONG_PTR>(pWnd) );
// set message proc to normal (non-setup) handler now that setup is finished
// 메시지 처리를 Window::HandleMsgThunk에 넘기게 된다.
SetWindowLongPtr( hWnd,GWLP_WNDPROC,reinterpret_cast<LONG_PTR>(&Window::HandleMsgThunk) );
// forward message to window class handler
return pWnd->HandleMsg( hWnd,msg,wParam,lParam );
}
// if we get a message before the WM_NCCREATE message, handle with default handler
return DefWindowProc( hWnd,msg,wParam,lParam );
}
// 이제 메시지 처리는 HandleMsgThunk가 한다
LRESULT CALLBACK Window::HandleMsgThunk( HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam ) noexcept
{
// retrieve ptr to window class
Window* const pWnd = reinterpret_cast<Window*>(GetWindowLongPtr( hWnd,GWLP_USERDATA ));
// forward message to window class handler
return pWnd->HandleMsg( hWnd,msg,wParam,lParam );
}
LRESULT Window::HandleMsg( HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam ) noexcept
{
switch( msg )
{
// we don't want the DefProc to handle this message because
// we want our destructor to destroy the window, so return 0 instead of break
case WM_CLOSE:
PostQuitMessage( 0 );
return 0;
}
return DefWindowProc( hWnd,msg,wParam,lParam );
}