#include<Windows.h>
HINSTANCE g_hInst;
LPCTSTR MyClassName = TEXT("FistClass");
HWND hWndMain,hC1,hC2,hC3;
HBRUSH hRedBrush, hBlueBrush, hGreenBrush;
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK ChildLeftProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK ChildTopProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK ChildBottomProc(HWND, UINT, WPARAM, LPARAM);
int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpCmdLine, _In_ int nCmdShow) {
WNDCLASS wndclass{};
HWND hWnd{};
MSG msg{};
g_hInst = hInstance;
hRedBrush = (HBRUSH)CreateSolidBrush(RGB(255,0,0));
hGreenBrush = (HBRUSH)CreateSolidBrush(RGB(0,255,0));
hBlueBrush = (HBRUSH)CreateSolidBrush(RGB(0,0,255));
wndclass.lpfnWndProc = WndProc;
wndclass.lpszClassName = MyClassName;
wndclass.hInstance = hInstance;
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wndclass.cbWndExtra = 0;
wndclass.cbClsExtra = 0;
wndclass.lpszMenuName = NULL;
wndclass.hbrBackground = NULL;
wndclass.style = CS_HREDRAW | CS_VREDRAW;
RegisterClass(&wndclass);
wndclass.hbrBackground = hRedBrush;
wndclass.lpfnWndProc = ChildLeftProc;
wndclass.lpszClassName = TEXT("ChildLeft");
RegisterClass(&wndclass);
wndclass.hbrBackground = hGreenBrush;
wndclass.lpfnWndProc = ChildTopProc;
wndclass.lpszClassName = TEXT("ChildTop");
RegisterClass(&wndclass);
wndclass.hbrBackground = hBlueBrush;
wndclass.lpfnWndProc = ChildBottomProc;
wndclass.lpszClassName = TEXT("ChildBottom");
RegisterClass(&wndclass);
hWnd = CreateWindowExW(NULL, MyClassName, MyClassName,WS_OVERLAPPEDWINDOW|WS_VSCROLL|WS_HSCROLL,CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT, NULL,(HMENU)NULL,hInstance,NULL);
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
hWndMain = hWnd;
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
DeleteObject(hRedBrush);
DeleteObject(hGreenBrush);
DeleteObject(hBlueBrush);
return((int)msg.wParam);
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam) {
RECT crt{};
switch (iMessage){
case WM_CREATE:
hC1 = CreateWindowExW(NULL, TEXT("ChildLeft"), NULL, WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN,
0, 0, 0, 0, hWnd, (HMENU)0, g_hInst, NULL);
hC2 = CreateWindowExW(NULL, TEXT("ChildTop"), NULL, WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN,
0, 0, 0, 0, hWnd, (HMENU)0, g_hInst, NULL);
hC3 = CreateWindowExW(NULL, TEXT("ChildBottom"), NULL, WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN,
0, 0, 0, 0, hWnd, (HMENU)0, g_hInst, NULL);
return(0);
case WM_SIZE:
if (wParam != SIZE_MINIMIZED) {
GetClientRect(hWnd, &crt);
MoveWindow(hC1,0,0,300,crt.bottom,TRUE);
MoveWindow(hC2,300,0,crt.right-300,150,TRUE);
MoveWindow(hC3,300,150,crt.right-300,crt.bottom-150,TRUE);
}
return(0);
case WM_DESTROY:
PostQuitMessage(0);
return(0);
}
return(DefWindowProc(hWnd, iMessage, wParam, lParam));
}
------------------------------------------------------------------------------------------------------------
1) hRedBrush, hBlueBrush, hGreenBrush는 wWinMain함수에서 자동으로 삭제가 안되는 지요? 자동으로 삭제가 안되기에
DeleteObject를 사용하는지 궁금합니다.
2) hRedBrush, hBlueBrush, hGreenBrush는 DeleteObject로 삭제하는 것이 맞는지 궁금합니다. hdc를 생성하여 selectobject로
선택후 다른 OldhRedBrush등을 생성하여 재선택한후 삭제하는게 아닌 지 궁금합니다. 책 164p처러 해야 하는 것처럼
배웠는데 여기서는 바로 삭제하니 궁금합니다. hdc를 생성하여 배경을 주지 않아 메모리 영향에 끼치는 것이 없어 저렇게
삭제하는 것인지 궁금합니다.
3) hC1,hC2,hC3의 윈도우 생성 시 hParent(부모윈도우)는 WndProc의 인자 hWnd로 사용하는 것이 맞는지 궁금합니다. 앞에서
해당 hWnd는 메시지 입력 인자로 배웠는데 해당 인자가 부모 윈도우 인자로 이해하면 되는지 궁금합니다. hInstance는
wWinMain인자로 사용했지만 부모윈도우는 WndProc으로 사용해서 궁금합니다. 위의 hWndMain이 부모윈도우 인자로
생각했는데 아예 그려지지도 않고 궁금합니다.
4) wParam!=SIZE_MINIMIZED는 왜 사용하는지 궁금합니다. 알려주시기 바랍니다.

김민수
error code: 522
error code: 522
|
|