Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM WParam, LPARAM lParam);
- LRESULT CALLBACK ChildProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
- HINSTANCE g_hInst;
- HWND hWndMain;
- RECT Mainrt;
- int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR nCmdLine, int nCmdShow) {
- LPCTSTR lpszClassName = TEXT("클래스");
- HWND hWnd;
- MSG msg;
- g_hInst = hInstance;
- WNDCLASSEX wc;
- wc.cbSize = sizeof(WNDCLASSEX);
- wc.style = CS_HREDRAW | CS_VREDRAW;
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 0;
- wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
- wc.hCursor = LoadCursor(NULL, IDC_ARROW);
- wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
- wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
- wc.lpfnWndProc = WndProc;
- wc.lpszClassName = lpszClassName;
- wc.lpszMenuName = NULL;
- wc.hInstance = hInstance;
- RegisterClassEx(&wc);
- wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
- wc.style = CS_NOCLOSE | CS_VREDRAW;
- wc.lpszClassName = TEXT("부모 윈도우");
- wc.lpfnWndProc = ChildProc;
- RegisterClassEx(&wc);
- hWnd = CreateWindow(
- lpszClassName,
- TEXT("Adhere"),
- WS_OVERLAPPEDWINDOW,
- CW_USEDEFAULT,
- CW_USEDEFAULT,
- CW_USEDEFAULT,
- CW_USEDEFAULT,
- NULL,
- NULL,
- hInstance,
- 0);
- if (!hWnd) {
- return FALSE;
- }
- ShowWindow(hWnd, nCmdShow);
- UpdateWindow(hWnd);
- while (GetMessage(&msg, NULL, 0, 0)) {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- return msg.wParam;
- }
- LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
- HDC hdc;
- PAINTSTRUCT ps;
- HWND hWndChild;
- switch (uMsg) {
- case WM_CREATE:
- hWndMain = hWnd;
- hWndChild = CreateWindow(
- TEXT("부모 윈도우"),
- TEXT("팔레트"),
- WS_POPUP | WS_CAPTION | WS_THICKFRAME | WS_SYSMENU,
- 200, 250, 200, 200,
- hWndMain,
- NULL,
- g_hInst,
- NULL);
- ShowWindow(hWndChild, SW_SHOW);
- return 0;
- case WM_PAINT:
- hdc = BeginPaint(hWnd, &ps);
- EndPaint(hWnd, &ps);
- return 0;
- case WM_DESTROY:
- PostQuitMessage(0);
- return 0;
- }
- return DefWindowProc(hWnd, uMsg, wParam, lParam);
- }
- LRESULT CALLBACK ChildProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
- HDC hdc;
- PAINTSTRUCT ps;
- LPWINDOWPOS wp;
- int height;
- int t;
- switch (uMsg) {
- case WM_CREATE:
- return 0;
- case WM_WINDOWPOSCHANGING:
- GetWindowRect(hWndMain, &Mainrt);
- height = Mainrt.bottom - Mainrt.top;
- wp = (LPWINDOWPOS)lParam;
- wp->cx = 200;
- wp->cy = min(max(wp->cy, height / 4), height);
- t = wp->x;
- if (abs(Mainrt.left - t) < 30)
- t = Mainrt.left + 10;
- if (abs(Mainrt.right - (t + wp->cx)) < 30)
- t = (Mainrt.right - wp->cx) - 10;
- wp->x = t;
- return 0;
- case WM_PAINT:
- hdc = BeginPaint(hWnd, &ps);
- EndPaint(hWnd, &ps);
- return 0;
- case WM_DESTROY:
- PostQuitMessage(0);
- return 0;
- }
- return DefWindowProc(hWnd, uMsg, wParam, lParam);
- }
Add Comment
Please, Sign In to add comment