Exemplo n.º 1
0
        private IShellFolder getDesktopFolder()
        {
            IShellFolder ppshf;
            int          r = UnManagedMethods.SHGetDesktopFolder(out ppshf);

            return(ppshf);
        }
Exemplo n.º 2
0
 public void GetWindows(IntPtr hWndParent)
 {
     this.Items = new EnumWindowsCollection();
     UnManagedMethods.EnumChildWindows(
         hWndParent,
         new EnumWindowsProc(this.WindowEnum), 0);
 }
Exemplo n.º 3
0
        private Icon _GetIcon(bool large)
        {
            // Get icon index and path:
            int iconIndex;
            var iconPath = new StringBuilder(260, 260);

            if (linkA == null)
            {
                linkW.GetIconLocation(iconPath, iconPath.Capacity, out iconIndex);
            }
            else
            {
                linkA.GetIconLocation(iconPath, iconPath.Capacity, out iconIndex);
            }

            var iconFile = iconPath.ToString();

            // If there are no details set for the icon, then we must use
            // the shell to get the icon for the target:
            if (iconFile.Length == 0)
            {
                // Use the FileIcon object to get the icon:
                var flags = FileIcon.SHGetFileInfoConstants.SHGFI_ICON | FileIcon.SHGetFileInfoConstants.SHGFI_ATTRIBUTES;
                if (large)
                {
                    flags = flags | FileIcon.SHGetFileInfoConstants.SHGFI_LARGEICON;
                }
                else
                {
                    flags = flags | FileIcon.SHGetFileInfoConstants.SHGFI_SMALLICON;
                }

                var fileIcon = new FileIcon(Target, flags);
                return(fileIcon.ShellIcon);
            }
            else
            {
                // Use ExtractIconEx to get the icon:
                var hIconEx = new IntPtr[1] {
                    IntPtr.Zero
                };

                if (large)
                {
                    UnManagedMethods.ExtractIconEx(iconFile, iconIndex, hIconEx, null, 1);
                }
                else
                {
                    UnManagedMethods.ExtractIconEx(iconFile, iconIndex, null, hIconEx, 1);
                }
                // If success then return as a GDI+ object
                Icon icon = null;
                if (hIconEx[0] != IntPtr.Zero)
                {
                    icon = Icon.FromHandle(hIconEx[0]);
                }

                return(icon);
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// Gets all top level windows on the system.
 /// </summary>
 public void GetWindows()
 {
     this.items = new EnumWindowsCollection();
     UnManagedMethods.EnumWindows(
         new EnumWindowsProc(this.WindowEnum),
         0);
 }
Exemplo n.º 5
0
        /// <summary>
        /// Gets all child windows of the specified window
        /// </summary>
        /// <param name="hWndParent">Window Handle to get children for</param>
        public int GetWindows(IntPtr hWndParent)
        {
            this.items = new EnumWindowsCollection();
            int success = UnManagedMethods.EnumChildWindows(hWndParent, new WindowEnumeratedEvent(this.WindowEnum), 0);

            return(success == 1 ? 0 : Marshal.GetLastWin32Error());
        }
Exemplo n.º 6
0
 /// <summary>
 ///     Gets all top level windows on the system.
 /// </summary>
 public void GetWindows()
 {
     Items = new EnumWindowsCollection();
     UnManagedMethods.EnumWindows(
         WindowEnum,
         0);
 }
Exemplo n.º 7
0
 /// <summary>
 /// Gets all child windows of the specified window
 /// </summary>
 /// <param name="hWndParent">Window Handle to get children for</param>
 private void GetWindows(
     IntPtr hWndParent)
 {
     UnManagedMethods.EnumChildWindows(
         hWndParent,
         new EnumWindowsProc(this.WindowEnum),
         0);
 }
Exemplo n.º 8
0
 /// <summary>
 ///     Gets all child windows of the specified window
 /// </summary>
 /// <param name="hWndParent">Window Handle to get children for</param>
 public void GetWindows(
     IntPtr hWndParent)
 {
     Items = new EnumWindowsCollection();
     UnManagedMethods.EnumChildWindows(
         hWndParent,
         WindowEnum,
         0);
 }
Exemplo n.º 9
0
 public void Restore()
 {
     if (this.Iconic)
     {
         UnManagedMethods.SendMessage(this.hWnd, 0x112, (IntPtr)0xf120, IntPtr.Zero);
     }
     UnManagedMethods.BringWindowToTop(this.hWnd);
     UnManagedMethods.SetForegroundWindow(this.hWnd);
 }
Exemplo n.º 10
0
 public void SendKey(byte key, byte val)
 {
     //press down de key
     UnManagedMethods.keybd_event(key, val, UnManagedMethods.KEYEVENTF_EXTENDEDKEY, UIntPtr.Zero);
     Thread.Sleep(Delay);
     //release de key
     UnManagedMethods.keybd_event(key, val,
                                  UnManagedMethods.KEYEVENTF_KEYUP | UnManagedMethods.KEYEVENTF_EXTENDEDKEY,
                                  UIntPtr.Zero);
     Thread.Sleep(Delay);
 }
Exemplo n.º 11
0
 /// <summary>
 /// Restores and Brings the window to the front,
 /// assuming it is a visible application window.
 /// </summary>
 public void Restore()
 {
     if (Iconic)
     {
         UnManagedMethods.SendMessage(
             this.hWnd,
             UnManagedMethods.WM_SYSCOMMAND,
             (IntPtr)UnManagedMethods.SC_RESTORE,
             IntPtr.Zero);
     }
     UnManagedMethods.BringWindowToTop(this.hWnd);
     UnManagedMethods.SetForegroundWindow(this.hWnd);
 }
        private string PathFromPidl(IntPtr pidl)
        {
            StringBuilder path   = new StringBuilder(260, 260);
            int           result = UnManagedMethods.SHGetPathFromIDList(pidl, path);

            if (result == 0)
            {
                return(string.Empty);
            }
            else
            {
                return(path.ToString());
            }
        }
Exemplo n.º 13
0
        public static IntPtr FindWindowsEx(string caption, string className, IntPtr hWndParent)
        {
            var _caption   = String.IsNullOrEmpty(caption) ? null : caption;
            var _className = String.IsNullOrEmpty(className) ? null : className;

            IntPtr hWindow = UnManagedMethods.FindWindowEx(hWndParent, IntPtr.Zero, _className, _caption);

            if (hWindow == IntPtr.Zero)
            {
                hWindow = UnManagedMethods.FindWindow(_className, _caption);
            }

            return(hWindow);
        }
Exemplo n.º 14
0
        public void SendAltF4()
        {
            //SendKey(UnManagedMethods.VK_ESCAPE, 0x1B);
            UnManagedMethods.keybd_event(UnManagedMethods.VK_MENU, 0, 0, UIntPtr.Zero);                 //alt Key Pressed
            Thread.Sleep(Delay);

            UnManagedMethods.keybd_event(UnManagedMethods.VK_F4, 0, 0, UIntPtr.Zero);                             //F4 Key Pressed
            Thread.Sleep(Delay);

            UnManagedMethods.keybd_event(UnManagedMethods.VK_MENU, 0, UnManagedMethods.KEYEVENTF_KEYUP, UIntPtr.Zero);             //alt Key released
            Thread.Sleep(Delay);

            UnManagedMethods.keybd_event(UnManagedMethods.VK_F4, 0, UnManagedMethods.KEYEVENTF_KEYUP, UIntPtr.Zero);             //F4 Key released
            Thread.Sleep(Delay);
        }
Exemplo n.º 15
0
        public void SendCtrlShiftP(bool wait = false)
        {
            UnManagedMethods.keybd_event(UnManagedMethods.VK_CONTROL, 0, 0, UIntPtr.Zero);                 //control Key Pressed
            Thread.Sleep(Delay);
            UnManagedMethods.keybd_event(UnManagedMethods.VK_SHIFT, 0, 0, UIntPtr.Zero);                   //shift Key Pressed
            Thread.Sleep(Delay);
            UnManagedMethods.keybd_event(UnManagedMethods.VK_P, 0, 0, UIntPtr.Zero);                       //P Key Pressed
            Thread.Sleep(Delay);

            UnManagedMethods.keybd_event(UnManagedMethods.VK_P, 0, UnManagedMethods.KEYEVENTF_KEYUP, UIntPtr.Zero);             //alt Key released
            Thread.Sleep(Delay);
            UnManagedMethods.keybd_event(UnManagedMethods.VK_SHIFT, 0, UnManagedMethods.KEYEVENTF_KEYUP, UIntPtr.Zero);         //n Key released
            Thread.Sleep(Delay);
            UnManagedMethods.keybd_event(UnManagedMethods.VK_CONTROL, 0, UnManagedMethods.KEYEVENTF_KEYUP, UIntPtr.Zero);       //n Key released
            Thread.Sleep(Delay);
        }
Exemplo n.º 16
0
        /// <summary>
        /// The enum Windows callback.
        /// </summary>
        /// <param name="hWnd">Window Handle</param>
        /// <param name="lParam">Application defined value</param>
        /// <returns>1 to continue enumeration, 0 to stop</returns>
        public int WindowEnum(IntPtr hWnd, int lParam)
        {
            int result = 0;

            //using (var e = new EnumWindowsItem(hWnd)) {
            //    string t = e.Text;
            //    string clss = e.ClassName;
            //    Breezy.Common.Logging.BreezyTrace.Log(System.Diagnostics.TraceEventType.Information, string.Format("window count: {0}, class: {1}, text: {2}", count, t, clss));
            //}

            if (WindowEnumerated != null)
            {
                result = WindowEnumerated(hWnd, lParam);
            }

            UnManagedMethods.SetLastError(0);
            return(result);
        }
Exemplo n.º 17
0
        /// <summary>
        /// The enum Windows callback.
        /// </summary>
        /// <param name="hWnd">Window Handle</param>
        /// <param name="lParam">Application defined value</param>
        /// <returns>1 to continue enumeration, 0 to stop</returns>
        private int WindowEnum(
            IntPtr hWnd,
            int lParam)
        {
            StringBuilder className = new StringBuilder(260, 260);

            UnManagedMethods.GetClassName(hWnd, className, className.Capacity);
            if (className.ToString().ToUpper().IndexOf("MDICLIENT") > 0)
            {
                // stop
                hWndMdiClient = hWnd;
                return(0);
            }
            else
            {
                // continue
                return(1);
            }
        }
Exemplo n.º 18
0
        private void mfrmMDIClientPaint_Load(object sender, System.EventArgs e)
        {
            // Start processing for MDIClient window messages:
            mdiClient = new MDIClientWindow(this, this.Handle);
            // Stop the default window proc from drawing the MDI background
            // with the brush:
            UnManagedMethods.SetClassLong(
                mdiClient.Handle,
                UnManagedMethods.GCL_HBRBACKGROUND,
                0);

            // Load a sample child form:
            frmChild f = new frmChild();

            f.MdiParent = this;
            f.Show();

            // Attach to menu events:
            this.mnuNew.Click  += new System.EventHandler(this.mnu_Click);
            this.mnuExit.Click += new System.EventHandler(this.mnu_Click);
        }
Exemplo n.º 19
0
        private Icon getIcon(bool large)
        {
            int           piIcon      = 0;
            StringBuilder pszIconPath = new StringBuilder(260, 260);

            if (this.linkA == null)
            {
                this.linkW.GetIconLocation(pszIconPath, pszIconPath.Capacity, out piIcon);
            }
            else
            {
                this.linkA.GetIconLocation(pszIconPath, pszIconPath.Capacity, out piIcon);
            }
            string lpszFile = pszIconPath.ToString();

            if (lpszFile.Length == 0)
            {
                FileIcon.SHGetFileInfoConstants flags = FileIcon.SHGetFileInfoConstants.SHGFI_ATTRIBUTES | FileIcon.SHGetFileInfoConstants.SHGFI_ICON;
                flags = !large ? (flags | FileIcon.SHGetFileInfoConstants.SHGFI_SMALLICON) : (flags | FileIcon.SHGetFileInfoConstants.SHGFI_LARGEICON);
                return(new FileIcon(this.Target, flags).ShellIcon);
            }
            IntPtr[] phIconLarge = new IntPtr[] { IntPtr.Zero };
            if (large)
            {
                UnManagedMethods.ExtractIconEx(lpszFile, piIcon, phIconLarge, null, 1);
            }
            else
            {
                UnManagedMethods.ExtractIconEx(lpszFile, piIcon, null, phIconLarge, 1);
            }
            Icon icon = null;

            if (phIconLarge[0] != IntPtr.Zero)
            {
                icon = Icon.FromHandle(phIconLarge[0]);
            }
            return(icon);
        }
Exemplo n.º 20
0
        public void WndProc(ref Message m, ref bool doDefault)
        {
            // Don't need to do anything if the form is minimized:
            if (this.WindowState != FormWindowState.Minimized)
            {
                if (m.Msg == UnManagedMethods.WM_PAINT)
                {
                    //
                    // Here we draw a logo on the "right" hand side
                    // of the form (depends on RTL)
                    //
                    PAINTSTRUCT ps = new PAINTSTRUCT();
                    UnManagedMethods.BeginPaint(m.HWnd, ref ps);
                    RECT rc = new RECT();
                    UnManagedMethods.GetClientRect(m.HWnd, ref rc);

                    // Convert to managed code world
                    Graphics   gfx      = Graphics.FromHdc(ps.hdc);
                    RectangleF rcClient = new RectangleF(
                        rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top);
                    Rectangle rcPaint = new Rectangle(
                        ps.rcPaint.left,
                        ps.rcPaint.top,
                        ps.rcPaint.right - ps.rcPaint.left,
                        ps.rcPaint.bottom - ps.rcPaint.top);

                    // Draw the logo bottom right:
                    SolidBrush   brText    = new SolidBrush(Color.White);
                    StringFormat strFormat = new StringFormat();
                    strFormat.Alignment   = StringAlignment.Far;
                    strFormat.FormatFlags = StringFormatFlags.DirectionVertical |
                                            StringFormatFlags.NoWrap;
                    strFormat.LineAlignment = StringAlignment.Far;
                    Font logoFont = new Font(this.Font.FontFamily, 20, FontStyle.Bold);
                    gfx.DrawString("SigFund.com", logoFont, brText, rcClient, strFormat);
                    logoFont.Dispose();
                    strFormat.Dispose();
                    brText.Dispose();

                    gfx.Dispose();
                    UnManagedMethods.EndPaint(m.HWnd, ref ps);
                }
                else if (m.Msg == UnManagedMethods.WM_ERASEBKGND)
                {
                    //
                    // Fill the background:
                    //

                    RECT rc = new RECT();
                    UnManagedMethods.GetClientRect(m.HWnd, ref rc);

                    // Convert to managed code world
                    Graphics  gfx      = Graphics.FromHdc(m.WParam);
                    Rectangle rcClient = new Rectangle(
                        rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top);

                    int angle = 45;
                    LinearGradientBrush linGrBrush = new LinearGradientBrush(
                        rcClient,
                        Color.FromArgb(255, 230, 242, 255),                        // pale blue
                        Color.FromArgb(255, 0, 72, 160),                           // deep blue
                        angle);

                    gfx.FillRectangle(linGrBrush, rcClient);

                    linGrBrush.Dispose();
                    gfx.Dispose();

                    // Tell Windows we've filled the background:
                    m.Result = (IntPtr)1;

                    // Don't call the default procedure:
                    doDefault = false;
                }
                else if (m.Msg == UnManagedMethods.WM_SIZE)
                {
                    // If your background is a tiled image then
                    // you don't need to do this.  This is only required
                    // when the entire background needs to be updated
                    // in response to the size of the object changing.
                    RECT rect = new RECT();
                    rect.left   = 0;
                    rect.top    = 0;
                    rect.right  = ((int)m.LParam) & 0xFFFF;
                    rect.bottom = (int)(((uint)(m.LParam) & 0xFFFF0000) >> 16);
                    //Console.WriteLine("WM_SIZE {0}", rect.ToString());
                    UnManagedMethods.InvalidateRect(m.HWnd, ref rect, 1);
                }
            }
        }
        private bool getThumbnail(string file, IntPtr pidl, IShellFolder item)
        {
            IntPtr        hBmp         = IntPtr.Zero;
            IExtractImage extractImage = null;

            try
            {
                string pidlPath = PathFromPidl(pidl);
                if (Path.GetFileName(pidlPath).ToUpperInvariant().Equals(Path.GetFileName(file).ToUpperInvariant()))
                {
                    // we have the item:
                    IUnknown iunk            = null;
                    int      prgf            = 0;
                    Guid     iidExtractImage = new Guid("BB2E617C-0920-11d1-9A0B-00C04FC2D6C1");
                    item.GetUIObjectOf(IntPtr.Zero, 1, ref pidl, ref iidExtractImage, out prgf, ref iunk);
                    extractImage = (IExtractImage)iunk;

                    if (extractImage != null)
                    {
                        //Got an IExtractImage object!
                        SIZE sz = new SIZE();
                        sz.cx = desiredSize.Width;
                        sz.cy = desiredSize.Height;
                        StringBuilder location             = new StringBuilder(260, 260);
                        int           priority             = 0;
                        int           requestedColourDepth = 32;
                        //EIEIFLAG flags = EIEIFLAG.IEIFLAG_ASPECT | EIEIFLAG.IEIFLAG_SCREEN;
                        EIEIFLAG flags  = EIEIFLAG.IEIFLAG_ORIGSIZE | EIEIFLAG.IEIFLAG_ASPECT | EIEIFLAG.IEIFLAG_QUALITY;
                        int      uFlags = (int)flags;

                        // E.g. for PDFs on Vista...
                        try
                        {
                            extractImage.GetLocation(location, location.Capacity, ref priority, ref sz, requestedColourDepth,
                                                     ref uFlags);
                        }
                        catch (Exception) {}

                        extractImage.Extract(out hBmp);
                        if (hBmp != IntPtr.Zero)
                        {
                            // create the image object:
                            thumbNail = System.Drawing.Bitmap.FromHbitmap(hBmp);
                            // is thumbNail owned by the Bitmap?
                        }

                        Marshal.ReleaseComObject(extractImage);
                        extractImage = null;
                    }
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                if (hBmp != IntPtr.Zero)
                {
                    UnManagedMethods.DeleteObject(hBmp);
                }
                if (extractImage != null)
                {
                    Marshal.ReleaseComObject(extractImage);
                }
                throw ex;
            }
        }
Exemplo n.º 22
0
 public void SendN()
 {
     SendKey(UnManagedMethods.VkKeyScan('N'), 0xB1);             // ‘A’ Press
 }
Exemplo n.º 23
0
 public void SendY()
 {
     SendKey(UnManagedMethods.VkKeyScan('Y'), 0x95);             // ‘A’ Press
 }
Exemplo n.º 24
0
        public void Focus()
        {
            var r = UnManagedMethods.SetFocus(this.hWnd);

            Thread.Sleep(Delay);
        }
Exemplo n.º 25
0
        private Icon GetIcon(bool large)
        {
            // Get icon index and path:
            int           iconIndex = 0;
            StringBuilder iconPath  = new StringBuilder(260, 260);

            if (_linkA == null)
            {
                _linkW.GetIconLocation(iconPath, iconPath.Capacity, out iconIndex);
            }
            else
            {
                _linkA.GetIconLocation(iconPath, iconPath.Capacity, out iconIndex);
            }
            string iconFile = iconPath.ToString();

            // If there are no details set for the icon, then we must use
            // the shell to get the icon for the target:
            if (iconFile.Length == 0)
            {
                // Use the FileIcon object to get the icon:
                FileIcon.ShGetFileInfoConstants flags = FileIcon.ShGetFileInfoConstants.ShgfiIcon |
                                                        FileIcon.ShGetFileInfoConstants.ShgfiAttributes;
                if (large)
                {
                    flags = flags | FileIcon.ShGetFileInfoConstants.ShgfiLargeicon;
                }
                else
                {
                    flags = flags | FileIcon.ShGetFileInfoConstants.ShgfiSmallicon;
                }
                FileIcon fileIcon = new FileIcon(Target, flags);
                return(fileIcon.ShellIcon);
            }
            else
            {
                // Use ExtractIconEx to get the icon:
                IntPtr[] hIconEx = new IntPtr[1] {
                    IntPtr.Zero
                };
                int iconCount = 0;
                if (large)
                {
                    iconCount = UnManagedMethods.ExtractIconEx(
                        iconFile,
                        iconIndex,
                        hIconEx,
                        null,
                        1);
                }
                else
                {
                    iconCount = UnManagedMethods.ExtractIconEx(
                        iconFile,
                        iconIndex,
                        null,
                        hIconEx,
                        1);
                }
                // If success then return as a GDI+ object
                Icon icon = null;
                if (hIconEx[0] != IntPtr.Zero)
                {
                    icon = Icon.FromHandle(hIconEx[0]);
                    //UnManagedMethods.DestroyIcon(hIconEx[0]);
                }
                return(icon);
            }
        }
Exemplo n.º 26
0
        /// <summary>
        /// Gets all top level windows on the system.
        /// </summary>
        public int GetWindows()
        {
            int success = UnManagedMethods.EnumWindows(new WindowEnumeratedEvent(this.WindowEnum), 0);

            return(success == 1 ? 0 : Marshal.GetLastWin32Error());
        }
Exemplo n.º 27
0
        public static EnumWindowsItem FindWindows(string caption, string className)
        {
            IntPtr hWindow = UnManagedMethods.FindWindow(caption, className);

            return(hWindow != IntPtr.Zero ? new EnumWindowsItem(hWindow) : null);
        }