如何禁用双击窗体图标关闭窗体
这个问题来自论坛提问,.Net由于对WindowsAPI的透明度增强,很多Winform开发者都不太了解经典的win32消息方面的知识。所有窗体上的鼠标反映都可以用WndProc拦截,除了系统菜单、标题栏、系统按纽还包括客户区。
<div class="highlighter">
[*]usingSystem;
[*]usingSystem.Windows.Forms;
[*]usingSystem.Runtime.InteropServices;
[*]namespaceWindowsApplication1
[*]{
[*]publicpartialclassForm1:Form
[*]{
[*]publicForm1()
[*]{
[*]InitializeComponent();
[*]
[*]
[*]}
[*]
[*]privatestaticexternIntPtrGetSystemMenu(IntPtrhWnd,boolbRevert);
[*]protectedoverridevoidWndProc(refMessagem)
[*]{
[*]if(m.Msg==0x112)
[*]{
[*]if(m.WParam.ToInt32()==61539||m.WParam.ToInt32()==61587)
[*]{
[*]Console.WriteLine(m.WParam);
[*]return;
[*]}
[*]}
[*]base.WndProc(refm);
[*]}
[*]}
[*]}
[*]
[*]
页:
[1]