熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

WinForm特效:攔截窗體上各個部位的點擊

2013-11-13 10:13:49  來源: .NET編程 

  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 = ;


From:http://tw.wingwit.com/Article/program/net/201311/12981.html
    推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.