Advertisement
Guest User

Untitled

a guest
Oct 19th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 KB | None | 0 0
  1.  
  2. #include <cstdio>
  3. #include <math.h>
  4. #include <sstream>
  5. #include <Windows.h>
  6. #include <string>
  7. #include <gdiplus.h>
  8. #include <cassert>
  9. using std::wstring;
  10.  
  11. LRESULT CALLBACK MainWindowProc(
  12. HWND hwnd,
  13. UINT uMsg,
  14. WPARAM wParam,
  15. LPARAM lParam
  16. );
  17.  
  18. struct UserData {
  19. int fontSize;
  20. wstring str;
  21. };
  22.  
  23. int CALLBACK WinMain(
  24. HINSTANCE hInstance,
  25. HINSTANCE hPrevInstance,
  26. LPSTR lpCmdLine,
  27. int nCmdShow
  28. ) {
  29. HBRUSH bckrndBrush = CreateSolidBrush(RGB(155, 89, 182));
  30. WNDCLASS mainWndClass = { 0 };
  31. mainWndClass.hInstance = hInstance;
  32. mainWndClass.lpszClassName = TEXT("KalyuzhinWin32_MainWindow");
  33. mainWndClass.lpfnWndProc = MainWindowProc;
  34. mainWndClass.hbrBackground = bckrndBrush;
  35. mainWndClass.hCursor = (HCURSOR)LoadCursor(NULL, IDC_ARROW);
  36. if (!RegisterClass(&mainWndClass)) {
  37. return 0;
  38. }
  39. int screenWeight = GetSystemMetrics(SM_CXSCREEN);
  40. int screenHeight = GetSystemMetrics(SM_CYSCREEN);
  41. int minSide = screenWeight < screenHeight ? screenWeight : screenHeight;
  42. int mainWindowWeight = minSide / 1.25;
  43. int mainWindowHeight = minSide / 1.25;
  44.  
  45. UserData userData = UserData();
  46. userData.fontSize = 18;
  47. userData.str = L"lorem ipsum dolor sit amet";
  48. HWND mainHWND = CreateWindow(
  49. mainWndClass.lpszClassName,
  50. TEXT("Main"),
  51. WS_OVERLAPPEDWINDOW,
  52. screenWeight / 2 - mainWindowWeight / 2,
  53. screenHeight / 2 - mainWindowHeight / 2,
  54. mainWindowWeight,
  55. mainWindowHeight,
  56. NULL,
  57. NULL,
  58. hInstance,
  59. NULL);
  60. SetWindowLongPtr(mainHWND, GWLP_USERDATA, (LONG)&userData);
  61. ShowWindow(mainHWND, nCmdShow);
  62.  
  63. MSG msg;
  64. while (GetMessage(&msg, NULL, 0, 0)) {
  65. DispatchMessage(&msg);
  66. }
  67. return msg.wParam;
  68. }
  69.  
  70. void HandleSysCommand(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  71. {
  72.  
  73. }
  74.  
  75. LRESULT CALLBACK MainWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  76. {
  77. PAINTSTRUCT ps;
  78. HDC hdc;
  79. static int angle = 0;
  80. switch (uMsg) {
  81. case WM_CREATE: {
  82. HMENU hSysMenu = GetSystemMenu(hwnd, false);
  83.  
  84. int cnt = GetMenuItemCount(hSysMenu);
  85. for (int i = 0; i < cnt; ++i) {
  86. MENUITEMINFO closeItem;
  87. GetMenuItemInfo(hSysMenu, i, TRUE, &closeItem);
  88. std::stringstream asd;
  89. asd << closeItem.wID << "\n";
  90. OutputDebugString(asd.str().c_str());
  91. }
  92. ModifyMenu(GetSystemMenu(hwnd, FALSE), SC_CLOSE, MF_BYCOMMAND, 100500, "Закрыть");
  93. DrawMenuBar(hwnd);
  94. break;
  95. }
  96. case WM_COMMAND: {
  97.  
  98. break;
  99. }
  100. case WM_SYSCOMMAND: {
  101. if (wParam == 100500) {
  102. DestroyWindow(hwnd);
  103. break;
  104. }
  105. if (wParam == 61536) {
  106. WORD xPos = LOWORD(lParam);
  107. WORD yPos = HIWORD(lParam);
  108. if (xPos != 0 && yPos != 0)
  109. return 0;
  110. }
  111. return DefWindowProc(hwnd, uMsg, wParam, lParam);
  112. break;
  113. }
  114. case WM_DESTROY:
  115. PostQuitMessage(0);
  116. break;
  117. default:
  118. return DefWindowProc(hwnd, uMsg, wParam, lParam);
  119. }
  120. return 0;
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement