Ejemplo n.º 1
0
 public static extern Boolean GetWindowInfo(IntPtr hwnd, ref WINDOWINFO pwi);
Ejemplo n.º 2
0
 static extern bool GetWindowInfo(HWND hwnd, out WINDOWINFO pwi);
Ejemplo n.º 3
0
        /// <summary>
        /// Determines whether the specified window is a match.
        /// </summary>
        /// <param name="hwnd">The window handle.</param>
        /// <returns>
        /// 	<c>true</c> if the specified window is a match; otherwise, <c>false</c>.
        /// </returns>
        private bool IsMatch(IntPtr hwnd)
        {
            var info = new WINDOWINFO(null);
            GetWindowInfo(hwnd, ref info);

            var title = GetWindowTitle(hwnd);
            return string.CompareOrdinal(title, windowTitle) == 0;
        }
Ejemplo n.º 4
0
 static extern bool GetWindowInfo(IntPtr hwnd, out WINDOWINFO pwi);
        private unsafe void aiRunner()
        {
            // init game state
            gs = new GameState();
            gs.AutomaticLevelChange = false;
            gs.Replay = true;
            gs.StartPlay();
            BasePacman controller = new SmartDijkstraPac();

            //
            runningPacman = true;
            while (true)
            {
                watch.Start();

                // get window info
                WINDOWINFO info = Comm.GetWindowInfoEasy(msPacmanProcess.MainWindowHandle);
                if (info.dwWindowStatus == 0)
                {
                    break;
                }

                // capture frame
                bitmap = (Bitmap)NativeMethods.GetDesktopBitmap(info.rcClient.Left, info.rcClient.Top, width, height, bitmap);
                unsafe {
                    BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, PixelFormat.Format32bppRgb);
                    IntPtr     ptr        = bitmapData.Scan0;
                    //Marshal.Copy(ptr, colorValues, 0, width * height);

                    Marshal.Copy(ptr, colorValues, 0, size);

                    // subtract red maze
                    for (int i = 0; i < colorValues.Length; i++)
                    {
                        colorValues[i] -= mazeRedEmpty[i];
                    }
                    // run test
                    test();

                    // Copy the RGB values back to the bitmap
                    Marshal.Copy(colorValues, 0, ptr, size);

                    bitmap.UnlockBits(bitmapData);
                }

                // update framerate
                if (runningAvg.Count > 8)
                {
                    runningAvg.Dequeue();
                }
                if (runningAvg.Count != 0)
                {
                    msPerFrame = 0;
                    foreach (long ms in runningAvg)
                    {
                        msPerFrame += (int)ms;
                    }
                    msPerFrame /= runningAvg.Count;
                }
                // test
                Comm.SendKey(controller.Think(gs));
                // update status
                this.BeginInvoke(updateMethod);
                watch.Stop();
                // update running avg
                runningAvg.Enqueue(watch.ElapsedMilliseconds);
                // reset
                watch.Reset();
                Thread.Sleep(30);
            }
            runningPacman = false;
            this.BeginInvoke(updateMethod);
        }
Ejemplo n.º 6
0
		public static void WmGetMinMaxInfo(IntPtr hwnd, IntPtr lParam)
		{
			// Get the MINMAXINFO structure from memory location given by lParam
			MINMAXINFO mmi =
				(MINMAXINFO)Marshal.PtrToStructure(lParam, typeof(MINMAXINFO));

			// Get the monitor that overlaps the window or the nearest
			IntPtr monitor = MonitorFromWindow(hwnd, (uint)MonitorDefaults.MONITOR_DEFAULTTONEAREST);
			if (monitor != IntPtr.Zero)
			{
				// Get monitor information
				MONITORINFO monitorInfo = new MONITORINFO();
				monitorInfo.Size = Marshal.SizeOf(typeof(MONITORINFO));
				GetMonitorInfo(monitor, ref monitorInfo);

				// The display monitor rectangle.
				// If the monitor is not the primary display monitor,
				// some of the rectangle's coordinates may be negative values
				RECT rcMonitorArea = monitorInfo.Monitor;

				// Get window information
				WINDOWINFO windowInfo = new WINDOWINFO();
				windowInfo.Size = (UInt32)(Marshal.SizeOf(typeof(WINDOWINFO)));
				GetWindowInfo(hwnd, ref windowInfo);
				int borderWidth = (int)windowInfo.WindowBordersWidth;
				int borderHeight = (int)windowInfo.WindowBordersHeight;

				// Set the dimensions of the window in maximized state
				mmi.MaxPosition.X = -borderWidth;
				mmi.MaxPosition.Y = -borderHeight;
				mmi.MaxSize.X =
					rcMonitorArea.Right - rcMonitorArea.Left + 2 * borderWidth;
				mmi.MaxSize.Y =
					rcMonitorArea.Bottom - rcMonitorArea.Top + 2 * borderHeight;

				// Set minimum and maximum size
				// to the size of the window in maximized state
				mmi.MinTrackSize.X = mmi.MaxSize.X;
				mmi.MinTrackSize.Y = mmi.MaxSize.Y;
				mmi.MaxTrackSize.X = mmi.MaxSize.X;
				mmi.MaxTrackSize.Y = mmi.MaxSize.Y;
			}

			// Copy the structure to memory location specified by lParam.
			// This concludes processing of WM_GETMINMAXINFO.
			Marshal.StructureToPtr(mmi, lParam, true);
		}
Ejemplo n.º 7
0
 // Call this function to determine if the parent skin is topmost
 public static bool ParentIsTopmost(Rainmeter.Settings.InstanceSettings Instance)
 {
     IntPtr hwnd = (IntPtr)(UInt32.Parse(Rainmeter.PluginBridge("GetWindow", Rainmeter.PluginBridge("GetConfig", Instance.INI_File))));
     WINDOWINFO info = new WINDOWINFO(true);
     GetWindowInfo(hwnd, ref info);
     return ((info.dwExStyle & 0x00000008L) > 0);
 }
Ejemplo n.º 8
0
 protected extern static bool GetWindowInfo(
     IntPtr hWnd,
     out WINDOWINFO pwi);
Ejemplo n.º 9
0
		/// <summary>
		/// Sends a window to a screen
		/// </summary>
		/// <param name="hwnd">window handle</param>
		/// <param name="screen">screen to send the window to</param>
		/// <param name="offsetX">x offset on the screen</param>
		/// <param name="offsetY">y offset on the screen</param>
		/// <returns>bool to indicate success and failure.</returns>
		public static bool SendToScreen(IntPtr hwnd, Screen screen, int offsetX = 0, int offsetY = 0)
		{
			if (screen == null)
				return false;

			WINDOWINFO winInfo = new WINDOWINFO();
			GetWindowInfo(hwnd, ref winInfo);

			int windowWidth = winInfo.Window.Right - winInfo.Window.Left;
			int windowHeight = winInfo.Window.Bottom - winInfo.Window.Top;

			var dpiRatio = getDPIRatio();
			double x = screen.WorkingArea.Left + offsetX;
			double y = screen.WorkingArea.Top + offsetY;
			if (1.45 < dpiRatio.X && dpiRatio.X < 1.55 &&
				1.45 < dpiRatio.Y && dpiRatio.Y < 1.55)
			{
				x /= dpiRatio.X;
				y /= dpiRatio.Y;
			}

			return MoveWindow(hwnd, (int)x, (int)y, windowWidth, windowHeight, false);
		}
Ejemplo n.º 10
0
        /// <summary> Find a windows and return true is it's active and visible </summary>
        /// <param name="hWnd"> Window's handle. </param>
        public static bool IsActive(IntPtr hWnd)
        {
            WINDOWINFO wInfo = GetWindowInfo(hWnd);

            return((wInfo.dwWindowStatus == 1) && (hWnd == GetForegroundWindow()));
        }
Ejemplo n.º 11
0
        void startOp(bool resize)
        {
            if (isOperating && isOperationResizing == resize)
                return; //an operation is in progress and is the same type as the one requested.

            //Make sure the window underneath the cursor is foregrounded.
            POINT p;
            if (GetCursorPos(out p))
            {
                IntPtr hWnd = WindowFromPoint(p);
                IntPtr hWndSuccess = IntPtr.Zero;

                while (hWnd != IntPtr.Zero)
                {
                    hWndSuccess = hWnd;
                    hWnd = GetParent(hWnd);
                }

                if (hWndSuccess != IntPtr.Zero && hWndSuccess != GetForegroundWindow())
                {
                    {
                        //first set the main form window as active...
                        uint cursorWindowThreadId = GetWindowThreadProcessId(Handle, IntPtr.Zero);
                        uint foregroundWindowThreadId = GetWindowThreadProcessId(GetForegroundWindow(), IntPtr.Zero);

                        if (foregroundWindowThreadId != cursorWindowThreadId)
                            AttachThreadInput(foregroundWindowThreadId, cursorWindowThreadId, true);

                        SetForegroundWindow(Handle);

                        if (foregroundWindowThreadId != cursorWindowThreadId)
                            AttachThreadInput(foregroundWindowThreadId, cursorWindowThreadId, false);
                    }

                    {
                        //then switch to the target window.
                        uint cursorWindowThreadId = GetWindowThreadProcessId(hWndSuccess, IntPtr.Zero);
                        uint foregroundWindowThreadId = GetWindowThreadProcessId(GetForegroundWindow(), IntPtr.Zero);

                        if (foregroundWindowThreadId != cursorWindowThreadId)
                            AttachThreadInput(foregroundWindowThreadId, cursorWindowThreadId, true);

                        SetForegroundWindow(hWndSuccess);

                        if (foregroundWindowThreadId != cursorWindowThreadId)
                            AttachThreadInput(foregroundWindowThreadId, cursorWindowThreadId, false);
                    }
                }
            }

            isOperationResizing = resize;

            IntPtr window = GetForegroundWindow();
            WINDOWINFO info = new WINDOWINFO();
            GetWindowInfo(window, ref info);

            initialPosition = Cursor.Position;
            windowSize = info.rcWindow;

            lock (this)
            {
                if (isOperating)
                    return; //an operation has just switch modes from move <-> resize, but is already in progress.

                isOperating = true;
            }

            new Thread(t =>
            {
                Point lastCursorPosition = Point.Empty;

                while (isOperating)
                {
                    if (Cursor.Position == lastCursorPosition)
                    {
                        Thread.Sleep(16);
                        continue;
                    }

                    lastCursorPosition = Cursor.Position;

                    if (isOperationResizing)
                    {
                        SetWindowPos(window, IntPtr.Zero, windowSize.X, windowSize.Y, windowSize.Width + (lastCursorPosition.X - initialPosition.X), windowSize.Height + (lastCursorPosition.Y - initialPosition.Y), 0);
                    }
                    else
                    {
                        SetWindowPos(window, IntPtr.Zero, windowSize.X + (lastCursorPosition.X - initialPosition.X), windowSize.Y + (lastCursorPosition.Y - initialPosition.Y), windowSize.Width, windowSize.Height, 0);
                    }
                }
            }).Start();
        }
Ejemplo n.º 12
0
 public static extern int GetWindowInfo(IntPtr hwnd, out WINDOWINFO pwi);
Ejemplo n.º 13
0
 public static extern Boolean GetWindowInfo(int hWnd, ref WINDOWINFO pwi);
Ejemplo n.º 14
0
 internal static void GetWindowInfo(IntPtr hwnd, out WINDOWINFO pwi)
 {
     pwi = new WINDOWINFO { cbSize = Marshal.SizeOf(typeof(WINDOWINFO)) };
     var result = _GetWindowInfo(hwnd, ref pwi);
     if (!result)
     {
         throw new Win32Exception();
     }
 }
Ejemplo n.º 15
0
 static extern bool GetWindowInfo(IntPtr hwnd, ref WINDOWINFO pwi);
Ejemplo n.º 16
0
		/// <summary>
		/// Converts ScreenAlignment to Offset. alignment depends on the window and the screen
		/// </summary>
		/// <param name="hwnd">window handle</param>
		/// <param name="screen"></param>
		/// <param name="alignment"></param>
		/// <returns>offset</returns>
		public static Point? AlignmentToOffset(IntPtr hwnd, Screen screen, ScreenAlignment alignment)
		{
			if (screen == null) return null;
			WINDOWINFO winInfo = new WINDOWINFO();
			GetWindowInfo(hwnd, ref winInfo);

			int windowWidth = winInfo.Window.Right - winInfo.Window.Left;
			int windowHeight = winInfo.Window.Bottom - winInfo.Window.Top;
			
			var dpiRatio = getDPIRatio();
			if (1.45 < dpiRatio.X && dpiRatio.X < 1.55 &&
				1.45 < dpiRatio.Y && dpiRatio.Y < 1.55)
			{
				windowWidth = (int)((double)windowWidth*dpiRatio.X);
				windowHeight = (int)((double)windowHeight*dpiRatio.Y);
			}

			return AlignmentToOffsetLogic(windowWidth, windowHeight, screen.WorkingArea, alignment);
		}
Ejemplo n.º 17
0
        public void NCPaint(ref Message m)
        {
            //IntPtr hDC = GetWindowDC(this.Handle);
            IntPtr hDC = GetDCEx(Handle, m.WParam, DCX_WINDOW | DCX_LOCKWINDOWUPDATE | DCX_UNDOCUMENTED);

            if (hDC != IntPtr.Zero)
            {
                Graphics grTemp = Graphics.FromHdc(hDC);

                int ScrollBarWidth = SystemInformation.VerticalScrollBarWidth;
                int ScrollBarHeight = SystemInformation.HorizontalScrollBarHeight;

                //Bounds is unreliable as it often reports the incorrect
                //location, especially when part of the window is OffScreen.
                //So we'll use GetWindowInfo as it returns all the info we need.
                WINDOWINFO wi = new WINDOWINFO();
                wi.cbSize = (uint) Marshal.SizeOf(wi);
                GetWindowInfo(Handle, ref wi);
                //Console.WriteLine(wi.rcWindow.ToRectangle().Width);

                wi.rcClient.Right--;
                wi.rcClient.Bottom--;

                //Define a Clip Region to pass back to WM_NCPAINTs wParam.
                //Must be in Screen Coordinates, which is what GetWindowInfo returns.
                Region updateRegion = new Region(wi.rcWindow.ToRectangle());
                updateRegion.Exclude(wi.rcClient.ToRectangle());

                if (this.HScroll && this.VScroll)
                    updateRegion.Exclude(Rectangle.FromLTRB
                        (wi.rcClient.Right + 1, wi.rcClient.Bottom + 1,
                        wi.rcWindow.Right, wi.rcWindow.Bottom));

                //For Painting we need to zero offset the Rectangles.
                Rectangle windowRect = wi.rcWindow.ToRectangle();

                Bitmap bmp = new Bitmap(windowRect.Width, windowRect.Height);
                Graphics gr = Graphics.FromImage(bmp);
                gr.Clear(Color.Black);

                Bitmap bmMask = new Bitmap(bmp.Width, bmp.Height);
                Graphics gMask = Graphics.FromImage(bmMask);
                gMask.Clear(Color.White);

                Point offset = Point.Empty - (Size) windowRect.Location;

                windowRect.Offset(offset);

                Rectangle clientRect = windowRect;

                clientRect.Inflate(-marginSize, -marginSize);
                clientRect.Width -= 1;
                clientRect.Height -= 1;

                //Fill the BorderArea
                Region paintRegion = new Region(windowRect);
                paintRegion.Exclude(clientRect);
                //					gr.FillRegion(Brushes.Green, PaintRegion);
                gMask.FillRegion(Brushes.Black, paintRegion);

                //Fill the Area between the scrollbars
                if (this.HScroll && this.VScroll)
                {
                    Rectangle scrollRect = new Rectangle(clientRect.Right - ScrollBarWidth,
                        clientRect.Bottom - ScrollBarHeight, ScrollBarWidth + 2, ScrollBarHeight + 2);
                    scrollRect.Offset(-1, -1);
                    gr.FillRectangle(SystemBrushes.Control, scrollRect);
                    gMask.FillRectangle(Brushes.Black, scrollRect);
                }

                //Adjust ClientRect for Drawing Border.
                clientRect.Inflate(2, 2);
                clientRect.Width -= 1;
                clientRect.Height -= 1;

                gr.DrawRectangle(SystemPens.ControlDark, clientRect);
                clientRect.Inflate(-1, -1);
                gr.DrawRectangle(new Pen(SystemColors.Window), clientRect);

                //Draw offscreen bitmap to Control
                //If Parent form has WS_EX_LAYERED then use
                //Interop to blit mask then image to screen
                //m.wParam will always be 1 in this case.
                if (m.WParam == (IntPtr) 1)
                {
                    Blit(bmMask, hDC, SRCAND);
                    Blit(bmp, hDC, SRCPAINT);
                }
                    //...otherwise draw image straight to control
                else
                {
                    bmp.MakeTransparent(Color.Black);
                    grTemp.DrawImage(bmp, windowRect);
                }

                //Clean Up
                gMask.Dispose();
                bmMask.Dispose();

                gr.Dispose();
                bmp.Dispose();

                //Return hRegion
            //				if ( m.WParam != (IntPtr) 1 )
            //					DeleteObject(m.WParam);

                m.WParam = updateRegion.GetHrgn(grTemp);

                ReleaseDC(Handle, hDC);
                grTemp.Dispose();
            }
        }
Ejemplo n.º 18
0
 internal static extern bool GetWindowInfo(IntPtr hwnd, ref WINDOWINFO windowInfo);
Ejemplo n.º 19
0
 public Rectangle GetScreenBounds()
 {
     WINDOWINFO wi = new WINDOWINFO();
     wi.cbSize = Marshal.SizeOf(wi);
     if (GetWindowInfo(this.handle, ref wi))
     {
         RECT r = wi.rcWindow;
         return new Rectangle(r.left, r.top, r.right - r.left, r.bottom - r.top);
     }
     return Rectangle.Empty;
 }
Ejemplo n.º 20
0
        public void DoMouseClick(Point p, RemoteDesktopMouseAction mouseAction)
        {
            var hitTest = HitTestValues.HTNOWHERE;
            var window  = WindowFromPoint(p, 100, ref hitTest, IntPtr.Zero);

            if (hitTest >= HitTestValues.HTSIZEFIRST && hitTest <= HitTestValues.HTSIZELAST)
            {
                var style = (WindowStyles)GetWindowLong(window, GWL_STYLE);
                if ((style & WindowStyles.WS_CHILD) == WindowStyles.WS_CHILD && !StyleHaveSizeBorders(style))
                {
                    var parent = GetParent(window);
                    if (parent != IntPtr.Zero)
                    {
                        window = parent;
                    }
                }
            }

            //TODO
            if ((GetWindowClassFlags(window) & WindowPrintTypes.WCF_MOUSE_AUTOCAPTURE) != 0)
            {
                hitTest = HitTestValues.HTCLIENT;
            }

            if (window == IntPtr.Zero)
            {
                return;
            }

            var info = new WINDOWINFO();

            info.cbSize = (uint)Marshal.SizeOf(info);
            if (!NativeMethods.GetWindowInfo(window, ref info))
            {
                return;
            }

            var    screenCursorPos = MAKELPARAM(p.X, p.Y);
            IntPtr clientCursorPos;

            //if (hitTest == HitTestValues.HTCLIENT)
            //  {
            if ((GetWindowClassFlags(window) & WindowPrintTypes.WCF_MOUSE_CLIENT_TO_SCREEN) ==
                WindowPrintTypes.WCF_MOUSE_CLIENT_TO_SCREEN)
            {
                clientCursorPos = screenCursorPos;
            }
            else
            {
                clientCursorPos = MAKELPARAM(p.X - info.rcClient.Left, p.Y - info.rcClient.Top);
            }
            // }
            // else
            //    clientCursorPos = IntPtr.Zero;

            if (mouseAction == RemoteDesktopMouseAction.LeftDown)
            {
                MouseEvent(window, info, hitTest, WM.LBUTTONDOWN, WM.NCLBUTTONDOWN, clientCursorPos, screenCursorPos);
            }
            if (mouseAction == RemoteDesktopMouseAction.LeftUp)
            {
                MouseEvent(window, info, hitTest, WM.LBUTTONUP, WM.NCLBUTTONUP, clientCursorPos, screenCursorPos);
            }
            //SetForegroundWindow(result.Key.Handle);

            /*
             * NativeMethods.SendMessage(handle, (uint) (isMouseDown ? (leftMouseButton ? WM.LBUTTONDOWN : WM.RBUTTONDOWN) : (leftMouseButton ? WM.LBUTTONUP : WM.RBUTTONUP)),
             *  (IntPtr) MK_LBUTTON,
             *  (IntPtr) ((controlY << 16) | (controlX & 0xFFFF)));
             * /*
             * NativeMethods.PostMessage(new HandleRef(null, handle), (uint) WM.LBUTTONUP,
             *  IntPtr.Zero,
             *  (IntPtr) ((controlY << 16) | (controlX & 0xFFFF)));*/

            //if (handle != result.Key.Handle)
            //   NativeMethods.SendMessage(result.Key.Handle, (uint) WM.PARENTNOTIFY, new IntPtr((uint) WM.LBUTTONDOWN),
            //    MAKELPARAM(windowX, windowY));

            /*NativeMethods.PostMessage(new HandleRef(null, handle), WM_LBUTTONUP,
             *  (IntPtr) 0x1,
             *  (IntPtr) ((y << 16) | (x & 0xFFFF)));*/
        }
Ejemplo n.º 21
0
 static bool IsDesktopVisible()
 {
     IntPtr hWnd = GetWindow(GetWindow(FindWindow("Progman", "Program Manager"), GetWindow_Cmd.GW_CHILD), GetWindow_Cmd.GW_CHILD);
     WINDOWINFO info = new WINDOWINFO();
     info.cbSize = (uint)Marshal.SizeOf(info);
     GetWindowInfo(hWnd, ref info);
     return (info.dwStyle & 0x10000000) == 0x10000000;
 }
Ejemplo n.º 22
0
        private void MouseEvent(IntPtr window, WINDOWINFO windowinfo, HitTestValues hitTest, WM message, WM ncMessage, IntPtr clientCursorPos, IntPtr screenCursorPos)
        {
            if (message == WM.LBUTTONDOWN || message == WM.MBUTTONDOWN || message == WM.RBUTTONDOWN)
            {
                var topParent = GetAncestor(window, GetAncestorFlags.GetRoot);

                if (topParent != _lastWindow)
                {
                    IntPtr        result;
                    MouseActivate mouseActivateResult;
                    if (
                        SendMessageTimeout(window, (uint)WM.MOUSEACTIVATE, topParent,
                                           MAKELPARAM((int)hitTest, (int)message),
                                           SendMessageTimeoutFlags.SMTO_ABORTIFHUNG | SendMessageTimeoutFlags.SMTO_NORMAL, 100,
                                           out result) != IntPtr.Zero &&
                        (((mouseActivateResult = (MouseActivate)result) == MouseActivate.MA_ACTIVATEANDEAT) ||
                         mouseActivateResult == MouseActivate.MA_NOACTIVATEANDEAT))
                    {
                        return;
                    }

                    NativeMethods.SetWindowPos(topParent, new IntPtr(HWND_TOPMOST), 0, 0, 0, 0,
                                               SetWindowPosFlags.IgnoreMove | SetWindowPosFlags.IgnoreResize | SetWindowPosFlags.ShowWindow);
                    _lastWindow = topParent;
                }
            }

            NativeMethods.PostMessage(new HandleRef(null, window), WM.SETCURSOR, window,
                                      MAKELPARAM((int)hitTest, (int)message));

            if (hitTest == HitTestValues.HTCLIENT)
            {
                NativeMethods.PostMessage(new HandleRef(null, window), message, (IntPtr)MK_LBUTTON, clientCursorPos);
                return;
            }

            SysCommands command = 0;

            switch (hitTest)
            {
            case HitTestValues.HTSYSMENU:
                if (ncMessage == WM.NCLBUTTONDBLCLK)
                {
                    command = SysCommands.SC_CLOSE;
                }
                else if (ncMessage == WM.NCRBUTTONUP || ncMessage == WM.NCLBUTTONDOWN)
                {
                    command = (SysCommands)0xFFFF;
                }
                break;

            case HitTestValues.HTMINBUTTON:
                if (ncMessage == WM.NCLBUTTONUP)
                {
                    if (((WindowStyles)windowinfo.dwStyle & WindowStyles.WS_MINIMIZEBOX) != 0)
                    {
                        command = SysCommands.SC_MINIMIZE;
                    }
                }
                else if (ncMessage == WM.NCRBUTTONUP)
                {
                    command = (SysCommands)0xFFFF;
                }
                break;

            case HitTestValues.HTMAXBUTTON:
                if (ncMessage == WM.NCLBUTTONUP)
                {
                    if (((WindowStyles)windowinfo.dwStyle & WindowStyles.WS_MAXIMIZEBOX) != 0)
                    {
                        command = ((WindowStyles)windowinfo.dwStyle & WindowStyles.WS_MAXIMIZE) == 0
                                ? SysCommands.SC_MAXIMIZE
                                : SysCommands.SC_RESTORE;
                    }
                }
                else if (ncMessage == WM.NCRBUTTONUP)
                {
                    command = (SysCommands)0xFFFF;
                }
                break;

            case HitTestValues.HTCLOSE:
                if (ncMessage == WM.NCLBUTTONUP)
                {
                    command = SysCommands.SC_CLOSE;
                }
                else if (ncMessage == WM.NCRBUTTONUP)
                {
                    command = (SysCommands)0xFFFF;
                }
                break;

            case HitTestValues.HTHELP:
                if (ncMessage == WM.NCLBUTTONUP)
                {
                    command = SysCommands.SC_CONTEXTHELP;
                }
                else if (ncMessage == WM.NCRBUTTONUP)
                {
                    command = (SysCommands)0xFFFF;
                }
                break;

            case HitTestValues.HTMENU:
                if (ncMessage == WM.NCLBUTTONDOWN)
                {
                    NativeMethods.PostMessage(new HandleRef(null, window), (WM)VncMessage, (IntPtr)VMW_EXECUTE_MENU, IntPtr.Zero);
                }
                else if (ncMessage == WM.NCMOUSEMOVE)
                {
                    NativeMethods.PostMessage(new HandleRef(null, window), (WM)VncMessage, (IntPtr)VMW_HILITE_MENU, IntPtr.Zero);
                }
                break;

            case HitTestValues.HTCAPTION:
                if (ncMessage == WM.NCLBUTTONDBLCLK)
                {
                    NativeMethods.PostMessage(new HandleRef(null, window), ncMessage, (IntPtr)hitTest, clientCursorPos);
                }
                else if (ncMessage == WM.NCRBUTTONUP)
                {
                    command = (SysCommands)0xFFFF;
                }
                break;

            default:
                NativeMethods.PostMessage(new HandleRef(null, window),
                                          message,
                                          (IntPtr)MK_LBUTTON, clientCursorPos);
                NativeMethods.PostMessage(new HandleRef(null, window), ncMessage, (IntPtr)hitTest, screenCursorPos);
                break;
            }

            if (command != 0)
            {
                if (command == (SysCommands)0xFFFF)
                {
                    NativeMethods.PostMessage(new HandleRef(null, window), WM.CONTEXTMENU, (IntPtr)command, clientCursorPos);
                }
                else
                {
                    NativeMethods.PostMessage(new HandleRef(null, window), WM.SYSCOMMAND, (IntPtr)command, clientCursorPos);
                }
            }
        }
Ejemplo n.º 23
0
 public static extern bool GetWindowInfo(int hwnd, ref WINDOWINFO info);
Ejemplo n.º 24
0
        public void DoMouseAction(RemoteDesktopMouseAction mouseAction, int x, int y, int extra, long windowHandle)
        {
            var handle = (IntPtr)windowHandle;

            var windowinfo = new WINDOWINFO(true);

            NativeMethods.GetWindowInfo(handle, ref windowinfo);

            RECT windowRect;

            NativeMethods.GetWindowRect(handle, out windowRect);

            var screenX = windowRect.X + x;
            var screenY = windowRect.Y + y;

            var hitTest = HitTestValues.HTNOWHERE;
            var window  = WindowFromPoint(new Point(screenX, screenY), 100, ref hitTest, IntPtr.Zero);

            if (hitTest >= HitTestValues.HTSIZEFIRST && hitTest <= HitTestValues.HTSIZELAST)
            {
                var style = (WindowStyles)GetWindowLong(window, GWL_STYLE);
                if ((style & WindowStyles.WS_CHILD) == WindowStyles.WS_CHILD && !StyleHaveSizeBorders(style))
                {
                    var parent = GetParent(window);
                    if (parent != IntPtr.Zero)
                    {
                        window = parent;
                    }
                }
            }

            if ((GetWindowClassFlags(window) & WindowPrintTypes.WCF_MOUSE_AUTOCAPTURE) != 0)
            {
                hitTest = HitTestValues.HTCLIENT;
            }

            if (window == IntPtr.Zero)
            {
                return;
            }

            var info = new WINDOWINFO();

            info.cbSize = (uint)Marshal.SizeOf(info);
            if (!NativeMethods.GetWindowInfo(window, ref info))
            {
                return;
            }

            var    screenCursorPos = MAKELPARAM(screenX, screenY);
            IntPtr clientCursorPos;

            //if (hitTest == HitTestValues.HTCLIENT)
            //  {
            if ((GetWindowClassFlags(window) & WindowPrintTypes.WCF_MOUSE_CLIENT_TO_SCREEN) ==
                WindowPrintTypes.WCF_MOUSE_CLIENT_TO_SCREEN)
            {
                clientCursorPos = screenCursorPos;
            }
            else
            {
                clientCursorPos = MAKELPARAM(screenX - info.rcClient.Left, screenY - info.rcClient.Top);
            }

            WM windowMessage;
            WM ncWindowMessage;

            switch (mouseAction)
            {
            case RemoteDesktopMouseAction.LeftDown:
                windowMessage   = WM.LBUTTONDOWN;
                ncWindowMessage = WM.NCLBUTTONDOWN;
                break;

            case RemoteDesktopMouseAction.LeftUp:
                windowMessage   = WM.LBUTTONUP;
                ncWindowMessage = WM.NCLBUTTONUP;
                break;

            case RemoteDesktopMouseAction.RightDown:
                windowMessage   = WM.RBUTTONDOWN;
                ncWindowMessage = WM.NCRBUTTONDOWN;
                break;

            case RemoteDesktopMouseAction.RightUp:
                windowMessage   = WM.RBUTTONUP;
                ncWindowMessage = WM.NCRBUTTONDOWN;
                break;

            case RemoteDesktopMouseAction.MiddleDown:
                windowMessage   = WM.MBUTTONDOWN;
                ncWindowMessage = WM.NCMBUTTONDOWN;
                break;

            case RemoteDesktopMouseAction.MiddleUp:
                windowMessage   = WM.MBUTTONUP;
                ncWindowMessage = WM.NCMBUTTONUP;
                break;

            case RemoteDesktopMouseAction.XButton1Down:
                windowMessage   = WM.XBUTTONDOWN;
                ncWindowMessage = WM.NCXBUTTONDOWN;
                break;

            case RemoteDesktopMouseAction.XButton1Up:
                windowMessage   = WM.XBUTTONUP;
                ncWindowMessage = WM.NCXBUTTONUP;
                break;

            case RemoteDesktopMouseAction.XButton2Down:
            case RemoteDesktopMouseAction.XButton2Up:
                return;

            case RemoteDesktopMouseAction.Move:
                windowMessage   = WM.MOUSEMOVE;
                ncWindowMessage = WM.NCMOUSEMOVE;
                break;

            case RemoteDesktopMouseAction.Wheel:
                return;

            default:
                throw new ArgumentOutOfRangeException(nameof(mouseAction), mouseAction, null);
            }

            MouseEvent(window, windowinfo, hitTest, windowMessage, ncWindowMessage, clientCursorPos, screenCursorPos);
        }
            private bool FileDialogEnumWindowCallBack(IntPtr hwnd, int lParam)
            {
                StringBuilder className = new StringBuilder(256);

                NativeMethods.GetClassName(new HandleRef(this, hwnd), className, className.Capacity);
                int        controlID = NativeMethods.GetDlgCtrlID(hwnd);
                WINDOWINFO windowInfo;

                NativeMethods.GetWindowInfo(new HandleRef(this, hwnd), out windowInfo);

                // Dialog Window
                if (className.ToString().StartsWith("#32770"))
                {
                    _BaseDialogNative = new MSFileDialogWrapper(_CustomControl);
                    _BaseDialogNative.AssignHandle(hwnd);
                    return(true);
                }

                switch ((ControlsId)controlID)
                {
                case ControlsId.DefaultView:
                    _CustomControl._hListViewPtr = hwnd;
                    NativeMethods.GetWindowInfo(new HandleRef(this, hwnd), out _ListViewInfo);
                    _CustomControl.UpdateListView();
                    break;

                case ControlsId.ComboFolder:
                    _ComboFolders     = hwnd;
                    _ComboFoldersInfo = windowInfo;
                    break;

                /*case ControlsId.ComboFileType:
                 *  _hComboExtensions = hwnd;
                 *  _ComboExtensionsInfo = windowInfo;
                 *  break;*/
                case ControlsId.ComboFileName:
                    if (className.ToString().ToLower() == "comboboxex32")
                    {
                        _hComboFileName    = hwnd;
                        _ComboFileNameInfo = windowInfo;
                    }
                    break;

                case ControlsId.GroupFolder:
                    _hGroupButtons    = hwnd;
                    _GroupButtonsInfo = windowInfo;
                    break;

                case ControlsId.LeftToolBar:
                    _hToolBarFolders    = hwnd;
                    _ToolBarFoldersInfo = windowInfo;
                    break;

                case ControlsId.ButtonOk:
                    _hOKButton                = hwnd;
                    _OKButtonInfo             = windowInfo;
                    _CustomControl._hOKButton = hwnd;
                    //Win32Types.NativeMethods.EnableWindow(_hOKButton, false);
                    break;

                case ControlsId.ButtonCancel:
                    _hCancelButton    = hwnd;
                    _CancelButtonInfo = windowInfo;
                    break;

                case ControlsId.ButtonHelp:
                    _hHelpButton    = hwnd;
                    _HelpButtonInfo = windowInfo;
                    break;

                case ControlsId.CheckBoxReadOnly:
                    _hChkReadOnly    = hwnd;
                    _ChkReadOnlyInfo = windowInfo;
                    break;

                case ControlsId.LabelFileName:
                    _hLabelFileName    = hwnd;
                    _LabelFileNameInfo = windowInfo;
                    break;

                case ControlsId.LabelFileType:
                    _hLabelFileType    = hwnd;
                    _LabelFileTypeInfo = windowInfo;
                    break;
                }

                return(true);
            }
Ejemplo n.º 26
0
 internal static extern bool GetWindowInfo(HandleRef hwnd, out WINDOWINFO pwi);
Ejemplo n.º 27
0
        public void HandleNCCalcsize(IntPtr wParam, IntPtr lParam)
        {
            // lParam is an [in, out] that can be either a RECT* (wParam == FALSE) or an NCCALCSIZE_PARAMS*.
            // Since the first field of NCCALCSIZE_PARAMS is a RECT and is the only field we care about
            // we can unconditionally treat it as a RECT.

            /* DefWindowProc must be called in both the maximized and non-maximized
             * cases, otherwise tile/cascade windows won't work */

            var nonclient = (RECT)Marshal.PtrToStructure(lParam, typeof(RECT));

            DefWindowProcW(_framelessInfo.Handle, WM.NCCALCSIZE, wParam, lParam);
            var client = (RECT)Marshal.PtrToStructure(lParam, typeof(RECT));

            if (IsMaximized(_framelessInfo.Handle))
            {
                WINDOWINFO wi = new WINDOWINFO(null);
                GetWindowInfo(_framelessInfo.Handle, ref wi);

                /* Maximized windows always have a non-client border that hangs over
                 * the edge of the screen, so the size proposed by WM_NCCALCSIZE is
                 * fine. Just adjust the top border to remove the window title. */
                var rect = new RECT();
                rect.left   = client.left;
                rect.top    = (int)(nonclient.top + wi.cyWindowBorders);
                rect.right  = client.right;
                rect.bottom = client.bottom;

                IntPtr         mon = MonitorFromWindow(_framelessInfo.Handle, MONITOR.DEFAULTTOPRIMARY);
                MONITORINFOEXW mi  = new MONITORINFOEXW(null);
                GetMonitorInfoW(mon, ref mi);

                /* If the client rectangle is the same as the monitor's rectangle,
                 * the shell assumes that the window has gone fullscreen, so it removes
                 * the topmost attribute from any auto-hide appbars, making them
                 * inaccessible. To avoid this, reduce the size of the client area by
                 * one pixel on a certain edge. The edge is chosen based on which side
                 * of the monitor is likely to contain an auto-hide appbar, so the
                 * missing client area is covered by it. */
                if (rect.AreEqual(mi.rcMonitor))
                {
                    if (HasAutohideAppbar(ABE_BOTTOM, mi.rcMonitor))
                    {
                        rect.bottom--;
                    }

                    else if (HasAutohideAppbar(ABE_LEFT, mi.rcMonitor))
                    {
                        rect.left++;
                    }

                    else if (HasAutohideAppbar(ABE_TOP, mi.rcMonitor))
                    {
                        rect.top++;
                    }

                    else if (HasAutohideAppbar(ABE_RIGHT, mi.rcMonitor))
                    {
                        rect.right--;
                    }
                }

                Marshal.StructureToPtr(rect, lParam, false);
            }
            else
            {
                /* For the non-maximized case, set the output RECT to what it was
                 * before WM_NCCALCSIZE modified it. This will make the client size the
                 * same as the non-client size. */
                Marshal.StructureToPtr(nonclient, lParam, false);
            }
        }
Ejemplo n.º 28
0
 public static extern int GetWindowInfo(IntPtr hWnd, ref WINDOWINFO pwi);
Ejemplo n.º 29
0
 public static extern bool GetWindowInfo(IntPtr hWnd, out WINDOWINFO pwi);
Ejemplo n.º 30
0
 public static extern bool GetWindowInfo(HandleRef hwnd, ref WINDOWINFO pwi);
Ejemplo n.º 31
0
        public IntPtr NCPaint(IntPtr region)
        {
            IntPtr hDC = GetWindowDC(this.Handle);

            if (hDC != IntPtr.Zero)
            {
                Graphics grTemp = Graphics.FromHdc(hDC);

                int ScrollBarWidth  = SystemInformation.VerticalScrollBarWidth;
                int ScrollBarHeight = SystemInformation.HorizontalScrollBarHeight;

                WINDOWINFO wi = new WINDOWINFO();
                wi.cbSize = (uint)Marshal.SizeOf(wi);

                //得到当前控件的窗口信息
                GetWindowInfo(Handle, ref wi);

                wi.rcClient.Right--;
                wi.rcClient.Bottom--;


                //获得当前控件的区域
                Region UpdateRegion = new Region(new Rectangle(wi.rcWindow.Top, wi.rcWindow.Left, wi.rcWindow.Right - wi.rcWindow.Left, wi.rcWindow.Bottom - wi.rcWindow.Top));

                //获得客户区以外的区域
                UpdateRegion.Exclude(new Rectangle(wi.rcClient.Top, wi.rcClient.Left, wi.rcClient.Right - wi.rcClient.Left, wi.rcClient.Bottom - wi.rcClient.Top));

                //if (IsHScrollVisible && IsVScrollVisible)
                //{
                //    UpdateRegion.Exclude(Rectangle.FromLTRB
                //            (wi.rcClient.Right + 2, wi.rcClient.Bottom + 2,
                //            wi.rcWindow.Right, wi.rcWindow.Bottom));
                //}

                //得到当前区域的句柄
                IntPtr hRgn = UpdateRegion.GetHrgn(grTemp);

                //For Painting we need to zero offset the Rectangles.
                Rectangle WindowRect = new Rectangle(wi.rcWindow.Top, wi.rcWindow.Left, wi.rcWindow.Right - wi.rcWindow.Left, wi.rcWindow.Bottom - wi.rcWindow.Top);

                Point offset = Point.Empty - (Size)WindowRect.Location;

                WindowRect.Offset(offset);

                Rectangle ClientRect = WindowRect;

                ClientRect.Inflate(-1, -1);

                //Fill the BorderArea
                Region PaintRegion = new Region(WindowRect);
                PaintRegion.Exclude(ClientRect);
                grTemp.FillRegion(SystemBrushes.Control, PaintRegion);

                //Adjust ClientRect for Drawing Border.
                ClientRect.Inflate(1, 1);
                ClientRect.Width--;
                ClientRect.Height--;

                //Draw Outer Raised Border
                //ControlPaint.DrawBorder3D(grTemp, WindowRect, Border3DStyle.Raised,
                //Border3DSide.Bottom | Border3DSide.Left | Border3DSide.Right | Border3DSide.Top);
                WindowRect.Width--;
                WindowRect.Height--;
                grTemp.DrawRectangle(_borderPen, WindowRect);

                //Draw Inner Sunken Border
                //ControlPaint.DrawBorder3D(grTemp, ClientRect, Border3DStyle.Sunken,
                //Border3DSide.Bottom | Border3DSide.Left | Border3DSide.Right | Border3DSide.Top);

                ReleaseDC(Handle, hDC);

                grTemp.Dispose();

                return(hRgn);
            }
            return(region);
        }
Ejemplo n.º 32
0
		protected extern static bool GetWindowInfo(
			IntPtr hWnd,
			out WINDOWINFO pwi);
Ejemplo n.º 33
0
 public static Screen GetScreenFromWindow(IntPtr windowHandle)
 {
     WINDOWINFO windowinfo = new WINDOWINFO { cbSize = (uint)Marshal.SizeOf(typeof(WINDOWINFO)) };
     GetWindowInfo(windowHandle, ref windowinfo);
     return Screen.FromRectangle(windowinfo.rcWindow.ToRectangle());
 }
Ejemplo n.º 34
0
		/// <summary>
		/// Retrieves the position and dimensions of a specified window
		/// </summary>
		/// <param name="hwnd">Window handle</param>
		/// <returns>Returns a rectangle object describing the client area</returns>
		public static Rectangle GetWindowClientRect(IntPtr hwnd)
		{
			if (hwnd == IntPtr.Zero)
				return System.Drawing.Rectangle.Empty;

			WINDOWINFO wi = new WINDOWINFO();

			if (GetWindowInfo(hwnd, out wi))
			{
				Rectangle rect = new Rectangle(
					wi.rcClient.left,
					wi.rcClient.top,
					wi.rcClient.right - wi.rcClient.left,
					wi.rcClient.bottom - wi.rcClient.top);

				return rect;
			}

			return System.Drawing.Rectangle.Empty;
		}
        private WindowSnap(IntPtr hWnd, bool specialCapturing)
        {
            this.isIconic = IsIconic(hWnd);
            this.hWnd = hWnd;

            if (specialCapturing)
                EnterSpecialCapturing(hWnd);

            #region Child Support (Enter)

            WINDOWINFO wInfo = new WINDOWINFO();
            wInfo.cbSize = WINDOWINFO.GetSize();
            GetWindowInfo(hWnd, ref wInfo);

            bool isChild = false;
            IntPtr parent = GetParent(hWnd);
            Rectangle pos = new Rectangle();
            Rectangle parentPos = new Rectangle();

            if (forceMDI && parent != IntPtr.Zero && (wInfo.dwExStyle & ExtendedWindowStyles.WS_EX_MDICHILD) == ExtendedWindowStyles.WS_EX_MDICHILD
                //&& (
                //(wInfo.dwStyle & WindowStyles.WS_CHILDWINDOW) == WindowStyles.WS_CHILDWINDOW||
                //(wInfo.dwStyle & WindowStyles.WS_CHILD) == WindowStyles.WS_CHILD)
                )//added 10 october 2007

            {
                StringBuilder name = new StringBuilder();
                GetClassName(parent, name, RUNDLL.Length + 1);
                if (name.ToString() != RUNDLL)
                {
                    isChild = true;
                    pos = GetWindowPlacement(hWnd);
                    MoveWindow(hWnd, int.MaxValue, int.MaxValue, pos.Width, pos.Height, true);

                    SetParent(hWnd, IntPtr.Zero);

                    parentPos = GetWindowPlacement(parent);
                }
            }
            #endregion

            Rectangle rect = GetWindowPlacement(hWnd);

            this.size = rect.Size;
            this.location = rect.Location;
            this.text = GetWindowText(hWnd);
            this.image = GetWindowImage(hWnd, this.size);

            #region Child Support (Exit)

            if (isChild)
            {
                SetParent(hWnd, parent);

                //int x = pos.X - parentPos.X;
                //int y = pos.Y - parentPos.Y;

                int x = wInfo.rcWindow.Left - parentPos.X;
                int y = wInfo.rcWindow.Top - parentPos.Y;

                if ((wInfo.dwStyle & WindowStyles.WS_THICKFRAME) == WindowStyles.WS_THICKFRAME)
                {
                    x -= SystemInformation.Border3DSize.Width;
                    y -= SystemInformation.Border3DSize.Height;
                }

                MoveWindow(hWnd, x, y, pos.Width, pos.Height, true);
            }
            #endregion

            if (specialCapturing)
                ExitSpecialCapturing(hWnd);
        }
Ejemplo n.º 36
0
        private WindowSnap(IntPtr hWnd, bool specialCapturing)
        {
            this.isIconic = IsIconic(hWnd);
            this.hWnd     = hWnd;

            if (specialCapturing)
            {
                EnterSpecialCapturing(hWnd);
            }

            #region Child Support (Enter)

            WINDOWINFO wInfo = new WINDOWINFO();
            wInfo.cbSize = WINDOWINFO.GetSize();
            GetWindowInfo(hWnd, ref wInfo);

            bool      isChild   = false;
            IntPtr    parent    = GetParent(hWnd);
            Rectangle pos       = new Rectangle();
            Rectangle parentPos = new Rectangle();

            if (forceMDI && parent != IntPtr.Zero && (wInfo.dwExStyle & ExtendedWindowStyles.WS_EX_MDICHILD) == ExtendedWindowStyles.WS_EX_MDICHILD
                //&& (
                //(wInfo.dwStyle & WindowStyles.WS_CHILDWINDOW) == WindowStyles.WS_CHILDWINDOW||
                //(wInfo.dwStyle & WindowStyles.WS_CHILD) == WindowStyles.WS_CHILD)
                )//added 10 october 2007

            {
                StringBuilder name = new StringBuilder();
                GetClassName(parent, name, RUNDLL.Length + 1);
                if (name.ToString() != RUNDLL)
                {
                    isChild = true;
                    pos     = GetWindowPlacement(hWnd);
                    MoveWindow(hWnd, int.MaxValue, int.MaxValue, pos.Width, pos.Height, true);

                    SetParent(hWnd, IntPtr.Zero);

                    parentPos = GetWindowPlacement(parent);
                }
            }
            #endregion

            Rectangle rect = GetWindowPlacement(hWnd);

            this.size     = rect.Size;
            this.location = rect.Location;
            this.text     = GetWindowText(hWnd);
            this.image    = GetWindowImage(hWnd, this.size);

            #region Child Support (Exit)

            if (isChild)
            {
                SetParent(hWnd, parent);

                //int x = pos.X - parentPos.X;
                //int y = pos.Y - parentPos.Y;

                int x = wInfo.rcWindow.Left - parentPos.X;
                int y = wInfo.rcWindow.Top - parentPos.Y;

                if ((wInfo.dwStyle & WindowStyles.WS_THICKFRAME) == WindowStyles.WS_THICKFRAME)
                {
                    x -= SystemInformation.Border3DSize.Width;
                    y -= SystemInformation.Border3DSize.Height;
                }

                MoveWindow(hWnd, x, y, pos.Width, pos.Height, true);
            }
            #endregion

            if (specialCapturing)
            {
                ExitSpecialCapturing(hWnd);
            }
        }
Ejemplo n.º 37
0
 public static extern bool GetWindowInfo(HandleRef hwnd, ref WINDOWINFO pwi);
Ejemplo n.º 38
0
        /// <summary>
        /// The hook procedure for window messages generated by the FileOpenDialog
        /// </summary>
        /// <param name="hWnd">the handle of the window at which this message is targeted</param>
        /// <param name="msg">the message identifier</param>
        /// <param name="wParam">message-specific parameter data</param>
        /// <param name="lParam">mess-specific parameter data</param>
        /// <returns></returns>
        public IntPtr MyHookProc(IntPtr hWnd, UInt32 msg, Int32 wParam, Int32 lParam)
        {
            try
            {
                if (hWnd == IntPtr.Zero)
                {
                    return(IntPtr.Zero);
                }

                switch (msg)
                {
                // We're not interested in every possible message; just return a NULL for those we don't care about
                default:
                {
                    return(IntPtr.Zero);
                }

                // WM_INITDIALOG - at this point the OpenFileDialog exists, so we pull the user-supplied control
                // into the FileOpenDialog now, using the SetParent API.
                case WM.INITDIALOG:
                {
                    _hWndParent = User32.GetParent(hWnd);

                    //setting a bool for whether the OS is RTL (not the installed language of WLW)
                    IsRTL = (User32.GetWindowLong(_hWndParent, User32.GWL_EXSTYLE) & User32.WS_EX_LAYOUTRTL) > 0;

                    //account for large title bar, borders for adjusting control locations
                    TITLEBARINFO titleBarInfo = new TITLEBARINFO();
                    titleBarInfo.cbSize = (uint)Marshal.SizeOf(titleBarInfo);
                    if (!User32.GetTitleBarInfo(_hWndParent, ref titleBarInfo))
                    {
                        throw new Win32Exception(Marshal.GetLastWin32Error());
                    }

                    WINDOWINFO info = new WINDOWINFO();
                    info.cbSize = (uint)Marshal.SizeOf(info);
                    if (!User32.GetWindowInfo(_hWndParent, ref info))
                    {
                        throw new Win32Exception(Marshal.GetLastWin32Error());
                    }

                    _extraWindowHeight = (titleBarInfo.rcTitleBar.bottom - titleBarInfo.rcTitleBar.top) + 2 * (int)info.cyWindowBorders;
                    _extraWindowWidth  = 2 * (int)info.cxWindowBorders;

                    Rectangle rcClient = new Rectangle(0, 0, 0, 0);
                    // Get client rectangle of dialog
                    RECT rcTemp = new RECT();
                    User32.GetWindowRect(_hWndParent, ref rcTemp);
                    rcClient.X      = rcTemp.left;
                    rcClient.Y      = rcTemp.top;
                    rcClient.Width  = rcTemp.Width;
                    rcClient.Height = rcTemp.Height + TABS_HEIGHT + BUTTONS_HEIGHT;
                    //make the dialog box bigger
                    User32.MoveWindow(_hWndParent, rcClient.Left, rcClient.Top, rcClient.Width, rcClient.Height, true);
                    //move all the controls down
                    AdjustControlLocations();
                    //top tab control
                    mainTabControl = new LightweightControlContainerControl();
                    User32.SetParent(mainTabControl.Handle, _hWndParent);
                    mainTabControl.Location = new Point(0, 0);
                    mainTabControl.Anchor   = AnchorStyles.Left | AnchorStyles.Right;
                    mainTabControl.Size     = new Size(rcClient.Width, TABS_HEIGHT);

                    tabs = new TabLightweightControl();
                    tabs.ColorizeBorder = false;
                    tabs.VirtualBounds  = new Rectangle(0, 0, rcClient.Width, TABS_HEIGHT);
                    tabs.LightweightControlContainerControl = mainTabControl;
                    tabs.DrawSideAndBottomTabPageBorders    = false;

                    InsertImageTabControl tabFromFile = new InsertImageTabControl();
                    tabFromFile.TabText   = Res.Get(StringId.InsertImageInsertFromFile);
                    tabFromFile.TabBitmap = ResourceHelper.LoadAssemblyResourceBitmap("ImageInsertion.Images.TabInsertFromFile.png");
                    tabFromFile.BackColor = SystemColors.Control;
                    User32.SetParent(tabFromFile.Handle, _hWndParent);
                    tabs.SetTab(0, tabFromFile);

                    mainTabControl.BackColor = tabFromFile.ApplicationStyle.InactiveTabTopColor;

                    //now, add tabs for the other controls
                    int i = 1;
                    foreach (InsertImageSource imageSource in imageSources)
                    {
                        InsertImageTabControl tab = new InsertImageTabControl();
                        tab.TabText   = imageSource.TabName;
                        tab.TabBitmap = imageSource.TabBitmap;
                        tab.BackColor = SystemColors.Control;
                        tabs.SetTab(i++, tab);
                    }

                    tabs.SelectedTabNumberChanged += new EventHandler(tabs_SelectedTabNumberChanged);

                    //set the keyboard hook for tab switching
                    tabKeyboardHook = new TabbingHookProc(tabs);
                    tabKeyboardHook.Install(_hWndParent);

                    //add other image source panels
                    _panelImage             = new Panel();
                    _panelImage.Location    = new Point(0, mainTabControl.Size.Height);
                    _panelImage.BorderStyle = BorderStyle.None;
                    _panelImage.Anchor      = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top | AnchorStyles.Bottom;
                    _panelImage.Size        = new Size(rcClient.Width, rcClient.Height - TABS_HEIGHT - BUTTONS_HEIGHT - _extraWindowHeight);
                    _panelImage.Visible     = false;

                    User32.SetParent(_panelImage.Handle, _hWndParent);

                    //initalize the other sources
                    foreach (InsertImageSource source in imageSources)
                    {
                        source.Init(_panelImage.Width, _panelImage.Height);
                        Control c = source.ImageSelectionControls;
                        DisplayHelper.Scale(c);
                        foreach (Control childControl in c.Controls)
                        {
                            DisplayHelper.Scale(childControl);
                        }
                    }
                    DisplayHelper.Scale(_panelImage);

                    //special cancel button
                    _buttonPanel             = new Panel();
                    _buttonPanel.Location    = new Point(rcClient.Width - (int)(0.5 * _extraWindowWidth) - _buttonPanel.Width, _panelImage.Bounds.Bottom);
                    _buttonPanel.Size        = new Size(75, 23);
                    _buttonPanel.BorderStyle = BorderStyle.None;

                    _cancelButton           = new Button();
                    _cancelButton.TextAlign = ContentAlignment.MiddleCenter;
                    if (BidiHelper.IsRightToLeft)
                    {
                        _cancelButton.RightToLeft = RightToLeft.Yes;
                    }
                    _cancelButton.Text      = Res.Get(StringId.CancelButton);
                    _cancelButton.FlatStyle = FlatStyle.System;
                    _cancelButton.Location  = new Point(0, 0);
                    _cancelButton.Size      = new Size(75, 23);
                    _cancelButton.Click    += new EventHandler(_cancelButton_Click);

                    _buttonPanel.Controls.Add(_cancelButton);

                    User32.SetParent(_buttonPanel.Handle, _hWndParent);

                    int    origWidth = _cancelButton.Width;
                    string tmp       = _cancelButton.Text;
                    _cancelButton.Text = Res.Get(StringId.InsertImageButton);
                    int newWidth = Math.Max(origWidth, DisplayHelper.MeasureButton(_cancelButton));
                    _cancelButton.Text = tmp;
                    newWidth           = Math.Max(newWidth, DisplayHelper.MeasureButton(_cancelButton));

                    _buttonPanel.Width = _cancelButton.Width = newWidth;
                    int deltaX = newWidth - origWidth;
                    _buttonPanel.Left -= deltaX;

                    //fixing up button text and tab order
                    IntPtr hWndOpenButton = User32.GetDlgItem(_hWndParent, _OPEN_BUTTON_ID);
                    User32.SetWindowText(hWndOpenButton, Res.Get(StringId.InsertImageButton));


                    mainTabControl.InitFocusManager();
                    mainTabControl.AddFocusableControls(tabs.GetAccessibleControls());
                    foreach (InsertImageSource tabPage in imageSources)
                    {
                        mainTabControl.AddFocusableControl(tabPage.ImageSelectionControls);
                    }

                    state = STATE.FILE;

                    return(IntPtr.Zero);
                }

                case WM.SIZE:
                {
                    ManipulatePanels();
                    return(IntPtr.Zero);
                }

                // WM_NOTIFY - we're only interested in the CDN_SELCHANGE notification message:
                // we grab the currently-selected filename and copy it into the buffer
                case WM.NOTIFY:
                {
                    IntPtr   ipNotify = new IntPtr(lParam);
                    OfNotify ofNot    = (OfNotify)Marshal.PtrToStructure(ipNotify, typeof(OfNotify));
                    Int16    code     = (short)ofNot.hdr.code;
                    if (code == CommonDlgNotification.SelChange)
                    {
                        UpdateChosenImage(false);
                        //CheckOptions(false);
                    }
                    else if (code == CommonDlgNotification.InitDone)
                    {
                        listener = new CommandListener(_hWndParent, this, (int)User32.GetDlgCtrlID(_cancelButton.Handle));
                    }
                    else if (code == CommonDlgNotification.FileOk)
                    {
                        // update the image path (need to do this if the user selected
                        // a file by simpliy typing in the filepath text box)
                        UpdateChosenImage(true);

                        // ok to insert
                        _insertFile = true;
                    }
                    else if ((code == CommonDlgNotification.FolderChange) && (state == STATE.WEB))
                    {
                        // If the user hits the OK button while there is no valid selection
                        // within the File panel, the file dialog sends a CommonDlgNotification.FolderChange
                        // We use this combined with other relevant state to trigger the closing
                        // of the Image dialog
                        HitOpen();
                    }
                    return(IntPtr.Zero);
                }
                }
            }
            catch (Exception ex)
            {
                UnexpectedErrorMessage.Show(ex);
                return(new IntPtr(1));
            }
            finally
            {
                GC.KeepAlive(this);
            }
        }
 /// <summary>
 /// Useful for finding window with style
 /// </summary>
 /// <param name="hwnd"></param>
 /// <returns></returns>
 public static Int64 GetWindowStyle(IntPtr hwnd)
 {
     var info = new WINDOWINFO();
     info.cbSize = (uint)Marshal.SizeOf(info);
     GetWindowInfo(hwnd, ref info);
     return Convert.ToInt64(info.dwStyle);
 }
Ejemplo n.º 40
0
 public static extern bool GetWindowInfo(IntPtr hWnd, ref WINDOWINFO lpWindowInfo);
Ejemplo n.º 41
0
        public IntPtr NCPaint(IntPtr region)
        {
            IntPtr hDC = GetWindowDC(this.Handle);
            if (hDC != IntPtr.Zero)
            {
                Graphics grTemp = Graphics.FromHdc(hDC);

                int ScrollBarWidth = SystemInformation.VerticalScrollBarWidth;
                int ScrollBarHeight = SystemInformation.HorizontalScrollBarHeight;

                WINDOWINFO wi = new WINDOWINFO();
                wi.cbSize = (uint)Marshal.SizeOf(wi);

                //得到当前控件的窗口信息
                GetWindowInfo(Handle, ref wi);

                wi.rcClient.Right--;
                wi.rcClient.Bottom--;


                //获得当前控件的区域
                Region UpdateRegion = new Region(new Rectangle(wi.rcWindow.Top, wi.rcWindow.Left, wi.rcWindow.Right - wi.rcWindow.Left, wi.rcWindow.Bottom - wi.rcWindow.Top));

                //获得客户区以外的区域
                UpdateRegion.Exclude(new Rectangle(wi.rcClient.Top, wi.rcClient.Left, wi.rcClient.Right - wi.rcClient.Left, wi.rcClient.Bottom - wi.rcClient.Top));

                //if (IsHScrollVisible && IsVScrollVisible)
                //{
                //    UpdateRegion.Exclude(Rectangle.FromLTRB
                //            (wi.rcClient.Right + 2, wi.rcClient.Bottom + 2,
                //            wi.rcWindow.Right, wi.rcWindow.Bottom));
                //}

                //得到当前区域的句柄
                IntPtr hRgn = UpdateRegion.GetHrgn(grTemp);

                //For Painting we need to zero offset the Rectangles.
                Rectangle WindowRect = new Rectangle(wi.rcWindow.Top, wi.rcWindow.Left, wi.rcWindow.Right - wi.rcWindow.Left, wi.rcWindow.Bottom - wi.rcWindow.Top);

                Point offset = Point.Empty - (Size)WindowRect.Location;

                WindowRect.Offset(offset);

                Rectangle ClientRect = WindowRect;

                ClientRect.Inflate(-1, -1);

                //Fill the BorderArea
                Region PaintRegion = new Region(WindowRect);
                PaintRegion.Exclude(ClientRect);
                grTemp.FillRegion(SystemBrushes.Control, PaintRegion);

                //Adjust ClientRect for Drawing Border.
                ClientRect.Inflate(1, 1);
                ClientRect.Width--;
                ClientRect.Height--;

                //Draw Outer Raised Border
                //ControlPaint.DrawBorder3D(grTemp, WindowRect, Border3DStyle.Raised,
                //Border3DSide.Bottom | Border3DSide.Left | Border3DSide.Right | Border3DSide.Top);
                WindowRect.Width--;
                WindowRect.Height--;
                grTemp.DrawRectangle(_borderPen, WindowRect);

                //Draw Inner Sunken Border
                //ControlPaint.DrawBorder3D(grTemp, ClientRect, Border3DStyle.Sunken,
                //Border3DSide.Bottom | Border3DSide.Left | Border3DSide.Right | Border3DSide.Top);

                ReleaseDC(Handle, hDC);

                grTemp.Dispose();

                return hRgn;

            }
            return region;

        }
Ejemplo n.º 42
0
 private static extern bool _GetWindowInfo(IntPtr hwnd, [In][Out] ref WINDOWINFO pwi);
Ejemplo n.º 43
0
        private static int CaptureEnumWindowsExProc(IntPtr hWnd, IntPtr param)
        {
            System.Runtime.InteropServices.GCHandle gch = (System.Runtime.InteropServices.GCHandle)param;
            CarverLabUtility.Win32Wrapper.InternalCallbackParams p = (CarverLabUtility.Win32Wrapper.InternalCallbackParams)gch.Target;
            CarverLabUtility.Win32Wrapper.WINDOWINFO windowinfo = new WINDOWINFO();
            string sWindowText = "", sWindowClass = "";
            System.Text.StringBuilder sbWindowText = new System.Text.StringBuilder(1024);
            System.Text.StringBuilder sbWindowClass = new System.Text.StringBuilder(1024);

            if (IsWindowVisible(hWnd))
            {
                if (!CarverLabUtility.Win32Wrapper.GetWindowInfo(hWnd,out windowinfo))
                {
                    throw new System.ApplicationException("Win32::GetWindowInfo failed.");
                }
                if (CarverLabUtility.Win32Wrapper.GetWindowText(hWnd, sbWindowText,1024) > 0)
                {
                    sWindowText = sbWindowText.ToString();
                }
                if (CarverLabUtility.Win32Wrapper.GetClassName(hWnd,sbWindowClass,1024) > 0)
                {
                    sWindowClass = sbWindowClass.ToString();
                }
                CarverLabUtility.Window window = new CarverLabUtility.Window(hWnd,
                    windowinfo.rcWindow.ToRectangle(),windowinfo.rcClient.ToRectangle(),
                    sWindowText,sWindowClass);
                p.m_This.OnEnumWindowsExReceived(window,p.m_obj);
            }
            return 1;
        }
Ejemplo n.º 44
0
            private bool OpenFileDialogEnumWindowCallBack(IntPtr hwnd, int lParam)
            {
                StringBuilder className = new StringBuilder(256);

                Win32.GetClassName(hwnd, className, className.Capacity);
                int        controlID = Win32.GetDlgCtrlID(hwnd);
                WINDOWINFO windowInfo;

                Win32.GetWindowInfo(hwnd, out windowInfo);

                // Dialog Window
                if (className.ToString().StartsWith("#32770"))
                {
                    mBaseDialogNative = new BaseDialogNative(hwnd);
                    mBaseDialogNative.FileNameChanged   += new BaseDialogNative.FileNameChangedHandler(BaseDialogNative_FileNameChanged);
                    mBaseDialogNative.FolderNameChanged += new BaseDialogNative.FileNameChangedHandler(BaseDialogNative_FolderNameChanged);
                    return(true);
                }

                switch ((ControlsID)controlID)
                {
                case ControlsID.DefaultView:
                    mListViewPtr = hwnd;
                    Win32.GetWindowInfo(hwnd, out mListViewInfo);
                    if (mSourceControl.DefaultViewMode != FolderViewMode.Default)
                    {
                        Win32.SendMessage(mListViewPtr, (int)Msg.WM_COMMAND, (int)mSourceControl.DefaultViewMode, 0);
                    }
                    break;

                case ControlsID.ComboFolder:
                    mComboFolders     = hwnd;
                    mComboFoldersInfo = windowInfo;
                    break;

                case ControlsID.ComboFileType:
                    mComboExtensions     = hwnd;
                    mComboExtensionsInfo = windowInfo;
                    break;

                case ControlsID.ComboFileName:
                    if (className.ToString().ToLower() == "comboboxex32")
                    {
                        mComboFileName     = hwnd;
                        mComboFileNameInfo = windowInfo;
                    }
                    break;

                case ControlsID.GroupFolder:
                    mGroupButtons     = hwnd;
                    mGroupButtonsInfo = windowInfo;
                    break;

                case ControlsID.LeftToolBar:
                    mToolBarFolders     = hwnd;
                    mToolBarFoldersInfo = windowInfo;
                    break;

                case ControlsID.ButtonOpen:
                    mOpenButton     = hwnd;
                    mOpenButtonInfo = windowInfo;
                    break;

                case ControlsID.ButtonCancel:
                    mCancelButton     = hwnd;
                    mCancelButtonInfo = windowInfo;
                    break;

                case ControlsID.ButtonHelp:
                    mHelpButton     = hwnd;
                    mHelpButtonInfo = windowInfo;
                    break;

                case ControlsID.CheckBoxReadOnly:
                    mChkReadOnly     = hwnd;
                    mChkReadOnlyInfo = windowInfo;
                    break;

                case ControlsID.LabelFileName:
                    mLabelFileName     = hwnd;
                    mLabelFileNameInfo = windowInfo;
                    break;

                case ControlsID.LabelFileType:
                    mLabelFileType     = hwnd;
                    mLabelFileTypeInfo = windowInfo;
                    break;
                }

                return(true);
            }
Ejemplo n.º 45
0
 private void HandleScreenshots()
 {
     IntPtr fg = Win32.GetForegroundWindow();
       if (this.Handle != fg && IntPtr.Zero != fg && null != fg) {
     WINDOWINFO info = new WINDOWINFO();
     Win32.GetWindowInfo(fg, ref info);
     RECT r = info.rcWindow;
     Rectangle rectangle = new Rectangle(r.Left, r.Top, r.Right - r.Left, r.Bottom - r.Top);
     if (0 < rectangle.Height && 0 < rectangle.Height) {
       if (fg != LastForegroundWindow) {
     Screenshot = TakeScreenshot(rectangle);
     LastForegroundWindow = fg;
     sent = false;
       }
       if (IsOutOfBounds(rectangle)) {
     if (!sent) {
       sent = true;
       TheState.TransferCenter.SendBitmap(Screenshot);
     }
     Point joint = LayoutStrategy.GetJointPosition();
     rectangle.Offset(-joint.X, -joint.Y);
     TheState.TransferCenter.SendBitmapPosition(rectangle);
       }
       return;
     }
       }
       sent = false;
       Screenshot = null;
       LastForegroundWindow = IntPtr.Zero;
 }
Ejemplo n.º 46
0
 internal static extern int GetWindowInfo(IntPtr hWnd, ref WINDOWINFO info);
Ejemplo n.º 47
0
 public static extern bool GetWindowInfo(IntPtr hwnd, ref WINDOWINFO pwi);
Ejemplo n.º 48
0
        protected override void OnPaintBackground(PaintEventArgs e)
        {
            if (base.BackgroundImage != null)
            {
                Graphics  g          = e.Graphics;
                Rectangle bounds     = new Rectangle(Point.Empty, base.Size);
                Rectangle clientRect = base.ClientRectangle;

                WINDOWINFO info   = GetWindowInfo();
                Point      offset = new Point(
                    info.rcClient.Left - info.rcWindow.Left,
                    info.rcClient.Top - info.rcWindow.Top);

                IntPtr hDC = g.GetHdc();

                try
                {
                    using (ImageDc imageDc = new ImageDc(bounds.Width, bounds.Height))
                    {
                        using (Graphics gDc = Graphics.FromHdc(imageDc.Hdc))
                        {
                            ControlPaintEx.DrawBackgroundImage(
                                gDc,
                                base.BackgroundImage,
                                base.BackColor,
                                base.BackgroundImageLayout,
                                bounds,
                                bounds);
                        }

                        Win32.NativeMethods.BitBlt(
                            hDC,
                            clientRect.X,
                            clientRect.Y,
                            clientRect.Width,
                            clientRect.Height,
                            imageDc.Hdc,
                            offset.X,
                            offset.Y,
                            TernaryRasterOperations.SRCCOPY);
                    }
                }
                catch
                {
                }
                finally
                {
                    g.ReleaseHdc(hDC);
                }
                return;
            }

            if (base.BackColor == Color.Transparent)
            {
                Graphics g   = e.Graphics;
                IntPtr   hDC = g.GetHdc();

                try
                {
                    WINDOWINFO info   = GetWindowInfo();
                    Point      offset = new Point(
                        info.rcClient.Left - info.rcWindow.Left,
                        info.rcClient.Top - info.rcWindow.Top);

                    offset += (Size)base.Location;

                    DrawTransparentBackground(
                        hDC,
                        base.ClientRectangle,
                        offset);
                }
                catch
                {
                }
                finally
                {
                    g.ReleaseHdc(hDC);
                }
                return;
            }

            base.OnPaintBackground(e);
        }