using System;
using System.Windows;
using System.Windows.Interop;
namespace WpfApplication1
{
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
protected override void OnSourceInitialized(EventArgs e)
{
base.OnSourceInitialized(e);
HwndSource source = PresentationSource.FromVisual(this) as HwndSource;
source.AddHook(WndProc);
}
private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
// Handle messages...
return IntPtr.Zero;
}
}
}WPF Window 中实现WndProc
最新推荐文章于 2026-05-10 14:52:24 发布
本文介绍了一个使用WPF创建窗口并处理窗口消息的示例。通过重写OnSourceInitialized方法,添加自定义的消息处理程序WndProc,实现了对窗口底层消息的拦截与处理。

913

被折叠的 条评论
为什么被折叠?



