Skip to content

Commit

Permalink
Implement feature to remember width and height of UIForETW Dialog
Browse files Browse the repository at this point in the history
This implements the requested feature to persist the window width and height to the app settings and respect it at launch.
  • Loading branch information
chrdavis committed Jan 19, 2019
1 parent df8ca8a commit 1339ade
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ Kristof Mattei
Alexander Riccio
Bradley Grainger
Michael Winterberg
Suresh Kumar Ponnusamy
Suresh Kumar Ponnusamy
Chris Davis
2 changes: 1 addition & 1 deletion UIforETW/ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ Most important tasks:
- [ ] Handle the duplicate copies of etwproviders.man.
- [ ] Add some unit tests.
- [ ] Translate the error codes on starting tracing into English, and give advice.
- [ ] Remember window height
- [X] Remember window height

To-do eventually:
- [ ] Should have the option to run arbitrary scripts after each trace is recorded.
Expand Down
2 changes: 2 additions & 0 deletions UIforETW/Support.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ void CUIforETWDlg::TransferSettings(bool saving)
// settings, to avoid privacy problems.
{ L"InputTracing", reinterpret_cast<int*>(&InputTracing_), kKeyLoggerOff, kKeyLoggerAnonymized },
{ L"TracingMode", reinterpret_cast<int*>(&tracingMode_), kTracingToMemory, kHeapTracingToFile },
{ L"PreviousWidth", &previousWidth_, minWidth_, maxWidth_ },
{ L"PreviousHeight", &previousHeight_, minHeight_, maxHeight_ },
};

for (auto& m : ints)
Expand Down
17 changes: 17 additions & 0 deletions UIforETW/UIforETWDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,17 @@ BOOL CUIforETWDlg::OnInitDialog()
initialWidth_ = lastWidth_ = windowRect.Width();
initialHeight_ = lastHeight_ = windowRect.Height();

// Ensure previousWidth_ and previousHeight_ are valid
if (previousWidth_ < initialWidth_)
{
previousWidth_ = initialWidth_;
}

if (previousHeight_ < initialHeight_)
{
previousHeight_ = initialHeight_;
}

// Win+Ctrl+R is used to trigger recording of traces. This is compatible with
// wprui. If this is changed then be sure to change the text on *both* buttons
// in the main window.
Expand Down Expand Up @@ -689,6 +700,10 @@ BOOL CUIforETWDlg::OnInitDialog()
if (bVersionChecks_)
versionCheckerThread_.StartVersionCheckerThread(this);

const UINT flags = SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER | SWP_NOACTIVATE;
// Resize our window per the previous dimensions if we have them
SetWindowPos(nullptr, 0, 0, previousWidth_, previousHeight_, flags);

return TRUE; // return TRUE unless you set the focus to a control
}

Expand Down Expand Up @@ -1734,8 +1749,10 @@ void CUIforETWDlg::OnSize(UINT nType, int /*cx*/, int /*cy*/)
GetWindowRect(&windowRect);
const int xDelta = windowRect.Width() - lastWidth_;
lastWidth_ += xDelta;
previousWidth_ = lastWidth_;
const int yDelta = windowRect.Height() - lastHeight_;
lastHeight_ += yDelta;
previousHeight_ = lastHeight_;

const UINT flags = SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER | SWP_NOACTIVATE;

Expand Down
7 changes: 7 additions & 0 deletions UIforETW/UIforETWDlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,13 @@ class CUIforETWDlg : public CDialog
int initialHeight_ = 0;
int lastWidth_ = 0;
int lastHeight_ = 0;
const int minWidth_ = 870;
const int minHeight_ = 398;
const int maxWidth_ = 3000;
const int maxHeight_ = 3000;
// Width and height persisted to settings
int previousWidth_ = 0;
int previousHeight_ = 0;

void SetSymbolPath();
// Call this to retrieve a directory from an environment variable, or use
Expand Down

0 comments on commit 1339ade

Please sign in to comment.