Win32 활성화 메시지를 처리 할 수 있도록 일부 WPF 윈도우의 Win32 윈도우 핸들에 액세스해야합니다. PresentationSource.FromVisual
또는 WindowInteropHelper
을 사용하여 Win32 창 핸들을 얻을 수 있지만 WPF 창이 아직 작성되지 않은 경우 문제점이 있음을 알고 있습니다.WPF 창의 네이티브 Win32 핸들 생성하기
PresentationSource.FromVisual
을 사용하고 창을 만들지 않은 경우 반환 된 PresentationSource
은 null입니다. WindowInteropHelper
을 사용하고 창을 만들지 않았다면 Handle
속성은 IntPtr.Zero
(null)입니다.
핸들에 액세스하려고하기 전에 창에 this.Show()
및 this.Hide()
을 호출 해 보았습니다. 그런 다음 핸들을 얻을 수 있지만 화면이 순간적으로 깜박입니다 (못생긴!).
누군가 WPF 창을 강제로 생성하는 방법을 알고 있습니까? Windows Forms에서는 Form.Handle
속성에 액세스하는 것만 큼 쉽습니다.
편집 : Chris Taylor의 답변에 변형이 있습니다. 여기에는, 경우에 다른 사람 도움이된다
static void InitializeWindow(Window window)
{
// Get the current values of the properties we are going to change
double oldWidth = window.Width;
double oldHeight = window.Height;
WindowStyle oldWindowStyle = window.WindowStyle;
bool oldShowInTaskbar = window.ShowInTaskbar;
bool oldShowActivated = window.ShowActivated;
// Change the properties to make the window invisible
window.Width = 0;
window.Height = 0;
window.WindowStyle = WindowStyle.None;
window.ShowInTaskbar = false;
window.ShowActivated = false;
// Make WPF create the window's handle
window.Show();
window.Hide();
// Restore the old values
window.Width = oldWidth;
window.Height = oldHeight;
window.WindowStyle = oldWindowStyle;
window.ShowInTaskbar = oldShowInTaskbar;
window.ShowActivated = oldShowActivated;
}
// Use it like this:
InitializeWindow(myWpfWindow);
이 질문을 본 적이 있으신가요? http://stackoverflow.com/questions/1556182/finding-the-handle-to-a-wpf-window- 창이 이미 존재하는지 언급하지 않으므로 도움이되지 않을 수 있습니다. 아닙니다. – ChrisF
@ChrisF : 감사합니다! 예, 나는 그것을 보았습니다. 불행히도 아직 창을 만들지 못하는 문제가 있습니다. –
귀하의 사례가 다른 경우 중복으로 선택되지 않도록 귀하의 회신을 받기 위해 언급하겠다고 생각했습니다. – ChrisF