Ä¿½ºÅÒ À©µµ¿ì¸¦ ¸¸µé·Á°í µÎ ¼Ó¼ºÀ» °°ÀÌ Áà ºÃ´Âµ¥ ¾Ë ¼ö ¾ø´Â ÀÌ»óÇÑ ¹®Á¦°¡ »ý°å´Ù.
Àü¿¡´Â ¾È ±×·¨´ø °Å °°Àºµ¥ ÆË¾÷À» µÎ²¨¿î °æ°è¼±À¸·Î ¸¸µé¸é À§ÂÊ¿¡ Èò»ö ¹Ù°¡ Ç¥½ÃµÈ´Ù.
¶ÇÇÑ ÀÛ¾÷ ¿µ¿ªÀÇ Å©±â°¡ °æ°è¼±¿¡ µû¶ó ÁÙ¾î µå´Â ¹®Á¦°¡ ÀÖ´Ù.
¿Ö ±×·±Áö ¿¹Á¦¸¦ ¸¸µé¾î º¸¾Ò´Ù.
#include
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
HINSTANCE g_hInst;
HWND hWndMain;
LPCTSTR lpszClass = TEXT("PopupWnd");
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance
, LPSTR lpszCmdParam, int nCmdShow)
{
HWND hWnd;
MSG Message;
WNDCLASS WndClass;
g_hInst = hInstance;
WndClass.cbClsExtra = 0;
WndClass.cbWndExtra = 0;
WndClass.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH);
WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WndClass.hInstance = hInstance;
WndClass.lpfnWndProc = WndProc;
WndClass.lpszClassName = lpszClass;
WndClass.lpszMenuName = NULL;
WndClass.style = CS_HREDRAW | CS_VREDRAW;
RegisterClass(&WndClass);
// ÀÌ µÎ ½ºÅ¸ÀÏÀ» ÁÖ¸é À§ÂÊ¿¡ Èò ¹Ù°¡ »ý±ä´Ù.
hWnd = CreateWindow(lpszClass, lpszClass, WS_POPUP | WS_VISIBLE,
1000, 500, 100, 100,
NULL, (HMENU)NULL, hInstance, NULL);
CreateWindow(lpszClass, lpszClass, WS_POPUP | WS_BORDER | WS_VISIBLE,
1110, 500, 100, 100,
NULL, (HMENU)NULL, hInstance, NULL);
CreateWindow(lpszClass, lpszClass, WS_POPUP | WS_THICKFRAME | WS_VISIBLE,
1220, 500, 100, 100,
NULL, (HMENU)NULL, hInstance, NULL);
ShowWindow(hWnd, nCmdShow);
hWndMain = hWnd;
while (GetMessage(&Message, NULL, 0, 0)) {
TranslateMessage(&Message);
DispatchMessage(&Message);
}
return Message.wParam;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
UINT nHit;
TCHAR Mes[128];
switch (iMessage) {
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
SetBkMode(hdc, TRANSPARENT);
RECT wrt;
GetWindowRect(hWnd, &wrt);
wsprintf(Mes, TEXT("W:%d,%d"), wrt.right - wrt.left, wrt.bottom - wrt.top);
TextOut(hdc, 10, 10, Mes, lstrlen(Mes));
RECT crt;
GetClientRect(hWnd, &crt);
wsprintf(Mes, TEXT("C:%d,%d"), crt.right, crt.bottom);
TextOut(hdc, 10, 30, Mes, lstrlen(Mes));
EndPaint(hWnd, &ps);
return 0;
case WM_NCHITTEST:
nHit = DefWindowProc(hWnd, iMessage, wParam, lParam);
if (nHit == HTCLIENT)
nHit = HTCAPTION;
return nHit;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return(DefWindowProc(hWnd, iMessage, wParam, lParam));
}
ÆË¾÷ À©µµ¿ì 3°³¸¦ ½ºÅ¸ÀÏ ¹Ù²ã °¡¸ç 100 * 100 Å©±â·Î Ãâ·ÂÇߴµ¥ °á°ú´Â ´ÙÀ½°ú °°´Ù.

À©µµ¿ì Å©±â´Â ´ç¿¬È÷ 100 * 100ÀÌ°í °æ°è¼±ÀÌ ¾øÀ¸¸é ÀÛ¾÷ ¿µ¿ªµµ ¶È°°´Ù.
WS_BORDER ½ºÅ¸ÀÏÀ» ÁÖ¸é »óÇÏÁ¿ì·Î 1Çȼ¿¾¿ °æ°è¼±ÀÌ Â÷ÁöÇÏ¿© ÀÛ¾÷ ¿µ¿ªÀº 2Çȼ¿¾¿ ÁÙ¾î µç´Ù.
±×·±µ¥ WS_THICKFRAMEÀ» ÁÖ¸é 14Çȼ¿¾¿ ÁÙ¾îµé »Ó¸¸ ¾Æ´Ï¶ó ŸÀÌÆ² ¹Ù À§ÂÊ¿¡ Èò»ö ¹Ù°¡ »ý±ä´Ù.
À©µµ¿ì ¹Ù±ùÂÊ¿¡ ±×¸²ÀÚ¸¦ ±î´À¶ó ÀÛ¾÷¿µ¿ªÀÌ Áö³ªÄ¡°Ô Ãà¼ÒµÇ°í ºÒÇÊ¿äÇÑ ÁÙ±îÁö ±×¾îÁø´Ù.
¹®Á¦´Â Àü ¹öÀü¿¡¼´Â ÀÌ·¯Áö ¾Ê¾Ò´Ù´Â °ÍÀÌ´Ù.
À©µµ¿ì ¹öÀüÀ̳ª Å׸¶ »ó°ü¾øÀÌ ÀÏÁ¤ÇÑ Å©±â¸¦ È®º¸ÇÏ·Á¸é WS_THICKFRAME ½ºÅ¸ÀÏÀº ¾²Áö ¸»¾Æ¾ß ÇÑ´Ù.
WS_POPUPÀ» ¾²¸é¼ Å©±â º¯°æµµ °¡´ÉÇÏ·Á¸é °á±¹ Á÷Á¢ ÄÚµùÇÏ´Â ¼ö¹Û¿¡ ¾ø´Ù.
ÆòÀÌÇÏ°Ô WS_POPUP ½ºÅ¸Àϸ¸ ÁÖ°í 100 * 100 Å©±â·Î À©µµ¿ì¸¦ »ý¼ºÇÑ´Ù.
hWnd = CreateWindow(lpszClass, lpszClass, WS_POPUP | WS_VISIBLE,
1000, 500, 100, 100,
NULL, (HMENU)NULL, hInstance, NULL);
ShowWindow(hWnd, nCmdShow);
.....
LRESULT CALLBACK WndProc(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
UINT nHit;
TCHAR Mes[128];
const int borderThick = 2;
HPEN gray, darkgray, oldPen;
switch (iMessage) {
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
SetBkMode(hdc, TRANSPARENT);
RECT wrt;
GetWindowRect(hWnd, &wrt);
RECT crt;
GetClientRect(hWnd, &crt);
// °æ°è¼±À» ÀÔ¸À´ë·Î Á÷Á¢ ±×¸°´Ù.
// Rectangle·Î ±×¸®¸é ±ò²ûÇÏÁö ¸øÇÏ´Ù.
gray = CreatePen(PS_SOLID, 1, RGB(0xf0, 0xf0, 0xf0));
darkgray = CreatePen(PS_SOLID, 1, RGB(0xa0, 0xa0, 0xa0));
oldPen = (HPEN)SelectObject(hdc, gray);
MoveToEx(hdc, 0, 0, NULL); LineTo(hdc, crt.right, 0);
MoveToEx(hdc, 0, 0, NULL); LineTo(hdc, 0, crt.bottom);
MoveToEx(hdc, crt.right - 2, 0, NULL); LineTo(hdc, crt.right - 2, crt.bottom - 1);
MoveToEx(hdc, 1, crt.bottom - 2, NULL); LineTo(hdc, crt.right - 2, crt.bottom - 2);
SelectObject(hdc, darkgray);
MoveToEx(hdc, 1, 1, NULL); LineTo(hdc, crt.right - 2, 1);
MoveToEx(hdc, 1, 1, NULL); LineTo(hdc, 1, crt.bottom - 2);
MoveToEx(hdc, crt.right - 1, 0, NULL); LineTo(hdc, crt.right - 1, crt.bottom - 1);
MoveToEx(hdc, 0, crt.bottom - 1, NULL); LineTo(hdc, crt.right - 1, crt.bottom - 1);
SelectObject(hdc, oldPen);
DeleteObject(gray);
DeleteObject(darkgray);
wsprintf(Mes, TEXT("W:%d,%d"), wrt.right - wrt.left, wrt.bottom - wrt.top);
TextOut(hdc, 10, 10, Mes, lstrlen(Mes));
wsprintf(Mes, TEXT("C:%d,%d"), crt.right, crt.bottom);
TextOut(hdc, 10, 30, Mes, lstrlen(Mes));
EndPaint(hWnd, &ps);
return 0;
case WM_NCHITTEST:
nHit = DefWindowProc(hWnd, iMessage, wParam, lParam);
if (nHit == HTCLIENT) {
RECT crt;
POINT mpt;
GetClientRect(hWnd, &crt);
mpt.x = LOWORD(lParam);
mpt.y = HIWORD(lParam);
ScreenToClient(hWnd, &mpt);
// »óÇÏ Á¿캯¿¡ Ä¿¼°¡ ÀÖÀ¸¸é Å©±â¸¦ Á¶Á¤ÇÑ´Ù.
if (mpt.x < borderThick)
return HTLEFT;
if (mpt.x > crt.right - 1 - borderThick)
return HTRIGHT;
if (mpt.y < borderThick)
return HTTOP;
if (mpt.y > crt.bottom - 1 - borderThick)
return HTBOTTOM;
}
// ±× ¿ÜÀÇ ¿µ¿ªÀº À©µµ¿ì¸¦ À̵¿ÇÑ´Ù.
nHit = HTCAPTION;
return nHit;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return(DefWindowProc(hWnd, iMessage, wParam, lParam));
}
WM_PAINT¿¡¼ °æ°è¼±À» Á÷Á¢ ±×¸°´Ù. À§ ¿ÞÂÊÀº ¾à°£ ¹à°Ô, ¾Æ·¡ ¿À¸¥ÂÊÀº ¾à°£ ¾îµÓ°Ô ÇÏ¿© ÀÔü°¨À» ÁÖ¾ú´Ù.
ÀÌ°Ç Rectangle·Îµµ ±×¸± ¼ö ÀÖÁö¸¸ °ãÄ¡´Â ºÎºÐÀÌ ±úÁö´Â ¹®Á¦°¡ ÀÖ¾î Á÷¼±À¸·Î Ç¥ÇöÇß´Ù.
¶Ç ES_EX_CLIENTEDGE È®Àå ½ºÅ¸ÀÏ·Î ºñ½ÁÇÑ È¿°ú¸¦ ³¾ ¼ö ÀÖÁö¸¸ À̰͵µ Å׸¶³ª ¹öÀü¿¡ µû¶ó ´Þ¶óÁú ¼ö ÀÖ¾î
¾ÈÀüÇÏÁö ¾Ê´Ù. ±×³É ±×¸®´Â°Ô Á¦ÀÏ ¼ÓÆíÇÏ´Ù.
WM_NCHITTEST¿¡¼ Ä¿¼ÀÇ À§Ä¡¿¡ µû¶ó °æ°è¼±À» ÆÇº°ÇÏ¿© Ä¿¼ ¹æÇâÀ» ÁöÁ¤Çϸé Å©±â Á¶Á¤ÀÌ °¡´ÉÇÏ´Ù.
¸ð¼¸® ºÎºÐµµ ó¸®ÇÒ ¼ö ÀÖÁö¸¸ ±»ÀÌ ±×·¸°Ô±îÁö ÇÏÁö´Â ¾Ê¾Ò´Ù.
°æ°è¼± ÀÌ¿ÜÀÇ ºÎºÐÀº À©µµ¿ì¸¦ À̵¿ÇÏ´Â °ÍÀ¸·Î ó¸®Çß´Ù.
ÀÌ ¹æ½Ä´ë·Î Çϸé Ä¿½ºÅÒ À©µµ¿ì¸¦ ½±°Ô ¸¸µé ¼ö ÀÖ°í ÀÚÀ¯µµ°¡ ³ô´Ù.

¿À´Ãµµ ÃÖ¼±À» ´Ù ÇÏÀÚ. |
|