Skip to content

Commit

Permalink
Changed ShowWindow to ShowWindowAsync to reduce the chance of blokcin…
Browse files Browse the repository at this point in the history
…g for non-responsive windows.
  • Loading branch information
BeneficialCode committed Feb 29, 2024
1 parent 4b7bff4 commit 7c96b2d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
25 changes: 18 additions & 7 deletions WinArk/WindowsView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ void CWindowsView::InitTree() {
if (!hDesktop)
return;

m_SelectedHwnd.Attach(hDesktop);
CWaitCursor wait;

m_Tree.LockWindowUpdate(TRUE);
Expand All @@ -201,14 +200,15 @@ void CWindowsView::InitTree() {
m_Deleting = false;

m_DesktopNode = AddNode(hDesktop, TVI_ROOT);

::EnumWindows([](auto hWnd, auto lp)->BOOL {
auto pThis = (CWindowsView*)lp;
pThis->AddNode(hWnd, pThis->m_DesktopNode);
return TRUE;
}, reinterpret_cast<LPARAM>(this));

m_DesktopNode.Expand(TVE_EXPAND);
m_Tree.LockWindowUpdate(FALSE);

m_DesktopNode.Select();
m_DesktopNode.EnsureVisible();
m_Tree.SetScrollPos(SB_HORZ, 0);
Expand Down Expand Up @@ -485,33 +485,44 @@ LRESULT CWindowsView::OnNodeSelected(int, LPNMHDR, BOOL&) {

LRESULT CWindowsView::OnWindowShow(WORD, WORD, HWND, BOOL&) {
ATLASSERT(m_Selected);
m_SelectedHwnd.ShowWindow(SW_SHOW);
if (m_SelectedHwnd)
m_SelectedHwnd.ShowWindowAsync(SW_SHOW);

return 0;
}

LRESULT CWindowsView::OnWindowHide(WORD, WORD, HWND, BOOL&) {
ATLASSERT(m_Selected);
m_SelectedHwnd.ShowWindow(SW_HIDE);
if (m_SelectedHwnd)
m_SelectedHwnd.ShowWindowAsync(SW_HIDE);
return 0;
}

LRESULT CWindowsView::OnWindowClose(WORD, WORD, HWND, BOOL&) {
if (m_SelectedHwnd)
m_SelectedHwnd.ShowWindowAsync(WM_CLOSE);
return 0;
}

LRESULT CWindowsView::OnWindowMinimize(WORD, WORD, HWND, BOOL&) {
ATLASSERT(m_Selected);
m_SelectedHwnd.ShowWindow(SW_MINIMIZE);
if(m_SelectedHwnd)
m_SelectedHwnd.ShowWindowAsync(SW_MINIMIZE);
return 0;
}

LRESULT CWindowsView::OnWindowMaximize(WORD, WORD, HWND, BOOL&) {
ATLASSERT(m_Selected);
m_SelectedHwnd.ShowWindow(SW_MAXIMIZE);
if(m_SelectedHwnd)
m_SelectedHwnd.ShowWindowAsync(SW_MAXIMIZE);

return 0;
}

LRESULT CWindowsView::OnWindowRestore(WORD, WORD, HWND, BOOL&) {
ATLASSERT(m_Selected);
m_SelectedHwnd.ShowWindow(SW_RESTORE);
if(m_SelectedHwnd)
m_SelectedHwnd.ShowWindowAsync(SW_RESTORE);
return 0;
}

Expand Down
3 changes: 2 additions & 1 deletion WinArk/WindowsView.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class CWindowsView :
COMMAND_ID_HANDLER(ID_WINDOW_MAXIMIZE, OnWindowMaximize)
COMMAND_ID_HANDLER(ID_STATE_FLASH, OnWindowFlash)
COMMAND_ID_HANDLER(ID_WINDOW_RESTORE, OnWindowRestore)
COMMAND_ID_HANDLER(ID_WINDOW_CLOSE,OnWindowClose)
/*COMMAND_ID_HANDLER(ID_VIEW_HIDDENWINDOWS, OnToggleHiddenWindows)
COMMAND_ID_HANDLER(ID_VIEW_EMPTYTITLEWINDOWS, OnToggleEmptyTitleWindows)
COMMAND_ID_HANDLER(ID_VIEW_CHILDWINDOWS, OnToggleChildWindows)*/
Expand Down Expand Up @@ -95,7 +96,7 @@ class CWindowsView :
LRESULT OnWindowMinimize(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
LRESULT OnWindowMaximize(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
LRESULT OnWindowRestore(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);

LRESULT OnWindowClose(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
LRESULT OnRefresh(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
//LRESULT OnToggleHiddenWindows(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
//LRESULT OnToggleEmptyTitleWindows(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
Expand Down

0 comments on commit 7c96b2d

Please sign in to comment.