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