Guest User

Untitled

a guest
Feb 19th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.22 KB | None | 0 0
  1. #include <windows.h>
  2. LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM WParam, LPARAM lParam);
  3. LRESULT CALLBACK ChildProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  4. HINSTANCE g_hInst;
  5. HWND hWndMain;
  6. RECT Mainrt;
  7.  
  8.  
  9. int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR nCmdLine, int nCmdShow) {
  10. LPCTSTR lpszClassName = TEXT("클래스");
  11.  
  12. HWND hWnd;
  13. MSG msg;
  14. g_hInst = hInstance;
  15. WNDCLASSEX wc;
  16.  
  17. wc.cbSize = sizeof(WNDCLASSEX);
  18. wc.style = CS_HREDRAW | CS_VREDRAW;
  19. wc.cbClsExtra = 0;
  20. wc.cbWndExtra = 0;
  21. wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
  22. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  23. wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  24. wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
  25. wc.lpfnWndProc = WndProc;
  26. wc.lpszClassName = lpszClassName;
  27. wc.lpszMenuName = NULL;
  28. wc.hInstance = hInstance;
  29. RegisterClassEx(&wc);
  30.  
  31. wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
  32. wc.style = CS_NOCLOSE | CS_VREDRAW;
  33. wc.lpszClassName = TEXT("부모 윈도우");
  34. wc.lpfnWndProc = ChildProc;
  35. RegisterClassEx(&wc);
  36.  
  37. hWnd = CreateWindow(
  38. lpszClassName,
  39. TEXT("Adhere"),
  40. WS_OVERLAPPEDWINDOW,
  41. CW_USEDEFAULT,
  42. CW_USEDEFAULT,
  43. CW_USEDEFAULT,
  44. CW_USEDEFAULT,
  45. NULL,
  46. NULL,
  47. hInstance,
  48. 0);
  49.  
  50. if (!hWnd) {
  51. return FALSE;
  52. }
  53.  
  54. ShowWindow(hWnd, nCmdShow);
  55. UpdateWindow(hWnd);
  56.  
  57. while (GetMessage(&msg, NULL, 0, 0)) {
  58. TranslateMessage(&msg);
  59. DispatchMessage(&msg);
  60. }
  61.  
  62. return msg.wParam;
  63. }
  64.  
  65.  
  66. LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
  67. HDC hdc;
  68. PAINTSTRUCT ps;
  69. HWND hWndChild;
  70.  
  71. switch (uMsg) {
  72. case WM_CREATE:
  73. hWndMain = hWnd;
  74. hWndChild = CreateWindow(
  75. TEXT("부모 윈도우"),
  76. TEXT("팔레트"),
  77. WS_POPUP | WS_CAPTION | WS_THICKFRAME | WS_SYSMENU,
  78. 200, 250, 200, 200,
  79. hWndMain,
  80. NULL,
  81. g_hInst,
  82. NULL);
  83. ShowWindow(hWndChild, SW_SHOW);
  84. return 0;
  85. case WM_PAINT:
  86. hdc = BeginPaint(hWnd, &ps);
  87. EndPaint(hWnd, &ps);
  88. return 0;
  89. case WM_DESTROY:
  90. PostQuitMessage(0);
  91. return 0;
  92. }
  93.  
  94. return DefWindowProc(hWnd, uMsg, wParam, lParam);
  95. }
  96.  
  97.  
  98. LRESULT CALLBACK ChildProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
  99. HDC hdc;
  100. PAINTSTRUCT ps;
  101. LPWINDOWPOS wp;
  102. int height;
  103. int t;
  104.  
  105. switch (uMsg) {
  106. case WM_CREATE:
  107. return 0;
  108. case WM_WINDOWPOSCHANGING:
  109. GetWindowRect(hWndMain, &Mainrt);
  110. height = Mainrt.bottom - Mainrt.top;
  111. wp = (LPWINDOWPOS)lParam;
  112. wp->cx = 200;
  113. wp->cy = min(max(wp->cy, height / 4), height);
  114. t = wp->x;
  115.  
  116. if (abs(Mainrt.left - t) < 30)
  117. t = Mainrt.left + 10;
  118. if (abs(Mainrt.right - (t + wp->cx)) < 30)
  119. t = (Mainrt.right - wp->cx) - 10;
  120. wp->x = t;
  121. return 0;
  122. case WM_PAINT:
  123. hdc = BeginPaint(hWnd, &ps);
  124. EndPaint(hWnd, &ps);
  125. return 0;
  126. case WM_DESTROY:
  127. PostQuitMessage(0);
  128. return 0;
  129. }
  130.  
  131. return DefWindowProc(hWnd, uMsg, wParam, lParam);
  132. }
Add Comment
Please, Sign In to add comment