NativeWindow提供窗口句柄和窗口过程的低级封装。下面是拦截ContextMenu的显示和消失的例子
public class NativeContextMenu : NativeWindow
{
private const int WM_EXITMENULOOP = 0x212;
private const int WM_ENTERMENULOOP = 0x0211;
public event System.EventHandler ExitMenuLoop;
private IntPtr handle;
public NativeContextMenu(IntPtr handle)//使用窗体句柄
{
this.handle = handle;
this.AssignHandle(handle);
}
protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case WM_EXITMENULOOP:
if (ExitMenuLoop!=null)
{
ExitMenuLoop(this, new EventArgs());
}
break;
}
base.WndProc(ref m);
}
}
在CF中没有NativeWindow,使用using OpenNETCF.Windows.Forms;
本文介绍了一个使用.NET框架的NativeWindow类来实现拦截上下文菜单显示和消失的示例。通过重写WndProc方法并处理WM_ENTERMENULOOP和WM_EXITMENULOOP消息,可以触发对应的事件。

919

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



