diff --git a/source/gui/detail/bedrock_windows.cpp b/source/gui/detail/bedrock_windows.cpp index d05a6119..58044bb9 100644 --- a/source/gui/detail/bedrock_windows.cpp +++ b/source/gui/detail/bedrock_windows.cpp @@ -173,15 +173,22 @@ namespace detail static LRESULT WINAPI Bedrock_WIN32_WindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam); + HINSTANCE windows_module_handle() + { + MEMORY_BASIC_INFORMATION mbi; + static int dummy; + VirtualQuery(&dummy, &mbi, sizeof(mbi)); + return reinterpret_cast(mbi.AllocationBase); + } + bedrock::bedrock() : pi_data_(new pi_data), impl_(new private_impl) { nana::detail::platform_spec::instance(); //to guaranty the platform_spec object is initialized before using. - WNDCLASSEX wincl; - wincl.hInstance = ::GetModuleHandle(0); + wincl.hInstance = windows_module_handle(); wincl.lpszClassName = L"NanaWindowInternal"; wincl.lpfnWndProc = &Bedrock_WIN32_WindowProc; wincl.style = CS_DBLCLKS | CS_OWNDC; @@ -229,6 +236,8 @@ namespace detail delete impl_; delete pi_data_; + + ::UnregisterClass(L"NanaWindowInternal", windows_module_handle()); } diff --git a/source/gui/detail/native_window_interface.cpp b/source/gui/detail/native_window_interface.cpp index efe49d21..54404ceb 100644 --- a/source/gui/detail/native_window_interface.cpp +++ b/source/gui/detail/native_window_interface.cpp @@ -34,6 +34,10 @@ namespace nana{ namespace detail{ #if defined(NANA_WINDOWS) + + //This function is defined in bedrock_windows.cpp + HINSTANCE windows_module_handle(); + class tray_manager { struct window_extra_t @@ -315,7 +319,7 @@ namespace nana{ HWND native_wd = ::CreateWindowEx(style_ex, L"NanaWindowInternal", L"Nana Window", style, pt.x, pt.y, 100, 100, - reinterpret_cast(owner), 0, ::GetModuleHandle(0), 0); + reinterpret_cast(owner), 0, windows_module_handle(), 0); //A window may have a border, this should be adjusted the client area fit for the specified size. ::RECT client; @@ -504,7 +508,7 @@ namespace nana{ WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_CLIPSIBLINGS, r.x, r.y, r.width, r.height, reinterpret_cast(parent), // The window is a child-window to desktop - 0, ::GetModuleHandle(0), 0); + 0, windows_module_handle(), 0); #elif defined(NANA_X11) nana::detail::platform_scope_guard psg;