2

基本上,我需要一个如下图所示的窗口:http: //screenshots.thex9.net/2010-05-31_2132.png

(不可调整大小,但保留玻璃边框)

我已经设法让它与 Windows 窗体一起工作,但我需要使用 WPF。为了让它在 Windows 窗体中工作,我使用了以下代码:

    protected override void WndProc(ref Message m)
    {
        if (m.Msg == 0x84 /* WM_NCHITTEST */)
        {
            m.Result = (IntPtr)1;
            return;
        }
        base.WndProc(ref m);
    }

这正是我想要的,但我找不到与 WPF 等效的东西。我设法使用 WPF 获得的最接近的结果导致 Window 忽略任何鼠标输入。

任何帮助将不胜感激:)

4

2 回答 2

2

一个非常简单的解决方案是将每个窗口的 Min 和 Max 大小设置为彼此相等,并在窗口构造函数中设置一个固定数字。像这样:

public MainWindow()
{
    InitializeComponent();

    this.MinWidth = this.MaxWidth = 300;
    this.MinHeight = this.MaxHeight = 300;
}

this way the user can not change the width and height of the window. also you must set the "WindowStyle=None" property in order the get the glass border.

于 2010-05-31T14:18:29.127 回答
1

您需要为消息循环添加一个钩子:

private void Window_Loaded(object sender, RoutedEventArgs e)
{
    var interopHelper = new WindowInteropHelper(this);
    var hwndSource = HwndSource.FromHwnd(interopHelper.Handle);
    hwndSource.AddHook(WndProcHook);
}

private IntPtr WndProcHook(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
    if (msg == 0x84 /* WM_NCHITTEST */)
    {
         handled = true;
         return (IntPtr)1;
    }
}
于 2010-05-31T12:03:48.077 回答