Skip to content

Commit

Permalink
this is me trying to fix #9443, but turns out that's a much bigger pr…
Browse files Browse the repository at this point in the history
…oblem than I expected.
  • Loading branch information
zadjii-msft committed Jul 27, 2021
1 parent 335f69e commit 1644a22
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/cascadia/WindowsTerminal/IslandWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,12 +289,25 @@ void IslandWindow::Initialize()
{
_source = DesktopWindowXamlSource{};

auto originalWndProc{ GetWindowLongPtr(_window.get(), GWLP_WNDPROC) };
originalWndProc;

auto interop = _source.as<IDesktopWindowXamlSourceNative>();
winrt::check_hresult(interop->AttachToWindow(_window.get()));

// stash the child interop handle so we can resize it when the main hwnd is resized
interop->get_WindowHandle(&_interopWindowHandle);

auto islandWndProc{ GetWindowLongPtr(_window.get(), GWLP_WNDPROC) };
islandWndProc;

if (islandWndProc == originalWndProc)
{
auto a = 0;
a++;
a;
}

_rootGrid = winrt::Windows::UI::Xaml::Controls::Grid();
_source.Content(_rootGrid);

Expand Down
52 changes: 52 additions & 0 deletions src/cascadia/WindowsTerminal/NonClientIslandWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,25 @@ void NonClientIslandWindow::Initialize()
// then make sure to update it's visual state to reflect if we're in the
// maximized state on launch.
_titlebar.Loaded([this](auto&&, auto&&) { _OnMaximizeChange(); });

_originalWndProc = GetWindowLongPtr(_window.get(), GWLP_WNDPROC);

// auto newProc = [originalProc](HWND hwnd, UINT wm, WPARAM wParam, LPARAM lParam) -> LRESULT {
// switch (wm)
// {
// case WM_NCHITTEST:
// {
// int a = 0;
// a++;
// a;
// break;
// }
// }

// return reinterpret_cast<WNDPROC>(originalProc)(hwnd, wm, wParam, lParam);
// };
// SetWindowLongPtr(_window.get(), GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(&newProc));
SetWindowLongPtr(_window.get(), GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(&NonClientIslandWindow::_StaticOverrideWndProc));
}

// Method Description:
Expand Down Expand Up @@ -948,3 +967,36 @@ void NonClientIslandWindow::_OpenSystemMenu(const int cursorX, const int cursorY
PostMessage(_window.get(), WM_SYSCOMMAND, ret, 0);
}
}

[[nodiscard]] LRESULT __stdcall NonClientIslandWindow::_StaticOverrideWndProc(HWND const window,
UINT const message,
WPARAM const wparam,
LPARAM const lparam) noexcept
{
WINRT_ASSERT(window);

if (auto nonClientIslandWindow{ reinterpret_cast<NonClientIslandWindow*>(GetWindowLongPtr(window, GWLP_USERDATA)) })
{
return nonClientIslandWindow->_OverrideMessageHandler(message, wparam, lparam);
}

return DefWindowProc(window, message, wparam, lparam);
}

LRESULT NonClientIslandWindow::_OverrideMessageHandler(UINT const message,
WPARAM const wparam,
LPARAM const lparam) noexcept
{
switch (message)
{
case WM_NCHITTEST:
{
int a = 0;
a++;
a;
break;
}
}

return reinterpret_cast<WNDPROC>(_originalWndProc)(_window.get(), message, wparam, lparam);
}
4 changes: 4 additions & 0 deletions src/cascadia/WindowsTerminal/NonClientIslandWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ class NonClientIslandWindow : public IslandWindow
[[nodiscard]] static LRESULT __stdcall _StaticInputSinkWndProc(HWND const window, UINT const message, WPARAM const wparam, LPARAM const lparam) noexcept;
[[nodiscard]] LRESULT _InputSinkMessageHandler(UINT const message, WPARAM const wparam, LPARAM const lparam) noexcept;

LONG_PTR _originalWndProc{ 0 };
[[nodiscard]] static LRESULT __stdcall _StaticOverrideWndProc(HWND const window, UINT const message, WPARAM const wparam, LPARAM const lparam) noexcept;
[[nodiscard]] LRESULT _OverrideMessageHandler(UINT const message, WPARAM const wparam, LPARAM const lparam) noexcept;

void _ResizeDragBarWindow() noexcept;

int _GetResizeHandleHeight() const noexcept;
Expand Down

0 comments on commit 1644a22

Please sign in to comment.