Example #1
0
        private Tree CaptureWindow(IntPtr hwnd, Win32.WINDOWINFO windowinfo, bool usePrintWindow, bool fixedSize = false)
        {
            BoundingBox windowRect = new BoundingBox(windowinfo.rcWindow.left, windowinfo.rcWindow.top,
                            windowinfo.rcWindow.right - windowinfo.rcWindow.left + 1, windowinfo.rcWindow.bottom - windowinfo.rcWindow.top + 1);

            var attributes = GetWindowAttributes(hwnd, windowinfo);

            if (windowRect.Width > 0 && windowRect.Height > 0)
            {
                System.Drawing.Bitmap bmp;
                int width = windowRect.Width;
                int height = windowRect.Height;

                if(fixedSize)
                {
                    width = (int)System.Windows.SystemParameters.VirtualScreenWidth;
                    height = (int)System.Windows.SystemParameters.VirtualScreenHeight;
                }

                if (!usePrintWindow)
                    bmp = GetBitmapFromScreen(hwnd, null, width, height);
                else
                    bmp = GetBitmapFromPrintWindow(hwnd, null, width, height);

                Tree window = _bitmapToTree.GetScreenshotAndCreateTree(windowRect.Width, windowRect.Height, bmp, attributes);
                //_pool.ReturnInstance(bmp);
                return window;
            }

            return null;
        }
Example #2
0
 // Methods
 public ColorOperation()
 {
     this.mouseAreaControl = null;
     this.translatePath = new GraphicsPath();
     this.scalePath = new GraphicsPath();
     this.rotatePath = new GraphicsPath();
     this.equalPath = new GraphicsPath();
     this.skewxPath = new GraphicsPath();
     this.skewyPath = new GraphicsPath();
     this.anglescalePath = new GraphicsPath();
     this.vscalPath = new GraphicsPath();
     this.controlPoints = null;
     this.reversePath = new GraphicsPath();
     this.startPoint = PointF.Empty;
     this.win32 = new Win32();
     this.ratiomatrix = new Matrix();
     this.graphMatrix = new Matrix();
     this.selectMatrix = new Matrix();
     this.gradientMatrix = new Matrix();
     this.gradientPath = new GraphicsPath();
     this.gradientheight = 1f;
     this.centerPoint = PointF.Empty;
     this.gradientstr = string.Empty;
     this.colorpickerstr = string.Empty;
     this.gradientstr = DrawAreaConfig.GetLabelForName("gradienttransform").Trim();
     this.colorpickerstr = DrawAreaConfig.GetLabelForName("colorpicker").Trim();
 }
 public Monitor(Win32.DISPLAY_DEVICE device, Win32.DEVMODE currentDisplaySettings, List<Win32.DEVMODE> availableDisplaySettings)
 {
     Device = device;
     AvailableDisplaySettings = availableDisplaySettings;
     CurrentDisplaySettings = currentDisplaySettings;
     IsPrimary = CurrentDisplaySettings.dmPositionX == 0 && CurrentDisplaySettings.dmPositionY == 0;
 }
        bool GetPreferences(string section, out Win32.RECT rect, out long style, out long exStyle)
        {
            rect = new Win32.RECT();
            style = 0;
            exStyle = 0;

            if (!Preferences.HasSection(section))
            {
                return false;
            }
            string[] keys = { "rectLeft", "rectTop", "rectRight", "rectBottom", "style", "exStyle" };
            foreach (string key in keys)
            {
                if (!Preferences[section].HasKey(key))
                {
                    return false;
                }
            }
            if (!int.TryParse(Preferences[section]["rectLeft"].Value, out rect.Left)) { return false; }
            if (!int.TryParse(Preferences[section]["rectTop"].Value, out rect.Top)) { return false; }
            if (!int.TryParse(Preferences[section]["rectRight"].Value, out rect.Right)) { return false; }
            if (!int.TryParse(Preferences[section]["rectBottom"].Value, out rect.Bottom)) { return false; }
            if (!long.TryParse(Preferences[section]["style"].Value, out style)) { return false; }
            if (!long.TryParse(Preferences[section]["exStyle"].Value, out exStyle)) { return false; }
            return true;
        }
Example #5
0
        /// <summary>
        /// Gets the icon as an <see cref="ImageSource"/> for the specified path.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <param name="info">The shell file info.</param>
        /// <returns>The icon as an <see cref="ImageSource"/> for the specified path.</returns>
        public static ImageSource GetImageSource(string path, out Win32.SHFILEINFO info)
        {
            info = new Win32.SHFILEINFO();

            int attr;
            if (Directory.Exists(path))
                attr = (int)Win32.FILE_ATTRIBUTE_DIRECTORY;
            else if (File.Exists(path))
                attr = (int)Win32.FILE_ATTRIBUTE_NORMAL;
            else if (path.Length == 3) // drive not ready
                attr = (int)Win32.FILE_ATTRIBUTE_DIRECTORY;
            else
                return null;

            Win32.SHGetFileInfo(path, attr, out info, (uint)Marshal.SizeOf(typeof(Win32.SHFILEINFO)), Win32.SHGFI_DISPLAYNAME | Win32.SHGFI_ICON | Win32.SHGFI_TYPENAME | Win32.SHGFI_SMALLICON | Win32.SHGFI_USEFILEATTRIBUTES);

            ImageSource img = null;
            if (info.hIcon != IntPtr.Zero)
            {
                using (Icon icon = Icon.FromHandle(info.hIcon))
                {
                    img = Imaging.CreateBitmapSourceFromHIcon(icon.Handle, new Int32Rect(0, 0, icon.Width, icon.Height), BitmapSizeOptions.FromEmptyOptions());
                }

                Win32.DestroyIcon(info.hIcon);
            }

            return img;
        }
Example #6
0
 // Methods
 public ViewOperation()
 {
     this.mouseAreaControl = null;
     this.startPoint = Point.Empty;
     this.oldleft = 0f;
     this.oldtop = 0f;
     this.reversePath =new GraphicsPath();
     this.win32 = new Win32();
 }
 public static bool Click(Win32.Point point)
 {
     if (bshandle == IntPtr.Zero)
         bshandle = GetBlueStackWindowHandle();
     if (bshandle == IntPtr.Zero)
         return false;
     MouseHelper.ClickOnPoint(bshandle, point);
     return true;
 }
Example #8
0
		static bool HandleCtrl(Win32.CtrlTypes type)
		{
			var name = Enum.GetName(type.GetType(), type);
			Console.WriteLine("\nExiting due to {0} event from system!\n", name);

			if (f != null)
				f.TerminateBots();
			return true;
		}
 bool SetPreferences(string section, Win32.RECT rect, long style, long exStyle)
 {
     Preferences[section]["rectLeft"].Value = rect.Left.ToString();
     Preferences[section]["rectTop"].Value = rect.Top.ToString();
     Preferences[section]["rectRight"].Value = rect.Right.ToString();
     Preferences[section]["rectBottom"].Value = rect.Bottom.ToString();
     Preferences[section]["style"].Value = style.ToString();
     Preferences[section]["exStyle"].Value = exStyle.ToString();
     return true;
 }
Example #10
0
 public static int DwmExtendFrameIntoClientArea(IntPtr hwnd, ref Win32.MARGINS margins)
 {
     IntPtr hModule = Win32.LoadLibrary("dwmapi");
       if (hModule == IntPtr.Zero)
     return 0;
       IntPtr procAddress = Win32.GetProcAddress(hModule, "DwmExtendFrameIntoClientArea");
       if (procAddress == IntPtr.Zero)
     return 0;
       else
     return ((Win32.DwmExtendFrameIntoClientAreaDelegate) Marshal.GetDelegateForFunctionPointer(procAddress, typeof (Win32.DwmExtendFrameIntoClientAreaDelegate)))(hwnd, ref margins);
 }
Example #11
0
 internal DrawOperation(MouseArea mousecontrol)
     : this()
 {
     this.mouseAreaControl = mousecontrol;
     this.win32 = this.mouseAreaControl.win32;
     this.openFileDialog1 = new OpenFileDialog();
     string text1 = DrawAreaConfig.GetLabelForName("filefilter").Trim();
     this.openFileDialog1.Filter = text1;
     this.openFileDialog1.Title = DrawAreaConfig.GetLabelForName("imagedialog").Trim();
     this.openFileDialog1.FileOk += new CancelEventHandler(this.openFileDialog1_FileOk);
 }
 private IntPtr EnumWindowByName(Win32.EnumWindowsProc filter)
 {
     IntPtr WindowHwnd = IntPtr.Zero;
     Win32.EnumWindows(delegate(IntPtr hwnd, IntPtr lparam)
     {
         if (filter(hwnd, lparam))
         {
             WindowHwnd = hwnd;
             return false;
         }
         return true;
     }, IntPtr.Zero);
     return WindowHwnd;
 }
Example #13
0
 // Methods
 public DrawOperation()
 {
     this.mouseAreaControl = null;
     this.win32 = new Win32();
     this.tempPath = new GraphicsPath();
     this.drawPath = null;
     this.showdialog = false;
     this.filename = string.Empty;
     this.haveTextActive = false;
     this.startPoint = Point.Empty;
     this.mouseDown = false;
     this.reversePath = new GraphicsPath();
     this.first = true;
     this.list = new ArrayList();
     this.tooltips = new Hashtable();
     this.finish = false;
     this.redPath =new GraphicsPath();
 }
Example #14
0
 /// <summary>
 /// ������
 /// </summary>
 /// <param name="mc"></param>
 public DistanceOperation(MouseArea mc)
 {
     this.reversePath = new GraphicsPath();
     this.graph = null;
     this.points = new ArrayList();
     this.moveindex = -1;
     this.startpoint = PointF.Empty;
     this.prePoint = PointF.Empty;
     this.nextPoint = PointF.Empty;
     this.insertindex = -1;
     this.tooltips = new Hashtable(0x10);
     this.oldpoints = string.Empty;
     this.mousedown = false;
     this.mouseAreaControl = mc;
     this.win32 = mc.win32;
     this.mouseAreaControl.DefaultCursor = SpecialCursors.MeasureCursor;
     this.tempPath=new GraphicsPath();
     this.connectPoint=PointF.Empty;
 }
        private IntPtr EnumChildWindowByName(IntPtr parent, Win32.EnumWindowsProc filter)
        {
            IntPtr WindowHwnd = IntPtr.Zero;
            Win32.EnumChildWindows(parent, delegate(IntPtr hwnd, IntPtr lparam)
            {
                if (filter(hwnd, lparam))
                {
                    WindowHwnd = hwnd;
                    return false;
                }
                else
                {
                    EnumChildWindowByName(hwnd, filter);

                }
                return true;
            }, IntPtr.Zero);
            return WindowHwnd;
        }
Example #16
0
 // Methods
 public SelectOperation()
 {
     this.mouseAreaControl = null;
     this.toBeSelectedGraph = null;
     this.toBeSelectedPath = null;
     this.currentMousePoint = MousePoint.None;
     this.reversePath = new GraphicsPath();
     this.oriPath = new GraphicsPath();
     this.startpoint = PointF.Empty;
     this.movePoint = PointF.Empty;
     this.selectMatrix = new Matrix();
     this.totalmatrix = new Matrix();
     this.controlPoint = PointF.Empty;
     this.selectAreaPath = new GraphicsPath();
     this.win32 = new Win32();
     this.AreaPoints = new ArrayList(0x10);
     this.ps = new PointF[8];
     this.rotateindex = 0;
     this.selectCollection = new SvgElementCollection();
     this.tooltips = new Hashtable(0x10);
     this.rotatepath = new GraphicsPath();
 }
Example #17
0
        private Dictionary<string, object> GetWindowAttributes(IntPtr hwnd, Win32.WINDOWINFO windowinfo)
        {
           
            Dictionary<string, object> attributes = new Dictionary<string, object>();
            attributes["handle"] = hwnd;


            ExpensiveWindowInfo expensiveInfo;

            if (!_windowInfo.TryGetValue(hwnd, out expensiveInfo))
            {
                expensiveInfo = new ExpensiveWindowInfo(Win32.GetClassName(hwnd), Win32.GetWindowText(hwnd), Win32.GetProcessPathFromWindowHandle(hwnd));
                _windowInfo.Add(hwnd, expensiveInfo);
            }

            attributes["processfilename"] = expensiveInfo.ProcessFilePath;
            attributes["title"] = expensiveInfo.Title;
            attributes["classname"] = expensiveInfo.ClassName;
            attributes["style"] = windowinfo.dwStyle;
            attributes["exstyle"] = windowinfo.dwExStyle;

            return attributes;
        }
Example #18
0
 // Methods
 public PolyOperation(MouseArea mc)
 {
     this.mouseAreaControl = null;
     this.win32 = null;
     this.reversePath = new GraphicsPath();
     this.graph = null;
     this.operate = PolyOperate.Draw;
     this.points = new PointF[0];
     this.moveindex = -1;
     this.startpoint = PointF.Empty;
     this.prePoint = PointF.Empty;
     this.nextPoint = PointF.Empty;
     this.insertindex = -1;
     this.tooltips = new Hashtable(0x10);
     this.oldpoints = string.Empty;
     this.mousedown = false;
     this.AreaPoints=new ArrayList();
     this.mouseAreaControl = mc;
     this.win32 = mc.win32;
     this.mouseAreaControl.PicturePanel.GraphChanged += new EventHandler(this.ChangeGraph);
     this.mouseAreaControl.SVGDocument.SelectCollection.OnCollectionChangedEvent += new OnCollectionChangedEventHandler(this.ChangeSelect);
     this.mouseAreaControl.DefaultCursor = SpecialCursors.bezierCursor;
 }
Example #19
0
        int Hooked(int code, IntPtr wparam, ref Win32.CWPSTRUCT cwp)
        {
            switch(code) {
                case 0:
                switch(cwp.message) {
                    case Win32.WM_CREATE:
                        string s = string.Empty;
                        char[] className = new char[10];
                        int length = Win32.GetClassName( cwp.hwnd, className, 9 );
                        for( int i = 0; i < length; i++ )
                            s += className[i];
                        if( s == "#32768" ) { // System class for menu
                            defaultWndProc = Win32.SetWindowLong( cwp.hwnd, (-4), subWndProc );
                            //int old = Win32.GetWindowLong( cwp.hwnd, (-20) );
                            //Win32.SetWindowLong2( cwp.hwnd,  (-20)/*GWL_EXSTYLE=(-20)*/, 0x20/*WS_EX_TRANSPARENT=0x20*/ );
                        }

                        break;
                }
                break;
            }
            return Win32.CallNextHookEx(hookHandle,code,wparam, ref cwp);
        }
 internal IntPtr addHook(Win32.HookingIDs hID, WinAPI.LowLevelMouseProc callback)
 {
     if (ModuleHandle == IntPtr.Zero) {
         using (var curProcess = Process.GetCurrentProcess())
         using (var curModule = curProcess.MainModule) {
             IntPtr ret = WinAPI.SetWindowsHookEx((int)hID, callback, WinAPI.GetModuleHandle(curModule.ModuleName), 0);
             HookInfo info = new HookInfo();
             info.hookID = ret;
             info.callback = callback;
             info.hID = hID;
             hookIDs.Add(info);
             return ret;
         }
     } else {
         IntPtr ret = WinAPI.SetWindowsHookEx((int)hID, callback, ModuleHandle, 0);
         HookInfo info = new HookInfo();
         info.hookID = ret;
         info.callback = callback;
         info.hID = hID;
         hookIDs.Add(info);
         hookIDs.Add(info);
         return ret;
     }
 }
Example #21
0
        /// <summary>
        ///     The callback for the Keyboard hook
        /// </summary>
        /// <param name="code"></param>
        /// <param name="wParam"></param>
        /// <param name="lParam"></param>
        /// <returns></returns>
        private int HookProc(int code, int wParam, ref Win32.KBDLLHOOKSTRUCT lParam)
        {
            if (code >= 0)
            {
                Key key = System.Windows.Input.KeyInterop.KeyFromVirtualKey(lParam.vkCode);

                //if (HookedKeys.Contains(key))
                {
                    KeyboardHookEventArgs kea = new KeyboardHookEventArgs(key, true);
                    if ((wParam == (int)Win32.WindowsMessages.WM_KEYDOWN || wParam == (int)Win32.WindowsMessages.WM_SYSKEYDOWN) && (KeyDown != null))
                    {
                        KeyDown(this, kea);
                    }
                    else if ((wParam == (int)Win32.WindowsMessages.WM_KEYUP || wParam == (int)Win32.WindowsMessages.WM_SYSKEYUP) && (KeyUp != null))
                    {
                        kea.IsDown = false;
                        KeyUp(this, kea);
                    }
                    if (kea.Handled)
                        return 1;
                }
            }
            return Win32.CallNextHookEx(m_hHook, code, wParam, ref lParam);
        }
Example #22
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Translate mouse buttons received from a Win API mouse message to .NET mouse buttons
        /// </summary>
        /// <param name="winMouseButtons">Windows mouse buttons</param>
        /// <returns>.NET mouse buttons</returns>
        /// ------------------------------------------------------------------------------------
        public static MouseButtons TranslateMouseButtons(Win32.MouseButtons winMouseButtons)
        {
            MouseButtons mouseButton = MouseButtons.None;
            if ((winMouseButtons & Win32.MouseButtons.MK_LBUTTON) == Win32.MouseButtons.MK_LBUTTON)
                mouseButton |= MouseButtons.Left;
            if ((winMouseButtons & Win32.MouseButtons.MK_RBUTTON) == Win32.MouseButtons.MK_RBUTTON)
                mouseButton |= MouseButtons.Right;
            if ((winMouseButtons & Win32.MouseButtons.MK_MBUTTON) == Win32.MouseButtons.MK_MBUTTON)
                mouseButton |= MouseButtons.Middle;
            if ((winMouseButtons & Win32.MouseButtons.MK_XBUTTON1) == Win32.MouseButtons.MK_XBUTTON1)
                mouseButton |= MouseButtons.XButton1;
            if ((winMouseButtons & Win32.MouseButtons.MK_XBUTTON2) == Win32.MouseButtons.MK_XBUTTON2)
                mouseButton |= MouseButtons.XButton2;

            return mouseButton;
        }
Example #23
0
 private static bool ConsoleCtrlHandler(Win32.CtrlType ctrlType)
 {
     const bool ignore = true;
     return ignore;
 }
Example #24
0
 /// <summary>
 /// Sends a win32 message to set scrollbars position.
 /// </summary>
 /// <param name="point">a POINT conatining H/Vscrollbar scrollpos.</param>
 private unsafe void SetScrollPos(Win32.POINT point)
 {
     IntPtr ptr = new IntPtr(&point);
     Win32.SendMessage(richTextBox1.Handle, Win32.EM_SETSCROLLPOS, 0, ptr);
 }
Example #25
0
		// ------------------------------------------------------------------
		#endregion

		#region Private member.
		// ------------------------------------------------------------------

		/// <summary>
		/// Called when [custom draw].
		/// </summary>
		/// <param name="idCtrl">The id CTRL.</param>
		/// <param name="nmcd">The NMCD.</param>
		/// <returns></returns>
		private int OnCustomDraw(
			int idCtrl,
			ref Win32.NMCUSTOMDRAW nmcd )
		{
			int nResult = 0;
			switch ( nmcd.dwDrawStage )
			{
				case (int)Win32.CDDS.CDDS_PREPAINT:
					nResult = interfaceCustDraw.OnPrePaint( idCtrl, ref nmcd );
					break;
				case (int)Win32.CDDS.CDDS_POSTPAINT:
					nResult = interfaceCustDraw.OnPostPaint( idCtrl, ref nmcd );
					break;
				case (int)Win32.CDDS.CDDS_PREERASE:
					nResult = interfaceCustDraw.OnPreErase( idCtrl, ref nmcd );
					break;
				case (int)Win32.CDDS.CDDS_POSTERASE:
					nResult = interfaceCustDraw.OnPostErase( idCtrl, ref nmcd );
					break;
				case (int)Win32.CDDS.CDDS_ITEMPREPAINT:
					nResult = interfaceCustDraw.OnItemPrePaint( idCtrl, ref nmcd );
					break;
				case (int)Win32.CDDS.CDDS_ITEMPOSTPAINT:
					nResult = interfaceCustDraw.OnItemPostPaint( idCtrl, ref nmcd );
					break;
				case (int)Win32.CDDS.CDDS_ITEMPREERASE:
					nResult = interfaceCustDraw.OnItemPreErase( idCtrl, ref nmcd );
					break;
				case (int)Win32.CDDS.CDDS_ITEMPOSTERASE:
					nResult = interfaceCustDraw.OnItemPostErase( idCtrl, ref nmcd );
					break;
				default:
					break;
			}
			return nResult;
		}
Example #26
0
			static int AVISaveOptions(IntPtr stream, ref Win32.AVICOMPRESSOPTIONS opts, IntPtr owner)
			{
				IntPtr mem = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(Win32.AVICOMPRESSOPTIONS)));

				Marshal.StructureToPtr(opts, mem, false);

				IntPtr[] streams = new[] { stream };
				IntPtr[] infPtrs = new[] { mem };

				int ret = Win32.AVISaveOptions(owner, 0, 1, streams, infPtrs);

				opts = (Win32.AVICOMPRESSOPTIONS)Marshal.PtrToStructure(mem, typeof(Win32.AVICOMPRESSOPTIONS));

				Marshal.FreeHGlobal(mem);

				return ret;
			}
Example #27
0
			public static CodecToken TakePossession(Win32.AVICOMPRESSOPTIONS comprOptions)
			{
				CodecToken ret = new CodecToken();
				ret.allocated = true;
				ret.comprOptions = comprOptions;
				ret.codec = Win32.decode_mmioFOURCC(comprOptions.fccHandler);
				return ret;
			}
Example #28
0
			public void PopulateWAVEFORMATEX(ref Win32.WAVEFORMATEX wfex)
			{
				int bytes = 0;
				if (a_bits == 16) bytes = 2;
				else if (a_bits == 8) bytes = 1;
				else throw new InvalidOperationException("only 8/16 bits audio are supported by AviWriter and you chose: " + a_bits);
				if (a_channels == 1) { }
				else if (a_channels == 2) { }
				else throw new InvalidOperationException("only 1/2 channels audio are supported by AviWriter and you chose: " + a_channels);

				wfex.Init();
				wfex.nBlockAlign = (ushort)(bytes * a_channels);
				wfex.nChannels = (ushort)a_channels;
				wfex.wBitsPerSample = (ushort)a_bits;
				wfex.wFormatTag = Win32.WAVE_FORMAT_PCM;
				wfex.nSamplesPerSec = (uint)a_samplerate;
				wfex.nAvgBytesPerSec = (uint)(wfex.nBlockAlign * a_samplerate);
			}
Example #29
0
			public void PopulateBITMAPINFOHEADER32(ref Win32.BITMAPINFOHEADER bmih)
			{
				bmih.Init();
				bmih.biPlanes = 1;
				bmih.biBitCount = 32;
				bmih.biHeight = height;
				bmih.biWidth = width;
				bmih.biSizeImage = (uint)(4 * width * height);
			}
Example #30
0
 //发送消息
 private void sendmessage(int msg)
 {
     Win32 mywin32 = new Win32();
     mywin32.SendMsgToMainForm(hwnd.ToInt32(),msg);
 }