C#调用API函数

 在类中写入:

            [DllImport("user32.dll")]
            private static extern int SetWindowLong(IntPtr hwnd, int nindex, int newlong);
            [DllImport("user32.dll")]
            private static extern int GetWindowLong(IntPtr hwnd, int newlong);
            [DllImportAttribute("gdi32.dll")]
            public static extern IntPtr CreateRoundRectRgn(int nLeftRect, int nTopRect, int         

             nRightRect, int nBottomRect, int nWidthEllipse, int nHeightEllipse);
            [DllImportAttribute("user32.dll")]
            public static extern int SetWindowRgn(IntPtr hWnd, IntPtr hRgn, bool bRedraw);

            [DllImport("user32.dll")]
            public static extern bool ReleaseCapture();
            [DllImport("user32.dll")]
            public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int

            lParam);

        [DllImport("user32")]
        public static extern int GetKeyState(int nVirtKey);   //得到键盘上的键状态

一些消息参数数值:

            const int WM_SYSCOMMAND = 0x0112;
            const int SC_MOVE = 0xF010;
            const int HTCAPTION = 0x0002;
            const int WS_CAPTION = 0x00C00000;
            const int GWL_EXSTYLE = -20;
            const int GWL_STYLE = -16;
            const int WS_EX_TOOLWINDOW = 0x0080000;
            const int WS_EX_APPWINDOW = 0x0040000;

           const int WM_LBUTTONDOWN = 0x0201;
           const int WM_RBUTTONDOWN = 0x0204;

API调用:

               SetWindowLong((IntPtr)f.Handle, GWL_STYLE,GetWindowLong((IntPtr)

                  f.Handle,GWL_STYLE) & ~WS_CAPTION );
                // 去掉窗体标题栏
               IntPtr rgnHwnd = CreateRoundRectRgn(0,0, f.Width, f.Height, 5, 5);
               SetWindowRgn((IntPtr)f.Handle, rgnHwnd, true);
                //给窗体切圆角

          

           SendMessage((IntPtr)control.Handle,WM_LBUTTONDOWN,0,0);

           SendMessage((IntPtr)control.Handle,WM_LBUTTONUP,0,0);

           //模拟一次鼠标单击

           label1.Text = (GetKeyState(20) & -1) > 0 ? "CapsLock:开" : "CapsLock:关";

            //取得CapsLock灯的状态赋值LABEL的TEXT属性

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值