Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <string>
- #define ID_BUTTON 1
- LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
- HANDLE hwndButton;
- 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"test";
- wc.hInstance = hInstance;
- wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
- wc.lpfnWndProc = WndProc;
- wc.hCursor = LoadCursor(0, IDC_ARROW);
- RegisterClassW(&wc);
- CreateWindowW(wc.lpszClassName, L"Test", WS_OVERLAPPEDWINDOW|WS_VISIBLE, 260, 134, 288, 104, 0, 0, hInstance, 0);
- 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) {
- int ret = MessageBoxW(hwnd, L"Woot?",
- L"Message", MB_OKCANCEL);
- if (ret == IDOK) {
- SendMessage(hwnd, WM_CLOSE, 0, 0);
- }
- }
- break;
- case WM_CREATE:
- CenterWindow(hwnd);
- hwndButton=CreateWindowW(L"Button", L"Click", WS_VISIBLE|WS_CHILD, 50, 9, 61, 21, hwnd, (HMENU)ID_BUTTON, NULL, NULL);
- break;
- case WM_COMMAND:
- if(LOWORD(wParam)==ID_BUTTON)
- {
- }
- 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