Browse Source

Platform: avoid registering WNDCLASS more than once.

Fixes an issue when creating the context more than once in a single
application. Also changed the API calls to be explicitly "W" and added
proper error reporting to this part of code.
pull/162/merge
mdietsch 10 years ago committed by Vladimír Vondruš
parent
commit
78ddfad543
  1. 35
      src/Magnum/Platform/WindowlessWglApplication.cpp

35
src/Magnum/Platform/WindowlessWglApplication.cpp

@ -46,20 +46,29 @@
namespace Magnum { namespace Platform {
WindowlessWglContext::WindowlessWglContext(const Configuration& configuration, Context* const magnumContext) {
/* Register the window class (if not yet done) */
WNDCLASSW wc;
if(!GetClassInfoW(GetModuleHandleW(nullptr), L"Magnum Windowless Application", &wc)) {
wc = WNDCLASSW{
0,
DefWindowProcW,
0,
0,
GetModuleHandleW(nullptr),
nullptr,
nullptr,
HBRUSH(COLOR_BACKGROUND),
nullptr,
L"Magnum Windowless Application"
};
if(!RegisterClassW(&wc)) {
Error() << "Platform::WindowlessWglContext: cannot create window class:" << GetLastError();
return;
}
}
/* Create the window */
const WNDCLASS wc{
0,
DefWindowProc,
0,
0,
GetModuleHandle(nullptr),
nullptr,
nullptr,
HBRUSH(COLOR_BACKGROUND),
nullptr,
L"Magnum Windowless Application"
};
if(!RegisterClass(&wc)) return;
_window = CreateWindowW(wc.lpszClassName, L"Magnum Windowless Application",
WS_OVERLAPPEDWINDOW, 0, 0, 32, 32, 0, 0, wc.hInstance, 0);

Loading…
Cancel
Save