Skip to content

Commit

Permalink
don't use WM_SETREDRAW on the main window because that sets the windo…
Browse files Browse the repository at this point in the history
…w hidden, which makes its representation on the taskbar transparent. Instead cloak the window during startup, and only hide some child windows instead.

closes #389
  • Loading branch information
stefankueng committed Oct 12, 2024
1 parent 7a02311 commit eb53fb4
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 16 deletions.
2 changes: 1 addition & 1 deletion ext/sktoolslib
2 changes: 2 additions & 0 deletions src/BowPad.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@
<ClInclude Include="..\ext\sktoolslib\AeroControls.h" />
<ClInclude Include="..\ext\sktoolslib\AeroGlass.h" />
<ClInclude Include="..\ext\sktoolslib\AnimationManager.h" />
<ClInclude Include="..\ext\sktoolslib\AutoCloakWindow.h" />
<ClInclude Include="..\ext\sktoolslib\BaseDialog.h" />
<ClInclude Include="..\ext\sktoolslib\BaseWindow.h" />
<ClInclude Include="..\ext\sktoolslib\ClipboardHelper.h" />
Expand Down Expand Up @@ -470,6 +471,7 @@
<ClCompile Include="..\ext\sktoolslib\AeroControls.cpp" />
<ClCompile Include="..\ext\sktoolslib\AeroGlass.cpp" />
<ClCompile Include="..\ext\sktoolslib\AnimationManager.cpp" />
<ClCompile Include="..\ext\sktoolslib\AutoCloakWindow.cpp" />
<ClCompile Include="..\ext\sktoolslib\BaseDialog.cpp" />
<ClCompile Include="..\ext\sktoolslib\BaseWindow.cpp" />
<ClCompile Include="..\ext\sktoolslib\BrowseFolder.cpp" />
Expand Down
6 changes: 6 additions & 0 deletions src/BowPad.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,9 @@
<ClInclude Include="SciTextReader.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\ext\sktoolslib\AutoCloakWindow.h">
<Filter>sktoolslib</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="stdafx.cpp">
Expand Down Expand Up @@ -743,6 +746,9 @@
<ClCompile Include="CustomLexers\LexAHK.cxx">
<Filter>Lexer</Filter>
</ClCompile>
<ClCompile Include="..\ext\sktoolslib\AutoCloakWindow.cpp">
<Filter>sktoolslib</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="BowPad.rc">
Expand Down
32 changes: 17 additions & 15 deletions src/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "DPIAware.h"
#include "Monitor.h"
#include "ResString.h"
#include "AutoCloakWindow.h"
#include "../ext/tinyexpr/tinyexpr.h"

#include <memory>
Expand Down Expand Up @@ -632,13 +633,9 @@ bool CMainWindow::RegisterAndCreateWindow()
// monitor but that monitor is not connected now).
if (CreateEx(WS_EX_ACCEPTFILES | WS_EX_NOINHERITLAYOUT, WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN, nullptr))
{
CAutoCloakWindow autoCloak(*this);

SetFileTreeWidth(static_cast<int>(CIniSettings::Instance().GetInt64(L"View", L"FileTreeWidth", 200)));
// hide the tab and status bar so they won't show right away when
// restoring the window: those two show a white background until properly painted.
// After restoring and showing the main window, ResizeChildControls() is called
// which will show those controls again.
ShowWindow(m_tabBar, SW_HIDE);
ShowWindow(m_statusBar, SW_HIDE);
std::wstring winPosKey = L"MainWindow_" + GetMonitorSetupHash();
CIniSettings::Instance().RestoreWindowPos(winPosKey.c_str(), *this, 0);
UpdateWindow(*this);
Expand Down Expand Up @@ -1878,11 +1875,7 @@ void CMainWindow::ResizeChildWindows()
{
RECT rect;
GetClientRect(*this, &rect);
// if the main window is not visible (yet) or the UI is blocked,
// then don't resize the child controls.
// as soon as the UI is unblocked, ResizeChildWindows() is called
// again.
if (!IsRectEmpty(&rect) && IsWindowVisible(*this))
if (!IsRectEmpty(&rect) )
{
constexpr UINT flags = SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER | SWP_SHOWWINDOW | SWP_NOCOPYBITS;
constexpr UINT noShowFlags = SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER | SWP_NOCOPYBITS;
Expand All @@ -1900,6 +1893,8 @@ void CMainWindow::ResizeChildWindows()
const int mainWidth = rect.right - rect.left;
const int btnMargin = CDPIAware::Instance().Scale(*this, 2);

OutputDebugString((L"ResizeChildWindows: " + std::to_wstring(treeWidth) + L" " + std::to_wstring(mainWidth) + L"\n").c_str());

HDWP hDwp = BeginDeferWindowPos(7);
DeferWindowPos(hDwp, m_statusBar, nullptr, rect.left, rect.bottom - m_statusBar.GetHeight(), mainWidth, m_statusBar.GetHeight(), flags);
DeferWindowPos(hDwp, m_tabBar, nullptr, treeWidth + rect.left, rect.top + m_ribbonHeight, mainWidth - treeWidth - (3 * (tabBtnWidth + btnMargin)) - btnMargin, rect.bottom - rect.top, flags);
Expand Down Expand Up @@ -2321,7 +2316,7 @@ void CMainWindow::UpdateStatusBar(bool bEverything)
}
else
{
auto text = selByte ? CStringUtils::Format(rsStatusSelectionLong, numberColor, sSelByte.c_str(), numberColor, sSelLine.c_str(), (selTextMarkerCount ? 0x008000 : numberColor), sSelTextMarkerCount.c_str()) : sNoSel;
auto text = selByte ? CStringUtils::Format(rsStatusSelectionLong, numberColor, sSelByte.c_str(), numberColor, sSelLine.c_str(), (selTextMarkerCount ? 0x008000 : numberColor), sSelTextMarkerCount.c_str()) : sNoSel;
auto shortText = selByte ? CStringUtils::Format(rsStatusSelection, numberColor, sSelByte.c_str(), numberColor, sSelLine.c_str(), (selTextMarkerCount ? 0x008000 : numberColor), sSelTextMarkerCount.c_str()) : sNoSel;
m_statusBar.SetPart(STATUSBAR_SEL,
text,
Expand Down Expand Up @@ -4805,10 +4800,16 @@ void CMainWindow::OpenFiles(const std::vector<std::wstring>& paths)

void CMainWindow::BlockAllUIUpdates(bool block)
{
std::vector<HWND> windows = {m_fileTree, m_statusBar};
if (block)
{
if (m_blockCount == 0)
SendMessage(*this, WM_SETREDRAW, FALSE, 0);
{
// don't block the main window, because WM_SETREDRAW with FALSE actually sets the WS_VISIBLE flag to false!
// Which for a main window means that the taskbar representation gets drawn empty.
for (auto window : windows)
SendMessage(window, WM_SETREDRAW, FALSE, 0);
}
FileTreeBlockRefresh(block);
++m_blockCount;
}
Expand All @@ -4819,11 +4820,12 @@ void CMainWindow::BlockAllUIUpdates(bool block)
if (m_blockCount == 0)
{
// unblock
SendMessage(*this, WM_SETREDRAW, TRUE, 0);
for (auto window : windows)
SendMessage(window, WM_SETREDRAW, TRUE, 0);
// force a redraw
RedrawWindow(*this, nullptr, nullptr, RDW_INVALIDATE | RDW_ERASE | RDW_INTERNALPAINT | RDW_ALLCHILDREN | RDW_UPDATENOW);
}
// FileTreeBlockRefresh maintains it's own count.
// FileTreeBlockRefresh maintains its own count.
FileTreeBlockRefresh(block);
if (m_blockCount == 0)
ResizeChildWindows();
Expand Down

0 comments on commit eb53fb4

Please sign in to comment.