Skip to content

Instantly share code, notes, and snippets.

@nekko1119
Created November 23, 2016 13:33
Show Gist options
  • Save nekko1119/27e4a000f8947c200544fa894265500d to your computer and use it in GitHub Desktop.
Save nekko1119/27e4a000f8947c200544fa894265500d to your computer and use it in GitHub Desktop.
#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;
}
#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