Created
November 23, 2016 13:33
-
-
Save nekko1119/27e4a000f8947c200544fa894265500d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <winerror.h> | |
#include <system_error> | |
#include <iostream> | |
#include <string> | |
int main() | |
{ | |
std::system("chcp 932"); | |
std::error_code ec{ERROR_FILE_EXISTS, std::system_category()}; | |
std::system_error se{ec}; | |
auto const str = se.what(); | |
std::cout << str << std::endl; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Windows.h> | |
#include <system_error> | |
#include <clocale> | |
LRESULT CALLBACK procedure(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) | |
{ | |
switch (msg) { | |
case WM_DESTROY: | |
{ | |
UpdateWindow(nullptr); | |
std::setlocale(LC_CTYPE, "jpn"); | |
wchar_t dest[1024]; | |
std::size_t size; | |
mbstowcs_s( | |
&size, | |
dest, | |
std::system_error{std::error_code{(int) GetLastError(), std::system_category()}}.what(), | |
_TRUNCATE | |
); | |
MessageBox(nullptr, dest, L"", MB_OK); | |
PostQuitMessage(0); | |
return 0; | |
} | |
} | |
return DefWindowProc(hwnd, msg, wParam, lParam);; | |
} | |
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR, int) | |
{ | |
WNDCLASSEX wc; | |
wc.cbSize = sizeof(WNDCLASSEX); | |
wc.style = CS_HREDRAW | CS_VREDRAW; | |
wc.lpfnWndProc = &procedure; | |
wc.cbClsExtra = 0; | |
wc.cbWndExtra = 0; | |
wc.hInstance = hInst; | |
wc.hIcon = static_cast<HICON>(LoadImage(nullptr, IDI_APPLICATION, IMAGE_ICON, 0, 0, LR_DEFAULTSIZE | LR_SHARED)); | |
wc.hCursor = static_cast<HCURSOR>(LoadImage(nullptr, IDC_ARROW, IMAGE_CURSOR, 0, 0, LR_DEFAULTSIZE | LR_SHARED)); | |
wc.hbrBackground = static_cast<HBRUSH>(GetStockObject(WHITE_BRUSH)); | |
wc.lpszMenuName = nullptr; | |
wc.lpszClassName = TEXT("main window"); | |
wc.hIconSm = static_cast<HICON>(LoadImage(nullptr, IDI_APPLICATION, IMAGE_ICON, 0, 0, LR_DEFAULTSIZE | LR_SHARED)); | |
RegisterClassEx(&wc); | |
auto hwnd = CreateWindowEx( | |
WS_EX_OVERLAPPEDWINDOW, | |
TEXT("main window"), | |
TEXT("RxCpp x Win32API"), | |
WS_OVERLAPPEDWINDOW, | |
CW_USEDEFAULT, CW_USEDEFAULT, | |
640, 480, | |
nullptr, | |
nullptr, | |
hInst, | |
nullptr); | |
ShowWindow(hwnd, SW_SHOW); | |
UpdateWindow(hwnd); | |
MSG msg; | |
BOOL ret; | |
while ((ret = GetMessage(&msg, hwnd, 0, 0)) != 0) { | |
if (ret == -1) { | |
break; | |
} | |
TranslateMessage(&msg); | |
DispatchMessage(&msg); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment