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. 19
      src/Magnum/Platform/WindowlessWglApplication.cpp

19
src/Magnum/Platform/WindowlessWglApplication.cpp

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

Loading…
Cancel
Save