我創建了這個類,它完美地適用於讓我的WPF應用程序對鼠標事件透明。如何使窗口對WPF中的鼠標事件不可見?
using System.Runtime.InteropServices;
class Win32
{
public const int WS_EX_TRANSPARENT = 0x00000020;
public const int GWL_EXSTYLE = (-20);
[DllImport("user32.dll")]
public static extern int GetWindowLong(IntPtr hwnd, int index);
[DllImport("user32.dll")]
public static extern int SetWindowLong(IntPtr hwnd, int index, int newStyle);
public static void makeTransparent(IntPtr hwnd)
{
// Change the extended window style to include WS_EX_TRANSPARENT
int extendedStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
Win32.SetWindowLong(hwnd, GWL_EXSTYLE, extendedStyle | WS_EX_TRANSPARENT);
}
public static void makeNormal(IntPtr hwnd)
{
//how back to normal what is the code ?
}
}
我運行這個讓我的應用程序忽略了鼠標事件,但之後執行的代碼,我希望應用程序恢復正常並重新處理鼠標事件。怎麼可以做到這一點?
IntPtr hwnd = new WindowInteropHelper(this).Handle;
Win32.makeTransparent(hwnd);
什麼是使應用程序恢復正常的代碼?
很抱歉,但不明白,可以SHOWME普萊舍如何。 – Larsen187 2011-01-10 13:49:37
沒有理由記住`extendedStyle`。您只需檢索當前值並從中刪除`WS_EX_TRANSPARENT`標誌。看到我的[回覆](http://stackoverflow.com/questions/4647345/how-can-i-make-a-window-invisible-to-mouse-events-in-wpf/4647540#4647540)瞭解更多詳情。 – 2011-01-10 13:59:10
@Cody Gray:同意,這是一個更優雅的解決方案。 – 2011-01-10 14:25:26