电脑故障

位置:IT落伍者 >> 电脑故障 >> 浏览文章

WinForm特效:拦截窗体上各个部位的点击


发布日期:2020/1/5
 

windows窗体的标题栏无法直接通过一些默认的事件来控制需要了解和WM_NCHITTEST相关的windows消息 以下示例演示了最简单的效果片断 他会把客户区和标题栏的效果互换比如无法按住标题栏拖动窗体而是改为了安抓客户区拖动并禁用了关闭按钮 其中mResult从都有定义分别度应了整个窗体的各个部位比如代表客户区代表最小化按钮等等 using System;

using SystemWindowsForms;

namespace WindowsApplication

{

public partial class Form : Form

{

public Form() { InitializeComponent(); thisText = 双击左上角图标关闭窗体; }

//拦击标题栏鼠标位置事件

const int WM_NCHITTEST = x;

protected override void WndProc(ref Message m)

{

baseWndProc(ref m); if (mMsg == WM_NCHITTEST)

{

switch (mResultToInt())

{

case ://客户区

mResult = new IntPtr(); break;

case ://标题栏

mResult = new IntPtr(); break;

case : mResult = new IntPtr(); break;

default: ConsoleWriteLine(m); break;

}

}

}

}

}

下面是各个常量的意义从Delphi VCL中摘取

{ WM_NCHITTEST and MOUSEHOOKSTRUCT Mouse Position Codes }

{$EXTERNALSYM HTERROR}

HTERROR = ;

{$EXTERNALSYM HTTRANSPARENT}

HTTRANSPARENT = ;

{$EXTERNALSYM HTNOWHERE}

HTNOWHERE = ;

{$EXTERNALSYM HTCLIENT}

HTCLIENT = ;

{$EXTERNALSYM HTCAPTION}

HTCAPTION = ;

{$EXTERNALSYM HTSYSMENU}

HTSYSMENU = ;

{$EXTERNALSYM HTGROWBOX}

HTGROWBOX = ;

{$EXTERNALSYM HTSIZE}

HTSIZE = HTGROWBOX;

{$EXTERNALSYM HTMENU}

HTMENU = ;

{$EXTERNALSYM HTHSCROLL}

HTHSCROLL = ;

{$EXTERNALSYM HTVSCROLL}

HTVSCROLL = ;

{$EXTERNALSYM HTMINBUTTON}

HTMINBUTTON = ;

{$EXTERNALSYM HTMAXBUTTON}

HTMAXBUTTON = ;

{$EXTERNALSYM HTLEFT}

HTLEFT = ;

{$EXTERNALSYM HTRIGHT}

HTRIGHT = ;

{$EXTERNALSYM HTTOP}

HTTOP = ;

{$EXTERNALSYM HTTOPLEFT}

HTTOPLEFT = ;

{$EXTERNALSYM HTTOPRIGHT}

HTTOPRIGHT = ;

{$EXTERNALSYM HTBOTTOM}

HTBOTTOM = ;

{$EXTERNALSYM HTBOTTOMLEFT}

HTBOTTOMLEFT = ;

{$EXTERNALSYM HTBOTTOMRIGHT}

HTBOTTOMRIGHT = ;

{$EXTERNALSYM HTBORDER}

HTBORDER = ;

{$EXTERNALSYM HTREDUCE}

HTREDUCE = HTMINBUTTON;

{$EXTERNALSYM HTZOOM}

HTZOOM = HTMAXBUTTON;

{$EXTERNALSYM HTSIZEFIRST}

HTSIZEFIRST = HTLEFT;

{$EXTERNALSYM HTSIZELAST}

HTSIZELAST = HTBOTTOMRIGHT;

{$EXTERNALSYM HTOBJECT}

HTOBJECT = ;

{$EXTERNALSYM HTCLOSE}

HTCLOSE = ;

{$EXTERNALSYM HTHELP}

HTHELP = ;

上一篇:构造函数和析构函数

下一篇:在Silverlight应用程序中操作Cookie