Exemplo n.º 1
0
        /// <summary>
        /// 获取窗口客户区域在屏幕上的位置
        /// </summary>
        /// <param name="hwnd"></param>
        /// <param name="x1"></param>
        /// <param name="y1"></param>
        /// <param name="x2"></param>
        /// <param name="y2"></param>
        /// <returns></returns>
        public bool GetClientRect(int hwnd, out int x1, out int y1, out int x2, out int y2)
        {
            if (!Win32API.IsWindow((IntPtr)hwnd))
            {
                x1 = -1;
                y1 = -1;
                x2 = -1;
                y2 = -1;
                return(false);
            }
            Win32API.RECT rect = new Win32API.RECT();
            bool          a    = Win32API.GetClientRect((IntPtr)hwnd, out rect);

            Point point = new Point()
            {
                X = rect.Left, Y = rect.Top
            };
            bool b = Win32API.ClientToScreen((IntPtr)hwnd, ref point);

            x1 = point.X;
            y1 = point.Y;

            point = new Point()
            {
                X = rect.Right, Y = rect.Bottom
            };
            bool c = Win32API.ClientToScreen((IntPtr)hwnd, ref point);

            x2 = point.X;
            y2 = point.Y;
            return(a && b && c);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 获取指定窗口句柄的非客户区数据
        /// </summary>
        /// <param name="hwnd">窗口句柄</param>
        /// <returns></returns>
        public static NcClientData GetNcClientData(IntPtr hwnd)
        {
            NcClientData data = new NcClientData();

            if (hwnd != IntPtr.Zero)
            {
                int style = Win32API.GetWindowLong(hwnd, WindowLongIndex.GWL_STYLE);
                if ((style & (int)WndStyle.WS_BORDER) == (int)WndStyle.WS_BORDER)//是否包含边框
                {
                    Rect wndRect = new Rect();
                    Win32API.GetWindowRect(hwnd, ref wndRect);
                    Rect clientRect = new Rect();
                    Win32API.GetClientRect(hwnd, ref clientRect);
                    Point p = new Point();
                    Win32API.ClientToScreen(hwnd, ref p);
                    clientRect.left        += p.x;
                    clientRect.right       += p.x;
                    clientRect.top         += p.y;
                    clientRect.bottom      += p.y;
                    data.leftBorderWidth    = (clientRect.right - wndRect.left) - (clientRect.right - clientRect.left);
                    data.rightBorderWidth   = (wndRect.right - clientRect.left) - (clientRect.right - clientRect.left);
                    data.bottomBorderHeight = (wndRect.bottom - clientRect.top) - (clientRect.bottom - clientRect.top);
                    if ((style & (int)WndStyle.WS_CAPTION) == (int)WndStyle.WS_CAPTION)//是否包含标题栏
                    {
                        data.titleHeight = (clientRect.bottom - wndRect.top) - (clientRect.bottom - clientRect.top);
                    }
                    else
                    {
                        data.topBorderHeight = (clientRect.bottom - wndRect.top) - (clientRect.bottom - clientRect.top);
                    }
                }
            }
            return(data);
        }
Exemplo n.º 3
0
        private void button65_Click(object sender, EventArgs e)
        {
            Mqd.Win32.DataDef.Point p = new Mqd.Win32.DataDef.Point();
            Win32API.ClientToScreen(this.Handle, ref p);
            Win32API.ScreenToClient(this.Handle, ref p);

            //int style = Win32API.GetWindowLong(this.Handle, WindowLongIndex.GWL_EXSTYLE);
            //style &= ~(int)WndExStyle.WS_EX_APPWINDOW;
            //Win32API.SetWindowLong(this.Handle,WindowLongIndex.GWL_EXSTYLE,style);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 将窗口坐标转换为屏幕坐标
        /// </summary>
        /// <param name="hwnd"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        public bool ClientToScreen(int hwnd, out int x, out int y)
        {
            if (!Win32API.IsWindow((IntPtr)hwnd))
            {
                x = -1;
                y = -1;
                return(false);
            }
            Point point = new Point();
            bool  ret   = Win32API.ClientToScreen((IntPtr)hwnd, ref point);

            x = point.X;
            y = point.Y;
            return(ret);
        }