winrt.windows.ui.xaml.hosting.interop module¶
APIs for desktop interop with the Windows.UI.Xaml.Hosting namespace, which hosts UWP XAML in a window of a desktop app (XAML Islands).
DesktopWindowXamlSourceNative¶
The native interfaces of a
DesktopWindowXamlSource,
which attach it to a window and hand it the window's messages.
Call as_() on a source to get one. The class cannot be created or subclassed.
It is equal to, and hashes like, any WinRT object that is the same COM object.
from winrt.windows.ui.xaml.hosting import DesktopWindowXamlSource
from winrt.windows.ui.xaml.hosting.interop import DesktopWindowXamlSourceNative
with DesktopWindowXamlSource() as source:
native = source.as_(DesktopWindowXamlSourceNative)
native.attach_to_window(hwnd)
...
attach_to_window¶
Attaches the XAML content to a window of the app, as a child window of it.
| Parameter | Type | Description |
|---|---|---|
hwnd |
int |
The handle (HWND) of the window to attach to. |
Raises: OSError on failure.
window_handle¶
The handle (HWND) of the child window that holds the XAML content, which the
app sizes and positions within its own window. It is 0 before
attach_to_window().
pretranslate_message¶
Gives the XAML content the first look at a message of the app's message loop, which is what makes keyboard navigation and accelerators work inside it.
| Parameter | Type | Description |
|---|---|---|
msg |
Buffer |
A Win32 MSG, such as a ctypes.wintypes.MSG. |
Returns: True if the XAML content handled the message, in which case the
app does not translate or dispatch it.
Raises:
BufferErrorifmsgis not the size of aMSG.OSErroron failure.
msg = wintypes.MSG()
while user32.GetMessageW(ctypes.byref(msg), None, 0, 0) > 0:
if native.pretranslate_message(msg):
continue
user32.TranslateMessage(ctypes.byref(msg))
user32.DispatchMessageW(ctypes.byref(msg))
Added in version 3.1