public static Image CaptureWindow(IntPtr handle) { IntPtr hDCSrc = user32.GetWindowDC(handle); user32.RECT windowRect = new user32.RECT(); user32.GetWindowRect(handle, ref windowRect); int width = windowRect.right - windowRect.left; int height = windowRect.bottom - windowRect.top; IntPtr hdcDest = gdi32.CreateCompatibleDC(hDCSrc); IntPtr hBitmap = gdi32.CreateCompatibleBitmap(hDCSrc, width, height); IntPtr hOld = gdi32.SelectObject(hdcDest, hBitmap); gdi32.BitBlt(hdcDest, 0, 0, width, height, hDCSrc, 0, 0, gdi32.SRCCOPY); gdi32.SelectObject(hdcDest, hOld); gdi32.DeleteDC(hdcDest); user32.ReleaseDC(handle, hDCSrc); Image img = Image.FromHbitmap(hBitmap); gdi32.DeleteObject(hBitmap); return(img); }
static void Main(string[] args) { var collection = new List <string>(); var Kader = new user32.RECT(); hWnd = user32.GetDesktopWindow(); StringBuilder strbDeskTitle = new StringBuilder(255); int nLengthd = user32.GetClassName(hWnd, strbDeskTitle, strbDeskTitle.Capacity + 1); string strDeskTitle = strbDeskTitle.ToString(); sClass = strDeskTitle; StringBuilder strbTitle = new StringBuilder(255); int nLength = user32.GetWindowText(hWnd, strbTitle, strbTitle.Capacity + 1); string strTitle = strbTitle.ToString(); sTitle = strTitle; bool retval0 = user32.GetWindowRect(hWnd, out Kader); if (retval0) { rKader = Kader; } System.Console.WriteLine("*******************************************************************************"); System.Console.WriteLine("* *"); System.Console.WriteLine("* FillRect v0.0.1 *"); System.Console.WriteLine("* *"); System.Console.WriteLine("* Fill a rectangle *"); System.Console.WriteLine("* *"); System.Console.WriteLine("* use: FillRect *"); System.Console.WriteLine("* *"); System.Console.WriteLine("* *"); System.Console.WriteLine("* *"); System.Console.WriteLine("* *"); System.Console.WriteLine("* *"); System.Console.WriteLine("* *"); System.Console.WriteLine("* Copyright (c) 2015 Geert-Jan Uijtdewilligen *"); System.Console.WriteLine("* This is free open source software that comes with no warranty, and you are *"); System.Console.WriteLine("* welcome to redistribute it under the terms of the GNU General Public License*"); System.Console.WriteLine("* as published by the Free Software Foundation https://www.gnu.org/licenses/ *"); System.Console.WriteLine("* *"); System.Console.WriteLine("*******************************************************************************"); if (args.Length != 0) { System.Console.WriteLine("Please don't enter arguments."); } else { sLocation = "//"; sLocation = sLocation + hWnd.ToString() + "/"; System.Console.WriteLine(sLocation); System.Console.WriteLine("Title:" + sTitle + " Class:" + sClass + " Left:" + rKader.Left.ToString() + " Right:" + rKader.Right.ToString() + " Top:" + rKader.Top.ToString() + " Bottom:" + rKader.Bottom.ToString() + " "); // This paints a Rect IntPtr wDc = user32.GetWindowDC(hWnd); IntPtr brush = gdi32.CreateSolidBrush((uint)0); gdi32.FillRgn(wDc, gdi32.CreateRectRgn(rKader.Left, rKader.Top, rKader.Right, rKader.Bottom), brush); gdi32.DeleteObject(brush); } }
/// <summary> /// Message handler of the Per_Monitor_DPI_Aware window. The handles the WM_DPICHANGED message and adjusts window size, graphics and text /// based on the DPI of the monitor. The window message provides the new window size (lparam) and new DPI (wparam) /// </summary> protected virtual IntPtr WindowProcedureHook(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) { switch ((user32.WinMessages)msg) { case user32.WinMessages.WM_DPICHANGED: if (IsPerMonitorEnabled) { user32.RECT newRect = (user32.RECT)Marshal.PtrToStructure(lParam, typeof(user32.RECT)); user32.SetWindowPos(hwnd, 0, newRect.Left, newRect.Top, newRect.Right - newRect.Left, newRect.Bottom - newRect.Top, user32.SWP_NOZORDER | user32.SWP_NOOWNERZORDER | user32.SWP_NOACTIVATE); // Set the Window's position & size. //Vector ul = source.CompositionTarget.TransformFromDevice.Transform(new Vector(newRect.Left, newRect.Top)); //Vector hw = source.CompositionTarget.TransformFromDevice.Transform(new Vector(newRect.Right = newRect.Left, newRect.Bottom - newRect.Top)); //Left = ul.X; //Top = ul.Y; //Width = hw.X; //Height = hw.Y; // Remember the current DPI settings. var oldDpi = CurrentDpi; // Get the new DPI settings from wParam CurrentDpi = new DPI(wParam.ToInt32() >> 16, wParam.ToInt32() & 0x0000FFFF); if ((oldDpi.X != CurrentDpi.X) || (oldDpi.Y != CurrentDpi.Y)) { OnDpiChangedInteranl(); } handled = true; } break; } return(IntPtr.Zero); }
static void Main(string[] args) { var collection = new List <string>(); var Kader = new user32.RECT(); var Kader3 = new user32.RECT(); cQuote = Convert.ToChar(34); System.Console.WriteLine("*******************************************************************************"); System.Console.WriteLine("* *"); System.Console.WriteLine("* Child v0.0.1 *"); System.Console.WriteLine("* *"); System.Console.WriteLine("* Lists child windows of desktop windows. *"); System.Console.WriteLine("* *"); System.Console.WriteLine("* use: Child sClass sTitle *"); System.Console.WriteLine("* *"); System.Console.WriteLine("* sClass Classname *"); System.Console.WriteLine("* sTitle Window Title *"); System.Console.WriteLine("* *"); System.Console.WriteLine("* Copyright (c) 2014 Geert-Jan Uijtdewilligen *"); System.Console.WriteLine("* This is free open source software that comes with no warranty, and you are *"); System.Console.WriteLine("* welcome to redistribute it under the terms of the GNU General Public License*"); System.Console.WriteLine("* as published by the Free Software Foundation https://www.gnu.org/licenses/ *"); System.Console.WriteLine("* *"); System.Console.WriteLine("*******************************************************************************"); if (args.Length != 2) { System.Console.WriteLine("Please enter arguments: classname, window title."); } else { sClass = args[0]; sTitle = args[1]; user32.EnumDelegate filter = delegate(IntPtr hWnd, int lParam) { StringBuilder strbTitle = new StringBuilder(255); int nLength = user32.GetWindowText(hWnd, strbTitle, strbTitle.Capacity + 1); string strTitle = strbTitle.ToString(); StringBuilder strbClass = new StringBuilder(255); int cLength = user32.GetClassName(hWnd, strbClass, strbClass.Capacity + 1); string strClass = strbClass.ToString(); if (strClass == sClass && string.IsNullOrEmpty(strClass) == false && strTitle == sTitle) { //bool retval = user32.SetForegroundWindow(hWnd); // Bring window on foreground bool retval2 = user32.GetWindowRect(hWnd, out Kader); collection.Add(" "); collection.Add("Title : " + strTitle); collection.Add("Class : " + strClass); collection.Add("Handle : " + hWnd.ToString()); collection.Add("Return : " + retval2.ToString()); collection.Add("Window Rectangle Top : " + Kader.Top.ToString()); collection.Add("Window Rectangle Bottom : " + Kader.Bottom.ToString()); collection.Add("Window Rectangle Left : " + Kader.Left.ToString()); collection.Add("Window Rectangle Right : " + Kader.Right.ToString()); int iCnt = 1; string sCnt = "000" + iCnt.ToString(); IntPtr hWndChild1 = user32.FindWindowEx(hWnd, IntPtr.Zero, null, IntPtr.Zero); bool retval3 = user32.GetWindowRect(hWndChild1, out Kader3); StringBuilder strbTitle1 = new StringBuilder(255); int nLength1 = user32.GetWindowText(hWndChild1, strbTitle1, strbTitle1.Capacity + 1); string strTitle1 = strbTitle1.ToString(); StringBuilder strbClass1 = new StringBuilder(255); int cLength1 = user32.GetClassName(hWndChild1, strbClass1, strbClass1.Capacity + 1); string strClass1 = strbClass1.ToString(); collection.Add(" "); collection.Add("Child " + sCnt.Substring((sCnt.Length) - 3, 3) + " Title : " + strTitle1); collection.Add("Class : " + strClass1); collection.Add("Handle : " + hWndChild1.ToString()); collection.Add("Return : " + retval3.ToString()); collection.Add("Client Rectangle Top : " + Kader3.Top.ToString()); collection.Add("Client Rectangle Bottom : " + Kader3.Bottom.ToString()); collection.Add("Client Rectangle Left : " + Kader3.Left.ToString()); collection.Add("Client Rectangle Right : " + Kader3.Right.ToString()); while (!(hWndChild1 == IntPtr.Zero)) { iCnt++; sCnt = "000" + iCnt.ToString(); hWndChild1 = user32.FindWindowEx(hWnd, hWndChild1, null, IntPtr.Zero); retval3 = user32.GetWindowRect(hWndChild1, out Kader3); strbTitle1 = new StringBuilder(255); nLength1 = user32.GetWindowText(hWndChild1, strbTitle1, strbTitle1.Capacity + 1); strTitle1 = strbTitle1.ToString(); strbClass1 = new StringBuilder(255); cLength1 = user32.GetClassName(hWndChild1, strbClass1, strbClass1.Capacity + 1); strClass1 = strbClass1.ToString(); if (retval3) { collection.Add(" "); collection.Add("Child " + sCnt.Substring((sCnt.Length) - 3, 3) + " Title : " + strTitle1); collection.Add("Class : " + strClass1); collection.Add("Handle : " + hWndChild1.ToString()); collection.Add("Return : " + retval3.ToString()); collection.Add("Client Rectangle Top : " + Kader3.Top.ToString()); collection.Add("Client Rectangle Bottom : " + Kader3.Bottom.ToString()); collection.Add("Client Rectangle Left : " + Kader3.Left.ToString()); collection.Add("Client Rectangle Right : " + Kader3.Right.ToString()); } } } return(true); }; if (user32.EnumDesktopWindows(IntPtr.Zero, filter, IntPtr.Zero)) { foreach (var item in collection) { Console.WriteLine(item); } } } }
static void Main(string[] args) { var collection = new List <string>(); var Kader = new user32.RECT(); IntPtr hDesktop = user32.GetDesktopWindow(); StringBuilder strbDeskTitle = new StringBuilder(255); int nLengthd = user32.GetClassName(hDesktop, strbDeskTitle, strbDeskTitle.Capacity + 1); string strDeskTitle = strbDeskTitle.ToString(); bool retval0 = user32.GetWindowRect(hDesktop, out Kader); System.Console.WriteLine("*******************************************************************************"); System.Console.WriteLine("* *"); System.Console.WriteLine("* rightclick v0.0.1 *"); System.Console.WriteLine("* *"); System.Console.WriteLine("* Do a right mouse click. *"); System.Console.WriteLine("* *"); System.Console.WriteLine("* use: Click iX iY *"); System.Console.WriteLine("* *"); System.Console.WriteLine("* iX horizontal position " + Kader.Left.ToString() + " .. " + Kader.Right.ToString() + " *"); System.Console.WriteLine("* iY vertical position " + Kader.Top.ToString() + " .. " + Kader.Bottom.ToString() + " *"); System.Console.WriteLine("* *"); System.Console.WriteLine("* *"); System.Console.WriteLine("* *"); System.Console.WriteLine("* Copyright (c) 2014 Geert-Jan Uijtdewilligen *"); System.Console.WriteLine("* This is free open source software that comes with no warranty, and you are *"); System.Console.WriteLine("* welcome to redistribute it under the terms of the GNU General Public License*"); System.Console.WriteLine("* as published by the Free Software Foundation https://www.gnu.org/licenses/ *"); System.Console.WriteLine("* *"); System.Console.WriteLine("*******************************************************************************"); if (args.Length != 2) { System.Console.WriteLine("Please enter arguments: iX , iY "); } else { iX = Int32.Parse(args[0]); iY = Int32.Parse(args[1]); if (iX < 0) { iX = 0; } if (iX > Kader.Right) { iX = Kader.Right; } if (iY < 0) { iY = 0; } if (iY > Kader.Bottom) { iY = Kader.Bottom; } uint uInputs = 3; var aInputs = new user32.INPUT[uInputs]; int iSize = 0x001C; Int32 x = Convert.ToInt32(iX * 65536 / Kader.Right); Int32 y = Convert.ToInt32(iY * 65536 / Kader.Bottom); aInputs[0].type = 0; //mouse aInputs[0].U.mi.dx = x; aInputs[0].U.mi.dy = y; aInputs[0].U.mi.dwFlags = user32.MOUSEEVENTF.MOVE | user32.MOUSEEVENTF.ABSOLUTE; aInputs[0].U.mi.time = 0; aInputs[0].U.mi.mouseData = 0; aInputs[1].type = 0; //mouse aInputs[1].U.mi.dx = x; aInputs[1].U.mi.dy = y; aInputs[1].U.mi.dwFlags = user32.MOUSEEVENTF.RIGHTDOWN; aInputs[1].U.mi.time = 0; aInputs[1].U.mi.mouseData = 0; aInputs[2].type = 0; //mouse aInputs[2].U.mi.dx = x; aInputs[2].U.mi.dy = y; aInputs[2].U.mi.dwFlags = user32.MOUSEEVENTF.RIGHTUP; aInputs[2].U.mi.time = 0; aInputs[2].U.mi.mouseData = 0; uint uRetval = user32.SendInput(uInputs, aInputs, iSize); } }
static void Main(string[] args) { var collection = new List <string>(); var Kader = new user32.RECT(); IntPtr[] hHistory; hHistory = new IntPtr[100]; for (int i = 0; i < 100; i++) { hHistory[i] = IntPtr.Zero; } int iHistory = 0; int iLinecount = 0; bExit = false; hWnd = user32.GetDesktopWindow(); hHistory[iHistory] = hWnd; StringBuilder strbDeskTitle = new StringBuilder(255); int nLengthd = user32.GetClassName(hWnd, strbDeskTitle, strbDeskTitle.Capacity + 1); string strDeskTitle = strbDeskTitle.ToString(); sClass = strDeskTitle; StringBuilder strbTitle = new StringBuilder(255); int nLength = user32.GetWindowText(hWnd, strbTitle, strbTitle.Capacity + 1); string strTitle = strbTitle.ToString(); sTitle = strTitle; bool retval0 = user32.GetWindowRect(hWnd, out Kader); if (retval0) { rKader = Kader; } System.Console.WriteLine("*******************************************************************************"); System.Console.WriteLine("* *"); System.Console.WriteLine("* Nav v0.0.1 (console) *"); System.Console.WriteLine("* *"); System.Console.WriteLine("* Navigate the ms windows api, starting from the desktop window. *"); System.Console.WriteLine("* *"); System.Console.WriteLine("* use: Nav *"); System.Console.WriteLine("* Commands can be *"); System.Console.WriteLine("* exit : Return to the ms windows console *"); System.Console.WriteLine("* child : List all current windows children *"); System.Console.WriteLine("* childpos : List all current windows children and their position *"); System.Console.WriteLine("* down iHndl : Change the current window to the iHndl window handle *"); System.Console.WriteLine("* up : Change the current window to the parent window *"); System.Console.WriteLine("* *"); System.Console.WriteLine("* Copyright (c) 2014 Geert-Jan Uijtdewilligen *"); System.Console.WriteLine("* This is free open source software that comes with no warranty, and you are *"); System.Console.WriteLine("* welcome to redistribute it under the terms of the GNU General Public License*"); System.Console.WriteLine("* as published by the Free Software Foundation https://www.gnu.org/licenses/ *"); System.Console.WriteLine("* *"); System.Console.WriteLine("*******************************************************************************"); if (args.Length != 0) { System.Console.WriteLine("Please don't enter arguments."); } else { while (!(bExit)) { sLocation = "//"; for (int i = 0; i <= iHistory; i++) { sLocation = sLocation + hHistory[i].ToString() + "/"; } System.Console.WriteLine(sLocation); System.Console.WriteLine("Title:" + sTitle + " Class:" + sClass + " Left:" + rKader.Left.ToString() + " Right:" + rKader.Right.ToString() + " Top:" + rKader.Top.ToString() + " Bottom:" + rKader.Bottom.ToString() + " "); sCmdline = System.Console.ReadLine(); if (sCmdline.Contains("exit")) { bExit = true; } if (sCmdline.Contains("up") && iHistory >= 1) { iHistory--; hWnd = hHistory[iHistory]; strbDeskTitle = new StringBuilder(255); nLengthd = user32.GetClassName(hWnd, strbDeskTitle, strbDeskTitle.Capacity + 1); strDeskTitle = strbDeskTitle.ToString(); sClass = strDeskTitle; strbTitle = new StringBuilder(255); nLength = user32.GetWindowText(hWnd, strbTitle, strbTitle.Capacity + 1); strTitle = strbTitle.ToString(); sTitle = strTitle; retval0 = user32.GetWindowRect(hWnd, out Kader); if (retval0) { rKader = Kader; } } if (sCmdline.Contains("down")) { iHistory++; string sHndl = sCmdline.Substring(5, sCmdline.Length - 5); try { int iNavigate = int.Parse(sHndl); IntPtr hNavigate = IntPtr.Add(IntPtr.Zero, iNavigate); hWnd = hNavigate; hHistory[iHistory] = hNavigate; } catch (Exception ex) { Console.WriteLine(ex.Message); iHistory--; } strbDeskTitle = new StringBuilder(255); nLengthd = user32.GetClassName(hWnd, strbDeskTitle, strbDeskTitle.Capacity + 1); strDeskTitle = strbDeskTitle.ToString(); sClass = strDeskTitle; strbTitle = new StringBuilder(255); nLength = user32.GetWindowText(hWnd, strbTitle, strbTitle.Capacity + 1); strTitle = strbTitle.ToString(); sTitle = strTitle; retval0 = user32.GetWindowRect(hWnd, out Kader); if (retval0) { rKader = Kader; } else { rKader.Bottom = 0; rKader.Top = 0; rKader.Left = 0; rKader.Right = 0; } } if (sCmdline.Contains("child")) { iLinecount = 0; int iCnt = 1; string sCnt = "000" + iCnt.ToString(); IntPtr hWndChild1 = user32.FindWindowEx(hWnd, IntPtr.Zero, null, IntPtr.Zero); bool retval3 = user32.GetWindowRect(hWndChild1, out Kader); StringBuilder strbTitle1 = new StringBuilder(255); int nLength1 = user32.GetWindowText(hWndChild1, strbTitle1, strbTitle1.Capacity + 1); string strTitle1 = strbTitle1.ToString(); StringBuilder strbClass1 = new StringBuilder(255); int cLength1 = user32.GetClassName(hWndChild1, strbClass1, strbClass1.Capacity + 1); string strClass1 = strbClass1.ToString(); string sChildHandle = "0000000" + hWndChild1.ToString(); System.Console.WriteLine("Child:" + sCnt.Substring((sCnt.Length) - 3, 3) + " Handle:" + sChildHandle.Substring(sChildHandle.Length - 7, 7) + " Title:" + strTitle1 + " Class:" + strClass1 + " Left:" + Kader.Left.ToString() + " Right:" + Kader.Right.ToString() + " Top:" + Kader.Top.ToString() + " Bottom:" + Kader.Bottom.ToString() + " "); while (!(hWndChild1 == IntPtr.Zero)) { iCnt++; sCnt = "000" + iCnt.ToString(); hWndChild1 = user32.FindWindowEx(hWnd, hWndChild1, null, IntPtr.Zero); retval3 = user32.GetWindowRect(hWndChild1, out Kader); strbTitle1 = new StringBuilder(255); nLength1 = user32.GetWindowText(hWndChild1, strbTitle1, strbTitle1.Capacity + 1); strTitle1 = strbTitle1.ToString(); strbClass1 = new StringBuilder(255); cLength1 = user32.GetClassName(hWndChild1, strbClass1, strbClass1.Capacity + 1); strClass1 = strbClass1.ToString(); if (retval3) { if (sCmdline.Contains("childpos") && (Kader.Left > -1) && (Kader.Right > -1) && (Kader.Top > -1) && (Kader.Bottom > -1) && (Kader.Left + Kader.Right + Kader.Top + Kader.Bottom > 0)) { sChildHandle = "0000000" + hWndChild1.ToString(); System.Console.WriteLine("Child:" + sCnt.Substring((sCnt.Length) - 3, 3) + " Handle:" + sChildHandle.Substring(sChildHandle.Length - 7, 7) + " Title:" + strTitle1 + " Class:" + strClass1); iLinecount++; System.Console.WriteLine(" Left:" + Kader.Left.ToString() + " Right:" + Kader.Right.ToString() + " Top:" + Kader.Top.ToString() + " Bottom:" + Kader.Bottom.ToString() + " "); iLinecount++; if (iLinecount > 200) { System.Console.WriteLine("Hit [Enter]"); System.Console.ReadLine(); iLinecount = 0; } } else { sChildHandle = "0000000" + hWndChild1.ToString(); System.Console.WriteLine("Child:" + sCnt.Substring((sCnt.Length) - 3, 3) + " Handle:" + sChildHandle.Substring(sChildHandle.Length - 7, 7) + " Title:" + strTitle1 + " Class:" + strClass1); iLinecount++; if (iLinecount > 200) { System.Console.WriteLine("Hit [Enter]"); System.Console.ReadLine(); iLinecount = 0; } } } } } } } }