Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
robmikh committed Sep 20, 2020
1 parent fae9967 commit 789cc01
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 51 deletions.
86 changes: 43 additions & 43 deletions Win32CaptureSample/SampleWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,19 @@ LRESULT SampleWindow::MessageHandler(UINT const message, WPARAM const wparam, LP
case CBN_SELCHANGE:
{
auto index = SendMessageW(hwnd, CB_GETCURSEL, 0, 0);
if (hwnd == m_windowComboBoxHwnd)
if (hwnd == m_windowComboBox)
{
auto window = m_windows->GetCurrentWindows()[index];
auto item = m_app->StartCaptureFromWindowHandle(window.WindowHandle);
OnCaptureStarted(item, CaptureType::ProgrammaticWindow);
}
else if (hwnd == m_monitorComboBoxHwnd)
else if (hwnd == m_monitorComboBox)
{
auto monitor = m_monitors->GetCurrentMonitors()[index];
auto item = m_app->StartCaptureFromMonitorHandle(monitor.MonitorHandle);
OnCaptureStarted(item, CaptureType::ProgrammaticMonitor);
}
else if (hwnd == m_pixelFormatComboBoxHwnd)
else if (hwnd == m_pixelFormatComboBox)
{
auto pixelFormatData = m_pixelFormats[index];
m_app->PixelFormat(pixelFormatData.PixelFormat);
Expand All @@ -96,26 +96,26 @@ LRESULT SampleWindow::MessageHandler(UINT const message, WPARAM const wparam, LP
break;
case BN_CLICKED:
{
if (hwnd == m_pickerButtonHwnd)
if (hwnd == m_pickerButton)
{
OnPickerButtonClicked();
}
else if (hwnd == m_stopButtonHwnd)
else if (hwnd == m_stopButton)
{
StopCapture();
}
else if (hwnd == m_snapshotButtonHwnd)
else if (hwnd == m_snapshotButton)
{
OnSnapshotButtonClicked();
}
else if (hwnd == m_cursorCheckBoxHwnd)
else if (hwnd == m_cursorCheckBox)
{
auto value = SendMessageW(m_cursorCheckBoxHwnd, BM_GETCHECK, 0, 0) == BST_CHECKED;
auto value = SendMessageW(m_cursorCheckBox, BM_GETCHECK, 0, 0) == BST_CHECKED;
m_app->IsCursorEnabled(value);
}
else if (hwnd == m_captureExcludeCheckBoxHwnd)
else if (hwnd == m_captureExcludeCheckBox)
{
auto value = SendMessageW(m_captureExcludeCheckBoxHwnd, BM_GETCHECK, 0, 0) == BST_CHECKED;
auto value = SendMessageW(m_captureExcludeCheckBox, BM_GETCHECK, 0, 0) == BST_CHECKED;
winrt::check_bool(SetWindowDisplayAffinity(m_window, value ? WDA_EXCLUDEFROMCAPTURE : WDA_NONE));
}
}
Expand Down Expand Up @@ -151,19 +151,19 @@ void SampleWindow::OnCaptureStarted(winrt::GraphicsCaptureItem const& item, Capt
switch (captureType)
{
case CaptureType::ProgrammaticWindow:
SendMessageW(m_monitorComboBoxHwnd, CB_SETCURSEL, -1, 0);
SendMessageW(m_monitorComboBox, CB_SETCURSEL, -1, 0);
break;
case CaptureType::ProgrammaticMonitor:
SendMessageW(m_windowComboBoxHwnd, CB_SETCURSEL, -1, 0);
SendMessageW(m_windowComboBox, CB_SETCURSEL, -1, 0);
break;
case CaptureType::Picker:
SendMessageW(m_windowComboBoxHwnd, CB_SETCURSEL, -1, 0);
SendMessageW(m_monitorComboBoxHwnd, CB_SETCURSEL, -1, 0);
SendMessageW(m_windowComboBox, CB_SETCURSEL, -1, 0);
SendMessageW(m_monitorComboBox, CB_SETCURSEL, -1, 0);
break;
}
SendMessageW(m_cursorCheckBoxHwnd, BM_SETCHECK, BST_CHECKED, 0);
EnableWindow(m_stopButtonHwnd, true);
EnableWindow(m_snapshotButtonHwnd, true);
SendMessageW(m_cursorCheckBox, BM_SETCHECK, BST_CHECKED, 0);
EnableWindow(m_stopButton, true);
EnableWindow(m_snapshotButton, true);
}

winrt::fire_and_forget SampleWindow::OnPickerButtonClicked()
Expand Down Expand Up @@ -204,32 +204,32 @@ void SampleWindow::CreateControls(HINSTANCE instance)
auto windowLabel = controls.CreateControl(ControlType::Label, L"Windows:");

// Create window combo box
HWND windowComboBoxHwnd = controls.CreateControl(ControlType::ComboBox, L"", win32ProgrammaticStyle);
auto windowComboBox = controls.CreateControl(ControlType::ComboBox, L"", win32ProgrammaticStyle);

// Populate window combo box and register for updates
m_windows->RegisterComboBoxForUpdates(windowComboBoxHwnd);
m_windows->RegisterComboBoxForUpdates(windowComboBox);

auto monitorLabel = controls.CreateControl(ControlType::Label, L"Displays:");

// Create monitor combo box
HWND monitorComboBoxHwnd = controls.CreateControl(ControlType::ComboBox, L"", win32ProgrammaticStyle);
auto monitorComboBox = controls.CreateControl(ControlType::ComboBox, L"", win32ProgrammaticStyle);

// Populate monitor combo box
m_monitors->RegisterComboBoxForUpdates(monitorComboBoxHwnd);
m_monitors->RegisterComboBoxForUpdates(monitorComboBox);

// Create picker button
HWND pickerButtonHwnd = controls.CreateControl(ControlType::Button, L"Open Picker");
auto pickerButton = controls.CreateControl(ControlType::Button, L"Open Picker");

// Create stop capture button
HWND stopButtonHwnd = controls.CreateControl(ControlType::Button, L"Stop Capture", WS_DISABLED);
auto stopButton = controls.CreateControl(ControlType::Button, L"Stop Capture", WS_DISABLED);

// Create independent snapshot button
HWND snapshotButtonHwnd = controls.CreateControl(ControlType::Button, L"Take Snapshot", WS_DISABLED);
auto snapshotButton = controls.CreateControl(ControlType::Button, L"Take Snapshot", WS_DISABLED);

auto pixelFormatLabel = controls.CreateControl(ControlType::Label, L"Pixel Format:");

// Create pixel format combo box
HWND pixelFormatComboBox = controls.CreateControl(ControlType::ComboBox, L"");
auto pixelFormatComboBox = controls.CreateControl(ControlType::ComboBox, L"");

// Populate pixel format combo box
for (auto& pixelFormat : m_pixelFormats)
Expand All @@ -241,29 +241,29 @@ void SampleWindow::CreateControls(HINSTANCE instance)
SendMessageW(pixelFormatComboBox, CB_SETCURSEL, 0, 0);

// Create cursor checkbox
HWND cursorCheckBoxHwnd = controls.CreateControl(ControlType::CheckBox, L"Enable Cursor", cursorEnableStyle);
auto cursorCheckBox = controls.CreateControl(ControlType::CheckBox, L"Enable Cursor", cursorEnableStyle);

// The default state is true for cursor rendering
SendMessageW(cursorCheckBoxHwnd, BM_SETCHECK, BST_CHECKED, 0);
SendMessageW(cursorCheckBox, BM_SETCHECK, BST_CHECKED, 0);

// Create capture exclude checkbox
// NOTE: We don't version check this feature because setting WDA_EXCLUDEFROMCAPTURE is the same as
// setting WDA_MONITOR on older builds of Windows. We're changing the label here to try and
// limit any user confusion.
std::wstring excludeCheckBoxLabel = isWin32CaptureExcludePresent ? L"Exclude this window" : L"Block this window";
HWND captureExcludeCheckBoxHwnd = controls.CreateControl(ControlType::CheckBox, excludeCheckBoxLabel.c_str());
auto captureExcludeCheckBox = controls.CreateControl(ControlType::CheckBox, excludeCheckBoxLabel.c_str());

// The default state is false for capture exclusion
SendMessageW(captureExcludeCheckBoxHwnd, BM_SETCHECK, BST_UNCHECKED, 0);

m_windowComboBoxHwnd = windowComboBoxHwnd;
m_monitorComboBoxHwnd = monitorComboBoxHwnd;
m_pickerButtonHwnd = pickerButtonHwnd;
m_stopButtonHwnd = stopButtonHwnd;
m_snapshotButtonHwnd = snapshotButtonHwnd;
m_cursorCheckBoxHwnd = cursorCheckBoxHwnd;
m_captureExcludeCheckBoxHwnd = captureExcludeCheckBoxHwnd;
m_pixelFormatComboBoxHwnd = pixelFormatComboBox;
SendMessageW(captureExcludeCheckBox, BM_SETCHECK, BST_UNCHECKED, 0);

m_windowComboBox = windowComboBox;
m_monitorComboBox = monitorComboBox;
m_pickerButton = pickerButton;
m_stopButton = stopButton;
m_snapshotButton = snapshotButton;
m_cursorCheckBox = cursorCheckBox;
m_captureExcludeCheckBox = captureExcludeCheckBox;
m_pixelFormatComboBox = pixelFormatComboBox;
}

void SampleWindow::SetSubTitle(std::wstring const& text)
Expand All @@ -280,11 +280,11 @@ void SampleWindow::StopCapture()
{
m_app->StopCapture();
SetSubTitle(L"");
SendMessageW(m_windowComboBoxHwnd, CB_SETCURSEL, -1, 0);
SendMessageW(m_monitorComboBoxHwnd, CB_SETCURSEL, -1, 0);
SendMessageW(m_cursorCheckBoxHwnd, BM_SETCHECK, BST_CHECKED, 0);
EnableWindow(m_stopButtonHwnd, false);
EnableWindow(m_snapshotButtonHwnd, false);
SendMessageW(m_windowComboBox, CB_SETCURSEL, -1, 0);
SendMessageW(m_monitorComboBox, CB_SETCURSEL, -1, 0);
SendMessageW(m_cursorCheckBox, BM_SETCHECK, BST_CHECKED, 0);
EnableWindow(m_stopButton, false);
EnableWindow(m_snapshotButton, false);
}

void SampleWindow::OnCaptureItemClosed(winrt::GraphicsCaptureItem const&, winrt::Windows::Foundation::IInspectable const&)
Expand Down
16 changes: 8 additions & 8 deletions Win32CaptureSample/SampleWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ struct SampleWindow : util::desktop::DesktopWindow<SampleWindow>
CaptureType captureType);

private:
HWND m_windowComboBoxHwnd = nullptr;
HWND m_monitorComboBoxHwnd = nullptr;
HWND m_pickerButtonHwnd = nullptr;
HWND m_stopButtonHwnd = nullptr;
HWND m_snapshotButtonHwnd = nullptr;
HWND m_pixelFormatComboBoxHwnd = nullptr;
HWND m_cursorCheckBoxHwnd = nullptr;
HWND m_captureExcludeCheckBoxHwnd = nullptr;
HWND m_windowComboBox = nullptr;
HWND m_monitorComboBox = nullptr;
HWND m_pickerButton = nullptr;
HWND m_stopButton = nullptr;
HWND m_snapshotButton = nullptr;
HWND m_pixelFormatComboBox = nullptr;
HWND m_cursorCheckBox = nullptr;
HWND m_captureExcludeCheckBox = nullptr;
std::unique_ptr<WindowList> m_windows;
std::unique_ptr<MonitorList> m_monitors;
std::vector<PixelFormatData> m_pixelFormats;
Expand Down

0 comments on commit 789cc01

Please sign in to comment.