Advertisement
Combreal

Akakyuri01.cpp

Jun 20th, 2020
1,055
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.43 KB | None | 0 0
  1. #include <windows.h>
  2. #include <commctrl.h>
  3. #include <string>
  4. #include "resource.h"
  5.  
  6. LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
  7. HANDLE hwndButton;
  8. HWND hWindowa, hWndProgressBar;
  9. int counter = 0;
  10.  
  11. void CenterWindow(HWND);
  12. LPWSTR stringToLPWSTR(const std::string& instr);
  13.  
  14. int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow)
  15. {
  16.     MSG msg;
  17.     WNDCLASSW wc = { 0 };
  18.     wc.lpszClassName = L"Akakyuri";
  19.     wc.hInstance = hInstance;
  20.     wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
  21.     wc.lpfnWndProc = WndProc;
  22.     wc.hCursor = LoadCursor(0, IDC_ARROW);
  23.     RegisterClassW(&wc);
  24.     hWindowa = CreateWindowW(wc.lpszClassName, L"", WS_CAPTION | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_OVERLAPPED | WS_MAXIMIZEBOX | WS_MINIMIZEBOX, 260, 130, 280, 135, 0, 0, hInstance, 0); // | WS_VISIBLE
  25.     ShowWindow(hWindowa, SW_HIDE);
  26.     int ret = MessageBox(NULL, "You are about to delete data on your system", "", MB_OKCANCEL | MB_ICONEXCLAMATION);
  27.     if ((ret == IDOK) || (ret == IDCANCEL))
  28.     {
  29.         ShowWindow(hWindowa, SW_SHOW);
  30.     }
  31.     while (GetMessage(&msg, NULL, 0, 0))
  32.     {
  33.         TranslateMessage(&msg);
  34.         DispatchMessage(&msg);
  35.     }
  36.     return (int)msg.wParam;
  37. }
  38.  
  39. LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  40. {
  41.     switch (msg)
  42.     {
  43.     case WM_KEYDOWN:
  44.         if (wParam == VK_ESCAPE)
  45.         {
  46.             MessageBoxW(hwnd, L"Do you want to abort?", L"Message", MB_OK);
  47.         }
  48.         break;
  49.     case WM_CREATE:
  50.         CenterWindow(hwnd);
  51.         CreateWindowEx(0, "STATIC", "Deleting data :", WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS, 10, 10, 120, 30, hwnd, (HMENU)IDC_STATICA, GetModuleHandle(NULL), 0);
  52.         hWndProgressBar = CreateWindowEx(0, PROGRESS_CLASS, (LPSTR)NULL, WS_VISIBLE | WS_CHILD , 10, 30, 240, 28, hwnd, (HMENU)IDPB_PROGRESS_BAR, (HINSTANCE)SetWindowLongPtr(hwnd, GWLP_HINSTANCE, DWLP_DLGPROC), NULL);
  53.         hwndButton = CreateWindowW(L"Button", L"Cancel", WS_VISIBLE | WS_CHILD, 100, 65, 61, 21, hwnd, (HMENU)ID_BUTTON, NULL, NULL);
  54.         if (!hWndProgressBar)
  55.         {
  56.             SendMessage(hwnd, PBM_SETRANGE, 0, MAKELPARAM(0, 9));
  57.             SendMessage(hwnd, PBM_SETSTEP, (WPARAM)1, 0);
  58.         }
  59.         break;
  60.     case WM_TIMER:
  61.     {
  62.         switch ((UINT)wParam)
  63.         {
  64.         case IDT_TIMER:
  65.         {
  66.             KillTimer(hwnd, IDT_TIMER);
  67.             KillTimer(hwnd, IDT_PROGRESS_TIMER);
  68.         }
  69.         break;
  70.         case IDT_PROGRESS_TIMER:
  71.             SendMessage(hWndProgressBar, PBM_STEPIT, 0, 0);
  72.             counter++;
  73.             if (counter == 10)
  74.             {
  75.                 PostMessage(hwnd, WM_CLOSE, 0, 0);
  76.             }
  77.             break;
  78.         }
  79.     }
  80.     break;
  81.     case WM_COMMAND:
  82.         if (LOWORD(wParam) == ID_BUTTON)
  83.         {
  84.            
  85.         }
  86.         break;
  87.     case WM_SHOWWINDOW:
  88.         if (SetTimer(hwnd, IDT_TIMER, 9000, (TIMERPROC)NULL))
  89.         {
  90.             SetTimer(hwnd, IDT_PROGRESS_TIMER, 500, (TIMERPROC)NULL);
  91.         }
  92.         break;
  93.     case WM_DESTROY:
  94.         PostQuitMessage(0);
  95.         break;
  96.     }
  97.     return DefWindowProcW(hwnd, msg, wParam, lParam);
  98. }
  99.  
  100. void CenterWindow(HWND hwnd)
  101. {
  102.     RECT rc = { 0 };
  103.     GetWindowRect(hwnd, &rc);
  104.     int win_w = rc.right - rc.left;
  105.     int win_h = rc.bottom - rc.top;
  106.     int screen_w = GetSystemMetrics(SM_CXSCREEN);
  107.     int screen_h = GetSystemMetrics(SM_CYSCREEN);
  108.     SetWindowPos(hwnd, HWND_TOP, (screen_w - win_w) / 2, (screen_h - win_h) / 2, 0, 0, SWP_NOSIZE);
  109. }
  110.  
  111. LPWSTR stringToLPWSTR(const std::string& instr)
  112. {
  113.     int bufferlen = ::MultiByteToWideChar(CP_ACP, 0, instr.c_str(), instr.size(), NULL, 0);
  114.     LPWSTR widestr = new WCHAR[bufferlen + 1];
  115.     ::MultiByteToWideChar(CP_ACP, 0, instr.c_str(), instr.size(), widestr, bufferlen);
  116.     widestr[bufferlen] = 0;
  117.     return widestr;
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement