Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: is there no API exposed to manipulate the WinUIDesktopWin32WindowClass window size? #2564

Closed
mqudsi opened this issue May 28, 2020 · 9 comments
Labels

Comments

@mqudsi
Copy link

mqudsi commented May 28, 2020

For a C#/Win32 project using XAML Islands to host WinUI 3, there does not seem to be any API that I can find for interacting with the parent window? e.g. without manually obtaining the hWnd and using the native api, it seems that you have access to the "fake" CoreWindow but no access to the actual top-level Window.

For example, with ApplicationView.SetPreferredMinSize and ApplicationView.TryResizeView not working, I wanted to work around it by manually setting the window size. While XamlRoot can be used to get the content size, it can't be used to set it.

@msft-github-bot msft-github-bot added the needs-triage Issue needs to be triaged by the area owners label May 28, 2020
@mdtauk
Copy link
Contributor

mdtauk commented May 28, 2020

There is a Window element, but with Win32 it links to the HWND, and with UWP it links to the CoreWindow.

The future direction and capabilities of Windowing is an ongoing topic, and Win32 enables you to go into the HWND, but UWP doesn't allow this.

@mqudsi
Copy link
Author

mqudsi commented May 28, 2020

Is there an abstraction over the two to set the window size?

@mdtauk
Copy link
Contributor

mdtauk commented May 28, 2020

Is there an abstraction over the two to set the window size?

This is the spec as it is being developed AFAICT
https://github.com/microsoft/microsoft-ui-xaml-specs/blob/Win32/active/Win32/Window_and_Application_API_Spec.md

@mqudsi
Copy link
Author

mqudsi commented May 28, 2020

Thanks. I see it has this

Win32: The Window is created with the default size of the Window specify by the Window Shell.
UWP: Keep the current behavior. To change the size of the CoreWindow in UWP, it’s required to use ApplicationView’s PreferredLaunchViewSize and PreferredLaunchWindowingMode.

I guess I should open an issue there? Because without additional APIs to support the Win32 case, there's a disparity in how much control the two different window modes give the application/developer (and ironically, uwp is giving more control than win32 in this case).

Then again, the entire ApplicationView class is not under the purview of WinUI (it still lives under Windows.UI), so all WinUI would have to do is expose the win32 feature the same way it exposes the UWP feature.

@ranjeshj
Copy link
Contributor

ranjeshj commented Jun 3, 2020

@marb2000 as FYI

@ranjeshj ranjeshj removed the needs-triage Issue needs to be triaged by the area owners label Jun 3, 2020
@marb2000
Copy link
Contributor

marb2000 commented Jun 3, 2020

In Preview 1 there is not an API that allows you to set the window size for Desktop. It's planned for future previews (TBD yet).

If you want to change the Window's size you can use Win32 APIs. For example using the SetWindowPos:

[DllImport("user32.dll", SetLastError = true)]
public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, int uFlags);

Then you can move it using the flag SWP_SHOWWINDOW

int HWND_TOP = 0;
int SWP_SHOWWINDOW = 0x0040;
SetWindowPos(windowHandle, (IntPtr)HWND_TOP, position_x, position_y, window_width, window_height,SWP_SHOWWINDOW);

To get Window Handle you can you use the IWindowNative COM interface that I used in my //Build demo:

Window window = new MainWindow();
WindowWrapper windowWrapper = WindowWrapper.FromAbi(window.ThisPtr);
IntPtr windowHandle = windowWrapper.WindowHandle;

Hope this helps meanwhile.

@mqudsi
Copy link
Author

mqudsi commented Jun 6, 2020

Thanks, @marb2000 both for the future API info and especially for the IWindowNative info. I had already tried to use the native win32 APIs but was unable to figure out how to get the hWnd without digging through the process memory. I thought the abstraction over the two window types was in CLR and not in WinRT/COM, so I was barking up the wrong tree with my approach.

Note that it seems you must first activate the window or else XamlUdk will throw an exception on the call, which is unfortunate because it means that there's a flash of the wrong window size before it gets set correctly.

@oliverw
Copy link

oliverw commented Feb 3, 2023

2023 and still no such feature in sight?

@pratikone
Copy link
Contributor

You may want to explore the new Window.AppWindow api we have released as part of WinAppSDK 1.3 preview. It simplifies a lot of HWND related operations.
API : https://learn.microsoft.com/en-us/windows/windows-app-sdk/api/winrt/microsoft.ui.windowing.appwindow?view=windows-app-sdk-1.1
https://github.com/microsoft/microsoft-ui-xaml/blob/main/specs/appwindow-spec.md is the spec

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants