Ejemplo n.º 1
0
        public bool Report(int hwnd, int lParam)
        {
            IntPtr ownerHandle = WinAPI.GetWindow((IntPtr)hwnd, WinAPI.GW_OWNER);

            if (ownerHandle == this.targetHandle)
            {
                StringBuilder sb = new StringBuilder(256);
                WindowHandleInfo.GetWindowText((IntPtr)hwnd, sb, sb.Capacity);
                Console.WriteLine(sb.ToString());
                if (sb.ToString().IndexOf("- Expresii -") != -1)
                {
                    getList.Add((IntPtr)hwnd);
                }
            }

            return(true);
        }
Ejemplo n.º 2
0
        public Bitmap GetProcPhoto()
        {
            if (this.ProcName.Length == 0)
            {
                return(null);
            }

            Process proc;

            try
            {
                proc = Process.GetProcessesByName(this.ProcName)[0];
            }
            catch (IndexOutOfRangeException e)
            {
                return(null);
            }

            this.targetHandle = proc.MainWindowHandle;

            WindowHandleInfo.EnumWindows(this.Report, 0);

            var guessHandle = this.getList[0];

            var allChildWindows = new WindowHandleInfo(guessHandle);

            var childList = allChildWindows.GetAllChildHandles();

            var rect = new User32.Rect();

            User32.GetWindowRect(childList[0], ref rect);

            int width  = rect.right - rect.left;
            int height = rect.bottom - rect.top;



            System.Drawing.Point center = new System.Drawing.Point(rect.left + width / 2, rect.top + height / 2);

            int padding = 26;

            double scale = width * 1.0 / height;

            int realTop, realHeight, realWidth, realLeft;

            // MessageBox.Show(height.ToString() + "    " + width.ToString());
            if (scale > 1.5)
            {
                realTop    = rect.top + padding;
                realHeight = height - padding * 2;
                realWidth  = (int)(realHeight * 1.5);
                realLeft   = center.X - realWidth / 2;
            }
            else
            {
                realLeft   = rect.left + padding;
                realWidth  = width - padding * 2;
                realHeight = (int)(realWidth / 1.5);
                realTop    = center.Y - realHeight / 2;
            }
            Bitmap   bmp      = new Bitmap(realWidth, realHeight, PixelFormat.Format32bppArgb);
            Graphics graphics = Graphics.FromImage(bmp);

            // graphics.CopyFromScreen(rect.left, rect.top, 0, 0, new Size(width, height), CopyPixelOperation.SourceCopy);
            // SetWindowPos(guessHandle, HWND_TOPMOST, 1, 1, 1, 1, SWP_NOMOVE | SWP_NOSIZE);
            graphics.CopyFromScreen(realLeft, realTop, 0, 0, new System.Drawing.Size(realWidth, realHeight), CopyPixelOperation.SourceCopy);
            return(bmp);
        }