mirror of
https://github.com/microsoft/PowerToys
synced 2024-11-22 00:03:48 +00:00
[Peek] Fix PreviewHandler previewer not visible on first activation (#34991)
ensure containerHwnd is created before usage
This commit is contained in:
parent
7e4baa14bb
commit
056fba0dcf
@ -13,5 +13,4 @@
|
||||
GotFocus="UserControl_GotFocus"
|
||||
IsEnabled="False"
|
||||
IsTabStop="True"
|
||||
Loaded="UserControl_Loaded"
|
||||
mc:Ignorable="d" />
|
||||
|
@ -61,6 +61,8 @@ namespace Peek.FilePreviewer.Controls
|
||||
|
||||
partial void OnSourceChanged(IPreviewHandler? value)
|
||||
{
|
||||
EnsureContainerHwndCreated();
|
||||
|
||||
if (Source != null)
|
||||
{
|
||||
UpdatePreviewerTheme();
|
||||
@ -82,6 +84,8 @@ namespace Peek.FilePreviewer.Controls
|
||||
|
||||
private void OnHandlerVisibilityChanged()
|
||||
{
|
||||
EnsureContainerHwndCreated();
|
||||
|
||||
if (HandlerVisibility == Visibility.Visible)
|
||||
{
|
||||
PInvoke.ShowWindow(containerHwnd, SHOW_WINDOW_CMD.SW_SHOW);
|
||||
@ -138,8 +142,19 @@ namespace Peek.FilePreviewer.Controls
|
||||
return PInvoke.DefWindowProc(hWnd, msg, wParam, lParam);
|
||||
}
|
||||
|
||||
private void UserControl_Loaded(object sender, RoutedEventArgs e)
|
||||
private void EnsureContainerHwndCreated()
|
||||
{
|
||||
if (!containerHwnd.IsNull)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var peekWindow = new HWND(Win32Interop.GetWindowFromWindowId(XamlRoot?.ContentIslandEnvironment?.AppWindowId ?? default));
|
||||
if (peekWindow.IsNull)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
fixed (char* pContainerClassName = "PeekShellPreviewHandlerContainer")
|
||||
{
|
||||
PInvoke.RegisterClass(new WNDCLASSW()
|
||||
@ -158,7 +173,7 @@ namespace Peek.FilePreviewer.Controls
|
||||
0, // Y
|
||||
0, // Width
|
||||
0, // Height
|
||||
(HWND)Win32Interop.GetWindowFromWindowId(XamlRoot.ContentIslandEnvironment.AppWindowId), // Peek UI window
|
||||
peekWindow,
|
||||
HMENU.Null,
|
||||
HINSTANCE.Null);
|
||||
|
||||
@ -169,6 +184,8 @@ namespace Peek.FilePreviewer.Controls
|
||||
|
||||
private void UserControl_EffectiveViewportChanged(FrameworkElement sender, EffectiveViewportChangedEventArgs args)
|
||||
{
|
||||
EnsureContainerHwndCreated();
|
||||
|
||||
var dpi = (float)PInvoke.GetDpiForWindow(containerHwnd) / 96;
|
||||
|
||||
// Resize the container window
|
||||
|
Loading…
Reference in New Issue
Block a user