void ExceptionHelper::ThrowOnWinapiError(bool isFatal) { const int lastError = GetLastError(); const wstring message = StringUtilities::Format(L"Error calling WINAPI function. Error code: %d.", lastError); if (isFatal) { throw SelectedTextTranslateFatalException(message); } else { throw SelectedTextTranslateException(message); } }
void ExceptionHelper::ThrowOnGdiPlusError(Gdiplus::Status status, bool isFatal) { if(status != Gdiplus::Ok) { const wstring message = StringUtilities::Format(L"Error calling GDI+ function. Status: %d.", status); if (isFatal) { throw SelectedTextTranslateFatalException(message); } else { throw SelectedTextTranslateException(message); } } }
void NativeWindowHolder::Initialize() { WNDCLASSEX windowClass = { 0 }; if(className == nullptr) { throw SelectedTextTranslateFatalException(L"Window class name should be provided."); } if (!GetClassInfoEx(instance, className, &windowClass)) { windowClass.hInstance = instance; windowClass.lpszClassName = className; windowClass.lpfnWndProc = WindowProcedureWrapper; windowClass.cbSize = sizeof(WNDCLASSEX); windowClass.hCursor = LoadCursor(nullptr, IDC_ARROW); windowClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); SpecifyWindowClass(&windowClass); AssertCriticalWinApiResult(RegisterClassEx(&windowClass)); } }