Added Window::GetStyle()
Useful with external windows Former-commit-id: 62974c8cdfb6919bc1e85507cc8adc8101daba1a
This commit is contained in:
parent
961c658ae1
commit
7908839785
|
|
@ -56,6 +56,7 @@ class NAZARA_API NzWindow : NzNonCopyable
|
|||
unsigned int GetHeight() const;
|
||||
NzVector2i GetPosition() const;
|
||||
NzVector2ui GetSize() const;
|
||||
nzUInt32 GetStyle() const;
|
||||
NzString GetTitle() const;
|
||||
unsigned int GetWidth() const;
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
#define GWL_USERDATA GWLP_USERDATA
|
||||
#endif
|
||||
|
||||
// N'est pas définit avec MinGW apparemment
|
||||
// N'est pas définit avec MinGW
|
||||
#ifndef MAPVK_VK_TO_VSC
|
||||
#define MAPVK_VK_TO_VSC 0
|
||||
#endif
|
||||
|
|
@ -43,6 +43,7 @@ NzWindowImpl::NzWindowImpl(NzWindow* parent) :
|
|||
m_cursor(nullptr),
|
||||
m_handle(nullptr),
|
||||
m_callback(0),
|
||||
m_style(0),
|
||||
m_maxSize(-1),
|
||||
m_minSize(-1),
|
||||
m_parent(parent),
|
||||
|
|
@ -148,24 +149,27 @@ bool NzWindowImpl::Create(NzVideoMode mode, const NzString& title, nzUInt32 styl
|
|||
#if !NAZARA_UTILITY_THREADED_WINDOW
|
||||
m_sizemove = false;
|
||||
#endif
|
||||
m_style = style;
|
||||
|
||||
return m_handle != nullptr;
|
||||
}
|
||||
|
||||
bool NzWindowImpl::Create(NzWindowHandle handle)
|
||||
{
|
||||
if (!handle)
|
||||
m_handle = reinterpret_cast<HWND>(handle);
|
||||
|
||||
if (!m_handle || !IsWindow(m_handle))
|
||||
{
|
||||
NazaraError("Invalid handle");
|
||||
return false;
|
||||
}
|
||||
|
||||
m_handle = reinterpret_cast<HWND>(handle);
|
||||
m_eventListener = false;
|
||||
m_ownsWindow = false;
|
||||
#if !NAZARA_UTILITY_THREADED_WINDOW
|
||||
m_sizemove = false;
|
||||
#endif
|
||||
m_style = RetrieveStyle(m_handle);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -228,6 +232,11 @@ NzVector2ui NzWindowImpl::GetSize() const
|
|||
return NzVector2ui(rect.right-rect.left, rect.bottom-rect.top);
|
||||
}
|
||||
|
||||
nzUInt32 NzWindowImpl::GetStyle() const
|
||||
{
|
||||
return m_style;
|
||||
}
|
||||
|
||||
NzString NzWindowImpl::GetTitle() const
|
||||
{
|
||||
unsigned int titleSize = GetWindowTextLengthW(m_handle);
|
||||
|
|
@ -570,7 +579,6 @@ bool NzWindowImpl::HandleMessage(HWND window, UINT message, WPARAM wParam, LPARA
|
|||
m_parent->PushEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
case WM_KEYDOWN:
|
||||
|
|
@ -985,28 +993,6 @@ void NzWindowImpl::Uninitialize()
|
|||
UnregisterClassW(className, GetModuleHandle(nullptr));
|
||||
}
|
||||
|
||||
LRESULT CALLBACK NzWindowImpl::MessageHandler(HWND window, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
NzWindowImpl* me;
|
||||
if (message == WM_CREATE)
|
||||
{
|
||||
me = reinterpret_cast<NzWindowImpl*>(reinterpret_cast<CREATESTRUCT*>(lParam)->lpCreateParams);
|
||||
SetWindowLongPtr(window, GWL_USERDATA, reinterpret_cast<LONG_PTR>(me));
|
||||
}
|
||||
else
|
||||
me = reinterpret_cast<NzWindowImpl*>(GetWindowLongPtr(window, GWL_USERDATA));
|
||||
|
||||
if (me)
|
||||
{
|
||||
if (me->HandleMessage(window, message, wParam, lParam))
|
||||
return 0;
|
||||
else if (me->m_callback)
|
||||
return CallWindowProcW(reinterpret_cast<WNDPROC>(me->m_callback), window, message, wParam, lParam);
|
||||
}
|
||||
|
||||
return DefWindowProcW(window, message, wParam, lParam);
|
||||
}
|
||||
|
||||
NzKeyboard::Key NzWindowImpl::ConvertVirtualKey(WPARAM key, LPARAM flags)
|
||||
{
|
||||
switch (key)
|
||||
|
|
@ -1139,6 +1125,63 @@ NzKeyboard::Key NzWindowImpl::ConvertVirtualKey(WPARAM key, LPARAM flags)
|
|||
}
|
||||
}
|
||||
|
||||
LRESULT CALLBACK NzWindowImpl::MessageHandler(HWND window, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
NzWindowImpl* me;
|
||||
if (message == WM_CREATE)
|
||||
{
|
||||
me = reinterpret_cast<NzWindowImpl*>(reinterpret_cast<CREATESTRUCT*>(lParam)->lpCreateParams);
|
||||
SetWindowLongPtr(window, GWL_USERDATA, reinterpret_cast<LONG_PTR>(me));
|
||||
}
|
||||
else
|
||||
me = reinterpret_cast<NzWindowImpl*>(GetWindowLongPtr(window, GWL_USERDATA));
|
||||
|
||||
if (me)
|
||||
{
|
||||
if (me->HandleMessage(window, message, wParam, lParam))
|
||||
return 0;
|
||||
else if (me->m_callback)
|
||||
return CallWindowProcW(reinterpret_cast<WNDPROC>(me->m_callback), window, message, wParam, lParam);
|
||||
}
|
||||
|
||||
return DefWindowProcW(window, message, wParam, lParam);
|
||||
}
|
||||
|
||||
nzUInt32 NzWindowImpl::RetrieveStyle(HWND handle)
|
||||
{
|
||||
nzUInt32 style = 0;
|
||||
|
||||
LONG_PTR winStyle = GetWindowLongPtr(handle, GWL_STYLE);
|
||||
|
||||
// http://msdn.microsoft.com/en-us/library/windows/desktop/ms632600(v=vs.85).aspx
|
||||
if (winStyle & WS_CAPTION)
|
||||
{
|
||||
style |= nzWindowStyle_Titlebar;
|
||||
if (winStyle & WS_SYSMENU)
|
||||
style |= nzWindowStyle_Closable;
|
||||
|
||||
if (winStyle & WS_MAXIMIZEBOX)
|
||||
style |= nzWindowStyle_Resizable;
|
||||
}
|
||||
|
||||
if (winStyle & WS_SIZEBOX)
|
||||
style |= nzWindowStyle_Resizable;
|
||||
|
||||
// Pour déterminer si la fenêtre est en plein écran, il suffit de vérifier si elle recouvre l'écran
|
||||
DEVMODE mode;
|
||||
mode.dmSize = sizeof(DEVMODE);
|
||||
EnumDisplaySettings(nullptr, ENUM_CURRENT_SETTINGS, &mode);
|
||||
|
||||
RECT rect;
|
||||
if (GetWindowRect(handle, &rect))
|
||||
{
|
||||
if (static_cast<DWORD>(rect.right-rect.left) == mode.dmPelsWidth && static_cast<DWORD>(rect.bottom-rect.top) == mode.dmPelsHeight)
|
||||
style |= nzWindowStyle_Fullscreen;
|
||||
}
|
||||
|
||||
return style;
|
||||
}
|
||||
|
||||
#if NAZARA_UTILITY_THREADED_WINDOW
|
||||
void NzWindowImpl::WindowThread(HWND* handle, DWORD styleEx, const wchar_t* title, DWORD style, unsigned int x, unsigned int y, unsigned int width, unsigned int height, NzWindowImpl* window, NzMutex* mutex, NzConditionVariable* condition)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@ class NzWindowImpl : NzNonCopyable
|
|||
unsigned int GetHeight() const;
|
||||
NzVector2i GetPosition() const;
|
||||
NzVector2ui GetSize() const;
|
||||
nzUInt32 GetStyle() const;
|
||||
NzString GetTitle() const;
|
||||
unsigned int GetWidth() const;
|
||||
|
||||
|
|
@ -77,8 +78,9 @@ class NzWindowImpl : NzNonCopyable
|
|||
private:
|
||||
bool HandleMessage(HWND window, UINT message, WPARAM wParam, LPARAM lParam);
|
||||
|
||||
static LRESULT CALLBACK MessageHandler(HWND window, UINT message, WPARAM wParam, LPARAM lParam);
|
||||
static NzKeyboard::Key ConvertVirtualKey(WPARAM key, LPARAM flags);
|
||||
static LRESULT CALLBACK MessageHandler(HWND window, UINT message, WPARAM wParam, LPARAM lParam);
|
||||
static nzUInt32 RetrieveStyle(HWND window);
|
||||
#if NAZARA_UTILITY_THREADED_WINDOW
|
||||
static void WindowThread(HWND* handle, DWORD styleEx, const wchar_t* title, DWORD style, unsigned int x, unsigned int y, unsigned int width, unsigned int height, NzWindowImpl* window, NzMutex* mutex, NzConditionVariable* condition);
|
||||
#endif
|
||||
|
|
@ -86,6 +88,7 @@ class NzWindowImpl : NzNonCopyable
|
|||
HCURSOR m_cursor;
|
||||
HWND m_handle;
|
||||
LONG_PTR m_callback;
|
||||
nzUInt32 m_style;
|
||||
NzVector2i m_maxSize;
|
||||
NzVector2i m_minSize;
|
||||
NzVector2i m_mousePos;
|
||||
|
|
|
|||
|
|
@ -276,6 +276,19 @@ NzVector2ui NzWindow::GetSize() const
|
|||
return m_impl->GetSize();
|
||||
}
|
||||
|
||||
nzUInt32 NzWindow::GetStyle() const
|
||||
{
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (!m_impl)
|
||||
{
|
||||
NazaraError("Window not created");
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_impl->GetStyle();
|
||||
}
|
||||
|
||||
NzString NzWindow::GetTitle() const
|
||||
{
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
|
|
|
|||
Loading…
Reference in New Issue