From ae56fea1969a3b9c12bfefaba42b7245215ed360 Mon Sep 17 00:00:00 2001 From: Vincent Wei Date: Fri, 6 Mar 2020 17:43:10 +0800 Subject: [PATCH] tune IncludeWindowStyle, ExcludeWindowStyle, IncludeExWindowStyle, and ExcludeWindowExStyle to not allow change the system styles --- include/window.h | 16 ++++++++++++++++ src/gui/window.c | 36 ++++++++++++++++++++++++++++-------- 2 files changed, 44 insertions(+), 8 deletions(-) diff --git a/include/window.h b/include/window.h index 37ef1158..9d70707b 100644 --- a/include/window.h +++ b/include/window.h @@ -7648,8 +7648,12 @@ MG_EXPORT DWORD GUIAPI GetWindowExStyle (HWND hWnd); * This function removes the specific style of the window * specified by \a hWnd. * + * Since 5.0.0, only the customizable window styles (bits in WS_CTRLMASK) + * can be changed by calling this function. + * * \param hWnd The handle to the window. * \param dwStyle The specific style which will be removed. + * * \return TRUE on success, otherwise FALSE. * * \sa ExcludeWindowStyle @@ -7663,6 +7667,9 @@ MG_EXPORT BOOL GUIAPI ExcludeWindowStyle (HWND hWnd, DWORD dwStyle); * This function includes the specific style of the window * specified by \a hWnd. * + * Since 5.0.0, only the customizable window styles (bits in WS_CTRLMASK) + * can be changed by calling this function. + * * \param hWnd The handle to the window. * \param dwStyle The specific style which will be included. * \return TRUE on success, otherwise FALSE. @@ -7678,6 +7685,10 @@ MG_EXPORT BOOL GUIAPI IncludeWindowStyle (HWND hWnd, DWORD dwStyle); * This function removes the specific extended style of the window * specified by \a hWnd. * + * Since 5.0.0, only the customizable window extended styles (bits in + * WS_EX_CONTROL_MASK | WS_EX_CONTROL_MASK) can be changed by calling + * this function. + * * \param hWnd The handle to the window. * \param dwStyle The specific extended style which will be removed. * \return TRUE on success, otherwise FALSE. @@ -7693,8 +7704,13 @@ MG_EXPORT BOOL GUIAPI ExcludeWindowExStyle (HWND hWnd, DWORD dwStyle); * This function includes the specific extended style of the window * specified by \a hWnd. * + * Since 5.0.0, only the customizable window extended styles (bits in + * WS_EX_CONTROL_MASK | WS_EX_CONTROL_MASK) can be changed by calling + * this function. + * * \param hWnd The handle to the window. * \param dwStyle The specific extended style which will be included. + * * \return TRUE on success, otherwise FALSE. * * \sa IncludeWindowStyle diff --git a/src/gui/window.c b/src/gui/window.c index 2649c2b7..788ecd95 100644 --- a/src/gui/window.c +++ b/src/gui/window.c @@ -4989,8 +4989,13 @@ BOOL GUIAPI ExcludeWindowStyle (HWND hWnd, DWORD dwStyle) MG_CHECK_RET (MG_IS_NORMAL_WINDOW(hWnd), FALSE); pWin = MG_GET_WINDOW_PTR (hWnd); - pWin->dwStyle &= ~dwStyle; - return TRUE; + dwStyle &= WS_CTRLMASK; + if (dwStyle) { + pWin->dwStyle &= ~dwStyle; + return TRUE; + } + + return FALSE; } BOOL GUIAPI IncludeWindowStyle (HWND hWnd, DWORD dwStyle) @@ -5000,8 +5005,13 @@ BOOL GUIAPI IncludeWindowStyle (HWND hWnd, DWORD dwStyle) MG_CHECK_RET (MG_IS_NORMAL_WINDOW(hWnd), FALSE); pWin = MG_GET_WINDOW_PTR (hWnd); - pWin->dwStyle |= dwStyle; - return TRUE; + dwStyle &= WS_CTRLMASK; + if (dwStyle) { + pWin->dwStyle |= dwStyle; + return TRUE; + } + + return FALSE; } DWORD GUIAPI GetWindowExStyle (HWND hWnd) @@ -5021,8 +5031,13 @@ BOOL GUIAPI ExcludeWindowExStyle (HWND hWnd, DWORD dwStyle) MG_CHECK_RET (MG_IS_NORMAL_WINDOW(hWnd), FALSE); pWin = MG_GET_WINDOW_PTR (hWnd); - pWin->dwExStyle &= ~dwStyle; - return TRUE; + dwStyle &= (WS_EX_CONTROL_MASK | WS_EX_CONTROL_MASK); + if (dwStyle) { + pWin->dwExStyle &= ~dwStyle; + return TRUE; + } + + return FALSE; } BOOL GUIAPI IncludeWindowExStyle (HWND hWnd, DWORD dwStyle) @@ -5032,8 +5047,13 @@ BOOL GUIAPI IncludeWindowExStyle (HWND hWnd, DWORD dwStyle) MG_CHECK_RET (MG_IS_NORMAL_WINDOW(hWnd), FALSE); pWin = MG_GET_WINDOW_PTR (hWnd); - pWin->dwExStyle |= dwStyle; - return TRUE; + dwStyle &= (WS_EX_CONTROL_MASK | WS_EX_CONTROL_MASK); + if (dwStyle) { + pWin->dwExStyle |= dwStyle; + return TRUE; + } + + return FALSE; } DWORD GUIAPI GetWindowAdditionalData (HWND hWnd)