FORM标题栏不可拖动

//不让拖动和双击无反应
                protected   override   void   WndProc(ref   Message   m)
                {
                        base.WndProc(ref   m);
                        if   (m.Msg   ==   0x84   &&   m.Result   ==   (IntPtr)2)   //不让拖动标题栏
                        {
                                m.Result   =   (IntPtr)1;
                        }
                        if   (m.Msg   ==   0xA3)   //双击标题栏无反应
                        {
                                m.WParam   =   System.IntPtr.Zero;
                        }
                }

                //标题栏右键只留下 "关闭 "菜单
                private   void   XxxxxForm_Load(object   sender,   EventArgs   e)
                {
                        for   (int   k   =   0;   k   <   6;   k++)
                                RemoveMenu(GetSystemMenu(Handle,   IntPtr.Zero),   0,   MF_BYPOSITION   |   MF_REMOVE);
                        if   (_FirstShown   ==   false)
                        {
                                。。。
                        }
                }

                //彻底去掉右键系统菜单
                //如果需要窗口右边的关闭按钮可以注释掉下面的这个函数
                protected   override   CreateParams   CreateParams
                {
                        get
                        {
                                CreateParams   cp   =   base.CreateParams;
                                //   cp.Style   =   cp.Style   &   ~WS_SYSMENU;
                                //   太狠了,连窗口的关闭按钮都没有了
                                return   cp;
                        }
                }
某些API要加入
                const   int   MF_BYPOSITION   =   0x0400;
                const   int   MF_REMOVE   =   0x1000;
                const   int   WS_SYSMENU   =   0x00080000;

                [DllImport( "user32.dll ",   EntryPoint   =   "GetSystemMenu ")]
                extern   static   IntPtr   GetSystemMenu(IntPtr   hWnd,   IntPtr   bRevert);

                [DllImport( "user32.dll ",   EntryPoint   =   "RemoveMenu ")]
                extern   static   int   RemoveMenu(IntPtr   hMenu,   int   nPos,   int   flags);

posted on 2012-01-09 15:00  carekee  阅读(217)  评论(0编辑  收藏  举报