我想显示一个带有自定义区域和自定义外观的窗口。我挂钩一个窗口proc并通过SetWindowRgn函数在WM_SIZE消息上设置自定义区域。我还处理WM_NCCALCSIZE以删除标准窗口框架。
[SecuritySafeCritical]
protected virtual IntPtr HwndSourceHookHandler(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) {
if(msg == WinApi.WM_NCCALCSIZE) {
handled = true;
return IntPtr.Zero;
}
if(msg == WinApi.WM_SIZE) {
if(region != IntPtr.Zero)
WinApi.DeleteObject(region);
int width = lParam.ToInt32() & 0xFFFF;
int height = lParam.ToInt32() >> 16;
region = WinApi.CreateRoundRectRgn(0, 0, width, height, 40, 40);
WinApi.SetWindowRgn(new WindowInteropHelper(this).Handle, region, true);
}
return IntPtr.Zero;
}
窗口出现在我的Windows 8.1操作系统上,其中包含预期的圆角,没有边框和窗口按钮。但我注意到在这种情况下窗口立即关闭而不执行关闭动画。如果我评论SetWindowRgn,一切正常。谁知道我做错了什么?
答案 0 :(得分:0)
动画正在Window
中执行。因此,您需要在按下关闭Window
时停止Button
实际关闭,然后启动动画。动画完成后,然后应关闭Window
。这可以通过以下方式实现:
处理Window.Closing
和Window.Close
事件:
private void AnimationWindow_Closing(object sender, CancelEventArgs e)
{
if (!isCloseAnimationComplete)
{
e.Cancel = true;
CloseWindow();
}
}
private void AnimationWindow_Close(object sender, RoutedEventArgs e)
{
CloseWindow();
}
public void CloseWindow()
{
// Set up animation
animation.Completed += CloseAnimation_Completed;
// Start animation
}
private void CloseAnimation_Completed(object sender, EventArgs e)
{
isCloseAnimationComplete = true;
// Actually close Window here
Close();
}