#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´Â ¿Ö »ç¿ëÇÏ´ÂÁö ±Ã±ÝÇÕ´Ï´Ù. ¾Ë·ÁÁֽñ⠹ٶø´Ï´Ù.

±è¹Î¼ö
403 Forbidden403 Forbidden |
|