question

youki avatar image
0 Votes"
youki asked youki commented

Communication between WinApi and hosted WinUI

Hello,
i have a few question for hosting a WinUI UI as an editor for my WinApi background app.

https://docs.microsoft.com/de-de/windows/apps/desktop/modernize/host-custom-control-with-xaml-islands-cpp

  1. Is there a possibility that I will have problems when I want the XAML UI to communicate with the WinApi part?
    (I want to save/ edit values in the XAML UI in a for i.e. resource file and tell the WinApi part to read the settings from the resource file [or may be a xml])

  2. Only WinUI 2 controls are supported? I will need listviews, dropdown boxes, radio buttons and something like a navigation view [slide menu], i won't have any problems there?




windows-apic++windows-app-sdk
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Castorix31 avatar image
0 Votes"
Castorix31 answered youki commented

XAML Islands for WinUI 3 is not ready yet : 1-under-consideration
(some XAML controls can be embedded like I explained in this thread, but it is just a workaround and not really usable)

You should do the reverse, Win32 APIs in a WinUI 3 app
(as unpackaged WinUI 3 apps are standard Win32 apps, you can do anything a C++/Win32 app can do)
From what you wrote in other threads, you can put it in background (just no window), add a Tray icon with Shell_NotifyIcon, etc...





· 7
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Will it also be possible to free the UI Memory, if the UI is closed and the application stays running in the background (system tray)?

0 Votes 0 ·

I don't see what you mean by "free the UI Memory", because WinUI 3 apps don't use more memory than other Win32 apps
I just checked with Process Explorer, and I did not notice anything particular... (Private Bytes, Working Set, User/GDI objects, Handles,...)

0 Votes 0 ·

How can i add the message loop for handling the xaml window and the context menu?

Is it like before, registering a window class and a new window, so I’m using the message loop of the WinApi window?


Until now i’ve created an unpackaged WinUI application, the context menu and i'm hiding it by "ShowWindow(handle, SW_HIDE)".

0 Votes 0 ·

For Shell_NotifyIcon, you just subclass the window with SetWindowSubclass where you intercept your custom message to display the context menu on WM_CONTEXTMENU or WM_RBUTTONUP

0 Votes 0 ·

Cool,
Works!

0 Votes 0 ·
Show more comments
youki avatar image
0 Votes"
youki answered youki edited

Even if the memory consumption of the UI is very small, wouldn't it still be possible to free up the memory with WinUI as a component?
The UI only serves as an editor and is rarely used (0.000001% of the time).

Forget the following: *> Aha ok, i understand.

I've just seen the message "This UWP process group is suspending processes to improve system performance" in the taskmanager for OneNote. So this is the default behaviour, if you minimize/close the UI in UWP (?!).*

201544-image.png






image.png (15.7 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.