Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <commctrl.h>
- #include <string>
- #include "resource.h"
- LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
- HANDLE hwndButton;
- HWND hWindowa, hWndProgressBar;
- int counter = 0;
- void CenterWindow(HWND);
- LPWSTR stringToLPWSTR(const std::string& instr);
- int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow)
- {
- MSG msg;
- WNDCLASSW wc = { 0 };
- wc.lpszClassName = L"Akakyuri";
- wc.hInstance = hInstance;
- wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
- wc.lpfnWndProc = WndProc;
- wc.hCursor = LoadCursor(0, IDC_ARROW);
- RegisterClassW(&wc);
- 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
- ShowWindow(hWindowa, SW_HIDE);
- int ret = MessageBox(NULL, "You are about to delete data on your system", "", MB_OKCANCEL | MB_ICONEXCLAMATION);
- if ((ret == IDOK) || (ret == IDCANCEL))
- {
- ShowWindow(hWindowa, SW_SHOW);
- }
- while (GetMessage(&msg, NULL, 0, 0))
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- return (int)msg.wParam;
- }
- LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
- {
- switch (msg)
- {
- case WM_KEYDOWN:
- if (wParam == VK_ESCAPE)
- {
- MessageBoxW(hwnd, L"Do you want to abort?", L"Message", MB_OK);
- }
- break;
- case WM_CREATE:
- CenterWindow(hwnd);
- CreateWindowEx(0, "STATIC", "Deleting data :", WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS, 10, 10, 120, 30, hwnd, (HMENU)IDC_STATICA, GetModuleHandle(NULL), 0);
- 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);
- hwndButton = CreateWindowW(L"Button", L"Cancel", WS_VISIBLE | WS_CHILD, 100, 65, 61, 21, hwnd, (HMENU)ID_BUTTON, NULL, NULL);
- if (!hWndProgressBar)
- {
- SendMessage(hwnd, PBM_SETRANGE, 0, MAKELPARAM(0, 9));
- SendMessage(hwnd, PBM_SETSTEP, (WPARAM)1, 0);
- }
- break;
- case WM_TIMER:
- {
- switch ((UINT)wParam)
- {
- case IDT_TIMER:
- {
- KillTimer(hwnd, IDT_TIMER);
- KillTimer(hwnd, IDT_PROGRESS_TIMER);
- }
- break;
- case IDT_PROGRESS_TIMER:
- SendMessage(hWndProgressBar, PBM_STEPIT, 0, 0);
- counter++;
- if (counter == 10)
- {
- PostMessage(hwnd, WM_CLOSE, 0, 0);
- }
- break;
- }
- }
- break;
- case WM_COMMAND:
- if (LOWORD(wParam) == ID_BUTTON)
- {
- }
- break;
- case WM_SHOWWINDOW:
- if (SetTimer(hwnd, IDT_TIMER, 9000, (TIMERPROC)NULL))
- {
- SetTimer(hwnd, IDT_PROGRESS_TIMER, 500, (TIMERPROC)NULL);
- }
- break;
- case WM_DESTROY:
- PostQuitMessage(0);
- break;
- }
- return DefWindowProcW(hwnd, msg, wParam, lParam);
- }
- void CenterWindow(HWND hwnd)
- {
- RECT rc = { 0 };
- GetWindowRect(hwnd, &rc);
- int win_w = rc.right - rc.left;
- int win_h = rc.bottom - rc.top;
- int screen_w = GetSystemMetrics(SM_CXSCREEN);
- int screen_h = GetSystemMetrics(SM_CYSCREEN);
- SetWindowPos(hwnd, HWND_TOP, (screen_w - win_w) / 2, (screen_h - win_h) / 2, 0, 0, SWP_NOSIZE);
- }
- LPWSTR stringToLPWSTR(const std::string& instr)
- {
- int bufferlen = ::MultiByteToWideChar(CP_ACP, 0, instr.c_str(), instr.size(), NULL, 0);
- LPWSTR widestr = new WCHAR[bufferlen + 1];
- ::MultiByteToWideChar(CP_ACP, 0, instr.c_str(), instr.size(), widestr, bufferlen);
- widestr[bufferlen] = 0;
- return widestr;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement