- Now retries UpdateLayeredWindow if it fails for some reason. (E.g. when SetLayeredWindowAttributes is called by other application process.)

- Replaced Get(Set)WindowLong with Get(Set)WindowLongPtr.
- Code cosmetics.
This commit is contained in:
spx 2012-03-14 02:52:35 +00:00
parent 476eaf1679
commit 8e4d37a8ea
5 changed files with 67 additions and 60 deletions

View File

@ -67,7 +67,7 @@ INT_PTR CDialog::OnActivate(WPARAM wParam, LPARAM lParam)
void CDialog::SetDialogRTL() void CDialog::SetDialogRTL()
{ {
SetWindowLong(m_Window, GWL_EXSTYLE, GetWindowLong(m_Window, GWL_EXSTYLE) | WS_EX_LAYOUTRTL); SetWindowLongPtr(m_Window, GWL_EXSTYLE, GetWindowLongPtr(m_Window, GWL_EXSTYLE) | WS_EX_LAYOUTRTL);
} }
/* /*

View File

@ -376,7 +376,7 @@ void CDialogManage::CTabSkins::Initialize()
// Get rid of the EDITTEXT control border // Get rid of the EDITTEXT control border
item = GetDlgItem(m_Window, IDC_MANAGESKINS_DESCRIPTION_TEXT); item = GetDlgItem(m_Window, IDC_MANAGESKINS_DESCRIPTION_TEXT);
SetWindowLong(item, GWL_EXSTYLE, GetWindowLong(item, GWL_EXSTYLE) &~ WS_EX_CLIENTEDGE); SetWindowLongPtr(item, GWL_EXSTYLE, GetWindowLongPtr(item, GWL_EXSTYLE) &~ WS_EX_CLIENTEDGE);
SetWindowPos(item, NULL, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER); SetWindowPos(item, NULL, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER);
item = GetDlgItem(m_Window, IDC_MANAGESKINS_DISPLAYMONITOR_BUTTON); item = GetDlgItem(m_Window, IDC_MANAGESKINS_DISPLAYMONITOR_BUTTON);

View File

@ -313,6 +313,24 @@ void CMeterWindow::IgnoreAeroPeek()
} }
} }
void CMeterWindow::AddWindowExStyle(LONG_PTR flag)
{
LONG_PTR style = GetWindowLongPtr(m_Window, GWL_EXSTYLE);
if ((style & flag) == 0)
{
SetWindowLongPtr(m_Window, GWL_EXSTYLE, style | flag);
}
}
void CMeterWindow::RemoveWindowExStyle(LONG_PTR flag)
{
LONG_PTR style = GetWindowLongPtr(m_Window, GWL_EXSTYLE);
if ((style & flag) != 0)
{
SetWindowLongPtr(m_Window, GWL_EXSTYLE, style & ~flag);
}
}
/* /*
** Unloads the skin with delay to avoid crash (and for fade to complete). ** Unloads the skin with delay to avoid crash (and for fade to complete).
** **
@ -400,11 +418,7 @@ void CMeterWindow::Refresh(bool init, bool all)
InitializeMeters(); InitializeMeters();
// Remove transparent flag // Remove transparent flag
LONG style = GetWindowLong(m_Window, GWL_EXSTYLE); RemoveWindowExStyle(WS_EX_TRANSPARENT);
if ((style & WS_EX_TRANSPARENT) != 0)
{
SetWindowLong(m_Window, GWL_EXSTYLE, style & ~WS_EX_TRANSPARENT);
}
m_Hidden = m_WindowStartHidden; m_Hidden = m_WindowStartHidden;
@ -636,7 +650,7 @@ void CMeterWindow::ChangeZPos(ZPOSITION zPos, bool all)
// Find the "backmost" topmost window // Find the "backmost" topmost window
while (winPos = ::GetNextWindow(winPos, GW_HWNDPREV)) while (winPos = ::GetNextWindow(winPos, GW_HWNDPREV))
{ {
if (GetWindowLong(winPos, GWL_EXSTYLE) & WS_EX_TOPMOST) if (GetWindowLongPtr(winPos, GWL_EXSTYLE) & WS_EX_TOPMOST)
{ {
// Insert after the found window // Insert after the found window
if (0 != SetWindowPos(m_Window, winPos, 0, 0, 0, 0, ZPOS_FLAGS)) if (0 != SetWindowPos(m_Window, winPos, 0, 0, 0, 0, ZPOS_FLAGS))
@ -2874,9 +2888,7 @@ void CMeterWindow::UpdateTransparency(int alpha, bool reset)
{ {
if (reset) if (reset)
{ {
// Add the window flag AddWindowExStyle(WS_EX_LAYERED);
LONG style = GetWindowLong(m_Window, GWL_EXSTYLE);
SetWindowLong(m_Window, GWL_EXSTYLE, style | WS_EX_LAYERED);
} }
BLENDFUNCTION blendPixelFunction = {AC_SRC_OVER, 0, alpha, AC_SRC_ALPHA}; BLENDFUNCTION blendPixelFunction = {AC_SRC_OVER, 0, alpha, AC_SRC_ALPHA};
@ -2888,7 +2900,14 @@ void CMeterWindow::UpdateTransparency(int alpha, bool reset)
HDC dcMemory = CreateCompatibleDC(dcScreen); HDC dcMemory = CreateCompatibleDC(dcScreen);
SelectObject(dcMemory, m_DIBSectionBuffer); SelectObject(dcMemory, m_DIBSectionBuffer);
BOOL ret = UpdateLayeredWindow(m_Window, dcScreen, &ptWindowScreenPosition, &szWindow, dcMemory, &ptSrc, 0, &blendPixelFunction, ULW_ALPHA);
if (!ret)
{
// Retry after resetting WS_EX_LAYERED flag
RemoveWindowExStyle(WS_EX_LAYERED);
AddWindowExStyle(WS_EX_LAYERED);
UpdateLayeredWindow(m_Window, dcScreen, &ptWindowScreenPosition, &szWindow, dcMemory, &ptSrc, 0, &blendPixelFunction, ULW_ALPHA); UpdateLayeredWindow(m_Window, dcScreen, &ptWindowScreenPosition, &szWindow, dcMemory, &ptSrc, 0, &blendPixelFunction, ULW_ALPHA);
}
ReleaseDC(0, dcScreen); ReleaseDC(0, dcScreen);
DeleteDC(dcMemory); DeleteDC(dcMemory);
@ -2899,9 +2918,7 @@ void CMeterWindow::UpdateTransparency(int alpha, bool reset)
{ {
if (reset) if (reset)
{ {
// Remove the window flag RemoveWindowExStyle(WS_EX_LAYERED);
LONG style = GetWindowLong(m_Window, GWL_EXSTYLE);
SetWindowLong(m_Window, GWL_EXSTYLE, style & ~WS_EX_LAYERED);
} }
} }
} }
@ -3129,11 +3146,7 @@ void CMeterWindow::ShowWindowIfAppropriate()
if (!inside || keyDown) if (!inside || keyDown)
{ {
// If Alt, shift or control is down, remove the transparent flag // If Alt, shift or control is down, remove the transparent flag
LONG style = GetWindowLong(m_Window, GWL_EXSTYLE); RemoveWindowExStyle(WS_EX_TRANSPARENT);
if ((style & WS_EX_TRANSPARENT) != 0)
{
SetWindowLong(m_Window, GWL_EXSTYLE, style & ~WS_EX_TRANSPARENT);
}
} }
} }
@ -3327,11 +3340,7 @@ LRESULT CMeterWindow::OnMouseMove(UINT uMsg, WPARAM wParam, LPARAM lParam)
{ {
if (m_ClickThrough) if (m_ClickThrough)
{ {
LONG style = GetWindowLong(m_Window, GWL_EXSTYLE); AddWindowExStyle(WS_EX_TRANSPARENT);
if ((style & WS_EX_TRANSPARENT) == 0)
{
SetWindowLong(m_Window, GWL_EXSTYLE, style | WS_EX_TRANSPARENT);
}
} }
if (!m_Hidden) if (!m_Hidden)
@ -3366,8 +3375,8 @@ LRESULT CMeterWindow::OnMouseMove(UINT uMsg, WPARAM wParam, LPARAM lParam)
if (!m_ClickThrough || keyDown) if (!m_ClickThrough || keyDown)
{ {
POINT pos; POINT pos;
pos.x = (SHORT)LOWORD(lParam); pos.x = GET_X_LPARAM(lParam);
pos.y = (SHORT)HIWORD(lParam); pos.y = GET_Y_LPARAM(lParam);
if (uMsg == WM_NCMOUSEMOVE) if (uMsg == WM_NCMOUSEMOVE)
{ {
@ -3599,11 +3608,7 @@ void CMeterWindow::SetClickThrough(bool b)
if (!m_ClickThrough) if (!m_ClickThrough)
{ {
// Remove transparent flag // Remove transparent flag
LONG style = GetWindowLong(m_Window, GWL_EXSTYLE); RemoveWindowExStyle(WS_EX_TRANSPARENT);
if ((style & WS_EX_TRANSPARENT) != 0)
{
SetWindowLong(m_Window, GWL_EXSTYLE, style & ~WS_EX_TRANSPARENT);
}
} }
if (m_MouseOver) if (m_MouseOver)
@ -3775,8 +3780,8 @@ LRESULT CMeterWindow::OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam)
if (m_WindowDraggable && !m_Rainmeter->GetDisableDragging()) if (m_WindowDraggable && !m_Rainmeter->GetDisableDragging())
{ {
POINT pos; POINT pos;
pos.x = (SHORT)LOWORD(lParam); pos.x = GET_X_LPARAM(lParam);
pos.y = (SHORT)HIWORD(lParam); pos.y = GET_Y_LPARAM(lParam);
MapWindowPoints(NULL, m_Window, &pos, 1); MapWindowPoints(NULL, m_Window, &pos, 1);
int x1 = m_DragMargins.left; int x1 = m_DragMargins.left;
@ -4002,8 +4007,8 @@ LRESULT CMeterWindow::OnSettingChange(UINT uMsg, WPARAM wParam, LPARAM lParam)
LRESULT CMeterWindow::OnLeftButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam) LRESULT CMeterWindow::OnLeftButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam)
{ {
POINT pos; POINT pos;
pos.x = (SHORT)LOWORD(lParam); pos.x = GET_X_LPARAM(lParam);
pos.y = (SHORT)HIWORD(lParam); pos.y = GET_Y_LPARAM(lParam);
if (uMsg == WM_NCLBUTTONDOWN) if (uMsg == WM_NCLBUTTONDOWN)
{ {
@ -4034,8 +4039,8 @@ LRESULT CMeterWindow::OnLeftButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam)
LRESULT CMeterWindow::OnLeftButtonUp(UINT uMsg, WPARAM wParam, LPARAM lParam) LRESULT CMeterWindow::OnLeftButtonUp(UINT uMsg, WPARAM wParam, LPARAM lParam)
{ {
POINT pos; POINT pos;
pos.x = (SHORT)LOWORD(lParam); pos.x = GET_X_LPARAM(lParam);
pos.y = (SHORT)HIWORD(lParam); pos.y = GET_Y_LPARAM(lParam);
if (uMsg == WM_NCLBUTTONUP) if (uMsg == WM_NCLBUTTONUP)
{ {
@ -4058,8 +4063,8 @@ LRESULT CMeterWindow::OnLeftButtonUp(UINT uMsg, WPARAM wParam, LPARAM lParam)
LRESULT CMeterWindow::OnLeftButtonDoubleClick(UINT uMsg, WPARAM wParam, LPARAM lParam) LRESULT CMeterWindow::OnLeftButtonDoubleClick(UINT uMsg, WPARAM wParam, LPARAM lParam)
{ {
POINT pos; POINT pos;
pos.x = (SHORT)LOWORD(lParam); pos.x = GET_X_LPARAM(lParam);
pos.y = (SHORT)HIWORD(lParam); pos.y = GET_Y_LPARAM(lParam);
if (uMsg == WM_NCLBUTTONDBLCLK) if (uMsg == WM_NCLBUTTONDBLCLK)
{ {
@ -4085,8 +4090,8 @@ LRESULT CMeterWindow::OnLeftButtonDoubleClick(UINT uMsg, WPARAM wParam, LPARAM l
LRESULT CMeterWindow::OnRightButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam) LRESULT CMeterWindow::OnRightButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam)
{ {
POINT pos; POINT pos;
pos.x = (SHORT)LOWORD(lParam); pos.x = GET_X_LPARAM(lParam);
pos.y = (SHORT)HIWORD(lParam); pos.y = GET_Y_LPARAM(lParam);
if (uMsg == WM_NCRBUTTONDOWN) if (uMsg == WM_NCRBUTTONDOWN)
{ {
@ -4109,8 +4114,8 @@ LRESULT CMeterWindow::OnRightButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam)
LRESULT CMeterWindow::OnRightButtonUp(UINT uMsg, WPARAM wParam, LPARAM lParam) LRESULT CMeterWindow::OnRightButtonUp(UINT uMsg, WPARAM wParam, LPARAM lParam)
{ {
POINT pos; POINT pos;
pos.x = (SHORT)LOWORD(lParam); pos.x = GET_X_LPARAM(lParam);
pos.y = (SHORT)HIWORD(lParam); pos.y = GET_Y_LPARAM(lParam);
// Handle buttons // Handle buttons
HandleButtons(pos, BUTTONPROC_MOVE); HandleButtons(pos, BUTTONPROC_MOVE);
@ -4132,8 +4137,8 @@ LRESULT CMeterWindow::OnRightButtonUp(UINT uMsg, WPARAM wParam, LPARAM lParam)
LRESULT CMeterWindow::OnRightButtonDoubleClick(UINT uMsg, WPARAM wParam, LPARAM lParam) LRESULT CMeterWindow::OnRightButtonDoubleClick(UINT uMsg, WPARAM wParam, LPARAM lParam)
{ {
POINT pos; POINT pos;
pos.x = (SHORT)LOWORD(lParam); pos.x = GET_X_LPARAM(lParam);
pos.y = (SHORT)HIWORD(lParam); pos.y = GET_Y_LPARAM(lParam);
if (uMsg == WM_NCRBUTTONDBLCLK) if (uMsg == WM_NCRBUTTONDBLCLK)
{ {
@ -4159,8 +4164,8 @@ LRESULT CMeterWindow::OnRightButtonDoubleClick(UINT uMsg, WPARAM wParam, LPARAM
LRESULT CMeterWindow::OnMiddleButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam) LRESULT CMeterWindow::OnMiddleButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam)
{ {
POINT pos; POINT pos;
pos.x = (SHORT)LOWORD(lParam); pos.x = GET_X_LPARAM(lParam);
pos.y = (SHORT)HIWORD(lParam); pos.y = GET_Y_LPARAM(lParam);
if (uMsg == WM_NCMBUTTONDOWN) if (uMsg == WM_NCMBUTTONDOWN)
{ {
@ -4183,8 +4188,8 @@ LRESULT CMeterWindow::OnMiddleButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam
LRESULT CMeterWindow::OnMiddleButtonUp(UINT uMsg, WPARAM wParam, LPARAM lParam) LRESULT CMeterWindow::OnMiddleButtonUp(UINT uMsg, WPARAM wParam, LPARAM lParam)
{ {
POINT pos; POINT pos;
pos.x = (SHORT)LOWORD(lParam); pos.x = GET_X_LPARAM(lParam);
pos.y = (SHORT)HIWORD(lParam); pos.y = GET_Y_LPARAM(lParam);
if (uMsg == WM_NCMBUTTONUP) if (uMsg == WM_NCMBUTTONUP)
{ {
@ -4207,8 +4212,8 @@ LRESULT CMeterWindow::OnMiddleButtonUp(UINT uMsg, WPARAM wParam, LPARAM lParam)
LRESULT CMeterWindow::OnMiddleButtonDoubleClick(UINT uMsg, WPARAM wParam, LPARAM lParam) LRESULT CMeterWindow::OnMiddleButtonDoubleClick(UINT uMsg, WPARAM wParam, LPARAM lParam)
{ {
POINT pos; POINT pos;
pos.x = (SHORT)LOWORD(lParam); pos.x = GET_X_LPARAM(lParam);
pos.y = (SHORT)HIWORD(lParam); pos.y = GET_Y_LPARAM(lParam);
if (uMsg == WM_NCMBUTTONDBLCLK) if (uMsg == WM_NCMBUTTONDBLCLK)
{ {
@ -4245,8 +4250,8 @@ LRESULT CMeterWindow::OnContextMenu(UINT uMsg, WPARAM wParam, LPARAM lParam)
} }
else else
{ {
pos.x = (SHORT)LOWORD(lParam); pos.x = GET_X_LPARAM(lParam);
pos.y = (SHORT)HIWORD(lParam); pos.y = GET_Y_LPARAM(lParam);
// Transform the point to client rect // Transform the point to client rect
POINT posc = {pos.x - rect.left, pos.y - rect.top}; POINT posc = {pos.x - rect.left, pos.y - rect.top};
@ -4593,8 +4598,8 @@ LRESULT CMeterWindow::OnMove(UINT uMsg, WPARAM wParam, LPARAM lParam)
// and in parent-client coordinates for child windows. // and in parent-client coordinates for child windows.
// Store the new window position // Store the new window position
m_ScreenX = (SHORT)LOWORD(lParam); m_ScreenX = GET_X_LPARAM(lParam);
m_ScreenY = (SHORT)HIWORD(lParam); m_ScreenY = GET_Y_LPARAM(lParam);
SetWindowPositionVariables(m_ScreenX, m_ScreenY); SetWindowPositionVariables(m_ScreenX, m_ScreenY);

View File

@ -336,6 +336,8 @@ private:
bool DoMoveAction(int x, int y, MOUSE mouse); bool DoMoveAction(int x, int y, MOUSE mouse);
bool ResizeWindow(bool reset); bool ResizeWindow(bool reset);
void IgnoreAeroPeek(); void IgnoreAeroPeek();
void AddWindowExStyle(LONG_PTR flag);
void RemoveWindowExStyle(LONG_PTR flag);
void BlurBehindWindow(BOOL fEnable); void BlurBehindWindow(BOOL fEnable);
void SetWindowPositionVariables(int x, int y); void SetWindowPositionVariables(int x, int y);
void SetWindowSizeVariables(int w, int h); void SetWindowSizeVariables(int w, int h);

View File

@ -814,7 +814,7 @@ void CSystem::PrepareHelperWindow(HWND WorkerW)
HWND hwnd = WorkerW; HWND hwnd = WorkerW;
while (hwnd = ::GetNextWindow(hwnd, GW_HWNDPREV)) while (hwnd = ::GetNextWindow(hwnd, GW_HWNDPREV))
{ {
if (GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST) if (GetWindowLongPtr(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST)
{ {
WCHAR className[64], windowText[64]; WCHAR className[64], windowText[64];
@ -832,7 +832,7 @@ void CSystem::PrepareHelperWindow(HWND WorkerW)
if (logging) if (logging)
{ {
LogWithArgs(LOG_DEBUG, L"System: HelperWindow: hwnd=0x%p (WorkerW=0x%p), hwndInsertAfter=0x%p (\"%s\" %s) - %s", LogWithArgs(LOG_DEBUG, L"System: HelperWindow: hwnd=0x%p (WorkerW=0x%p), hwndInsertAfter=0x%p (\"%s\" %s) - %s",
c_HelperWindow, WorkerW, hwnd, windowText, className, (GetWindowLong(c_HelperWindow, GWL_EXSTYLE) & WS_EX_TOPMOST) ? L"TOPMOST" : L"NORMAL"); c_HelperWindow, WorkerW, hwnd, windowText, className, (GetWindowLongPtr(c_HelperWindow, GWL_EXSTYLE) & WS_EX_TOPMOST) ? L"TOPMOST" : L"NORMAL");
} }
return; return;
} }
@ -849,7 +849,7 @@ void CSystem::PrepareHelperWindow(HWND WorkerW)
if (logging) if (logging)
{ {
LogWithArgs(LOG_DEBUG, L"System: HelperWindow: hwnd=0x%p (WorkerW=0x%p), hwndInsertAfter=HWND_TOPMOST - %s", LogWithArgs(LOG_DEBUG, L"System: HelperWindow: hwnd=0x%p (WorkerW=0x%p), hwndInsertAfter=HWND_TOPMOST - %s",
c_HelperWindow, WorkerW, (GetWindowLong(c_HelperWindow, GWL_EXSTYLE) & WS_EX_TOPMOST) ? L"TOPMOST" : L"NORMAL"); c_HelperWindow, WorkerW, (GetWindowLongPtr(c_HelperWindow, GWL_EXSTYLE) & WS_EX_TOPMOST) ? L"TOPMOST" : L"NORMAL");
} }
} }
else else
@ -860,7 +860,7 @@ void CSystem::PrepareHelperWindow(HWND WorkerW)
if (logging) if (logging)
{ {
LogWithArgs(LOG_DEBUG, L"System: HelperWindow: hwnd=0x%p (WorkerW=0x%p), hwndInsertAfter=HWND_BOTTOM - %s", LogWithArgs(LOG_DEBUG, L"System: HelperWindow: hwnd=0x%p (WorkerW=0x%p), hwndInsertAfter=HWND_BOTTOM - %s",
c_HelperWindow, WorkerW, (GetWindowLong(c_HelperWindow, GWL_EXSTYLE) & WS_EX_TOPMOST) ? L"TOPMOST" : L"NORMAL"); c_HelperWindow, WorkerW, (GetWindowLongPtr(c_HelperWindow, GWL_EXSTYLE) & WS_EX_TOPMOST) ? L"TOPMOST" : L"NORMAL");
} }
} }
} }