Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <math.h>
- #include <sstream>
- #include <Windows.h>
- #include <string>
- #include <gdiplus.h>
- #include <cassert>
- using std::wstring;
- LRESULT CALLBACK MainWindowProc(
- HWND hwnd,
- UINT uMsg,
- WPARAM wParam,
- LPARAM lParam
- );
- struct UserData {
- int fontSize;
- wstring str;
- };
- int CALLBACK WinMain(
- HINSTANCE hInstance,
- HINSTANCE hPrevInstance,
- LPSTR lpCmdLine,
- int nCmdShow
- ) {
- HBRUSH bckrndBrush = CreateSolidBrush(RGB(155, 89, 182));
- WNDCLASS mainWndClass = { 0 };
- mainWndClass.hInstance = hInstance;
- mainWndClass.lpszClassName = TEXT("KalyuzhinWin32_MainWindow");
- mainWndClass.lpfnWndProc = MainWindowProc;
- mainWndClass.hbrBackground = bckrndBrush;
- mainWndClass.hCursor = (HCURSOR)LoadCursor(NULL, IDC_ARROW);
- if (!RegisterClass(&mainWndClass)) {
- return 0;
- }
- int screenWeight = GetSystemMetrics(SM_CXSCREEN);
- int screenHeight = GetSystemMetrics(SM_CYSCREEN);
- int minSide = screenWeight < screenHeight ? screenWeight : screenHeight;
- int mainWindowWeight = minSide / 1.25;
- int mainWindowHeight = minSide / 1.25;
- UserData userData = UserData();
- userData.fontSize = 18;
- userData.str = L"lorem ipsum dolor sit amet";
- HWND mainHWND = CreateWindow(
- mainWndClass.lpszClassName,
- TEXT("Main"),
- WS_OVERLAPPEDWINDOW,
- screenWeight / 2 - mainWindowWeight / 2,
- screenHeight / 2 - mainWindowHeight / 2,
- mainWindowWeight,
- mainWindowHeight,
- NULL,
- NULL,
- hInstance,
- NULL);
- SetWindowLongPtr(mainHWND, GWLP_USERDATA, (LONG)&userData);
- ShowWindow(mainHWND, nCmdShow);
- MSG msg;
- while (GetMessage(&msg, NULL, 0, 0)) {
- DispatchMessage(&msg);
- }
- return msg.wParam;
- }
- void HandleSysCommand(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
- {
- }
- LRESULT CALLBACK MainWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
- {
- PAINTSTRUCT ps;
- HDC hdc;
- static int angle = 0;
- switch (uMsg) {
- case WM_CREATE: {
- HMENU hSysMenu = GetSystemMenu(hwnd, false);
- int cnt = GetMenuItemCount(hSysMenu);
- for (int i = 0; i < cnt; ++i) {
- MENUITEMINFO closeItem;
- GetMenuItemInfo(hSysMenu, i, TRUE, &closeItem);
- std::stringstream asd;
- asd << closeItem.wID << "\n";
- OutputDebugString(asd.str().c_str());
- }
- ModifyMenu(GetSystemMenu(hwnd, FALSE), SC_CLOSE, MF_BYCOMMAND, 100500, "Закрыть");
- DrawMenuBar(hwnd);
- break;
- }
- case WM_COMMAND: {
- break;
- }
- case WM_SYSCOMMAND: {
- if (wParam == 100500) {
- DestroyWindow(hwnd);
- break;
- }
- if (wParam == 61536) {
- WORD xPos = LOWORD(lParam);
- WORD yPos = HIWORD(lParam);
- if (xPos != 0 && yPos != 0)
- return 0;
- }
- return DefWindowProc(hwnd, uMsg, wParam, lParam);
- break;
- }
- case WM_DESTROY:
- PostQuitMessage(0);
- break;
- default:
- return DefWindowProc(hwnd, uMsg, wParam, lParam);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement