재정의 타입 예시)
1. 윈도우 프로그램의 기본 구조
WinMain() {
윈도우 클래스 만들기
윈도우 객체 생성
윈도우 객체 화면에 띄우기
메세지 루프 돌리기
}
WndProc() {
전달된 메세지 처리하기
}
윈도우 객체 화면 띄우기
BOOL ShowWindow(
HWND hWnd
int nCmdShow
);
예시 코드
#include<Windows.h>
#include<tchar.h>
LRESULT CALLBACK WndProc(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam) {
return 0;
}
int APIENTRY WinMain(
HINSTANCE hInstance,
HINSTANCE hPreInstance,
LPSTR lpCmdLine,
int nCmdShow
) {
//MessageBox(NULL, L"Hellow World", L"메세지", MB_OK);
HWND hWnd;
MSG Message;
WNDCLASS WndClass;
WndClass.cbClsExtra = 0;
WndClass.cbWndExtra = 0;
WndClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WndClass.hInstance = hInstance;
WndClass.lpfnWndProc = (WNDPROC)WndProc;
WndClass.lpszClassName = L"MyClass";
WndClass.lpszMenuName = NULL;
WndClass.style = CS_HREDRAW | CS_VREDRAW;
RegisterClass(&WndClass);
// 객체 생성
hWnd = CreateWindow(L"MyClass", L"Win32", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, (HMENU)NULL, hInstance, NULL);
// 윈도우 표시
ShowWindow(hWnd, nCmdShow);
return 0;
}
2. 메세지 루프 돌리기
윈도우 항시 루프를 돌며 사용자의 메세지를 기다림
메세지가 들어오면 받아서 처리하는데, 이러한 방식을 이벤트 처리 방식이라고 한다.
발생된 이벤트를 메세지 루프에서 감지
윈도우 프로시저 함수로 메세지를 보내는 역할
