public static void DrawText(this VisualStyleRenderer rnd, IDeviceContext dc, ref Rectangle bounds, string text, System.Windows.Forms.TextFormatFlags flags, NativeMethods.DrawThemeTextOptions options)
 {
     NativeMethods.RECT rc = new NativeMethods.RECT(bounds);
     using (SafeGDIHandle hdc = new SafeGDIHandle(dc))
         NativeMethods.DrawThemeTextEx(rnd.Handle, hdc, rnd.Part, rnd.State, text, text.Length, (int)flags, ref rc, ref options);
     bounds = rc;
 }
        private void SetFileInputPath(IdentifierType identType, string identifier, string filePath, string tagName)
        {
            if (!File.Exists(filePath))
            {
                throw new FileNotFoundException(string.Format("Could not find file {0}", filePath));
            }

            ElementFireEvent(identType, identifier, tagName, "onclick");
            waitForBrowserReadyOnly();
            //Sleep(2000);
            StringBuilder className = new StringBuilder(255);
            StringBuilder btnName = new StringBuilder(255);

            IntPtr dialogHwnd = IntPtr.Zero;
            List<IntPtr> windowChildren = new List<IntPtr>();

            for (int i = 0; i < 30; i++)
            {
                dialogHwnd = NativeMethods.FindWindow("#32770", "Choose File");

                //Specific window title for IE8
                if (dialogHwnd == IntPtr.Zero)
                    dialogHwnd = NativeMethods.FindWindow("#32770", "Choose File to Upload");

                if (dialogHwnd != IntPtr.Zero)
                {   //Now find the combobox fill in box
                    windowChildren = NativeMethods.GetWindowChildren(dialogHwnd);
                    foreach (IntPtr dlgComboBox in windowChildren)
                    {
                        NativeMethods.GetClassName(dlgComboBox, className, className.MaxCapacity); //get the childs's type                    
                        if (string.Equals(className.ToString(), "ComboBoxEx32"))
                        {
                            IntPtr comboBoxTxt = NativeMethods.GetChildWindowHwnd(dlgComboBox, "Edit"); //find the combobox

                            ////old implementation
                            //for (int tempCtr = 0; tempCtr < filePath.Length; tempCtr++) //send the text
                            //    sendKeyPressToHwnd((uint)filePath[tempCtr], comboBoxTxt);

                            //reimplemented using .net UIAutomation library
                            AutomationElement editBox = AutomationElement.FromHandle(comboBoxTxt);
                            ValuePattern valuePattern = (ValuePattern)editBox.GetCurrentPattern(ValuePattern.Pattern);
                            valuePattern.SetValue(filePath);

                            break;
                        }
                    }
                    //Click on the OK Button
                    foreach (IntPtr okBtn in windowChildren)
                    {
                        NativeMethods.GetWindowText(okBtn, btnName, btnName.Capacity);
                        if (string.Equals(btnName.ToString(), "&Open")) // we found the OK Button
                        {
                            NativeMethods.RECT placement = new NativeMethods.RECT();
                            NativeMethods.GetClientRect(okBtn, out placement);
                            uint lParam = (uint)((placement.Left + 1 * 0x010000) + placement.Top + 1); //Find it's coordinates and generate the parameter

                            //click on it
                            NativeMethods.SendMessage(okBtn, 0x201, 0x000, lParam); //WM_LBUTTONDOWN
                            NativeMethods.SendMessage(okBtn, 0x202, 0x000, lParam); //WM_LBUTTONUP
                            break;
                        }
                    }
                    break;
                }
                else
                {
                    //Sleep(1000);
                }
            }

            if (dialogHwnd == IntPtr.Zero)
            {
                throw new Exception(string.Format("Could not find file input dialog handle"));
            }
        }
 public static void DrawGlassIcon(this VisualStyleRenderer rnd, Graphics g, Rectangle bounds, ImageList imgList, int imgIndex)
 {
     DrawWrapper(rnd, g, bounds,
         delegate(IntPtr memoryHdc)
         {
             NativeMethods.RECT rBounds = new NativeMethods.RECT(bounds);
             NativeMethods.DrawThemeIcon(rnd.Handle, memoryHdc, rnd.Part, rnd.State, ref rBounds, imgList.Handle, imgIndex);
         }
     );
 }
 public static void DrawGlassBackground(this VisualStyleRenderer rnd, IDeviceContext dc, Rectangle bounds, Rectangle clipRectangle, bool rightToLeft = false)
 {
     DrawWrapper(rnd, dc, bounds,
         delegate(IntPtr memoryHdc)
         {
             NativeMethods.RECT rBounds = new NativeMethods.RECT(bounds);
             NativeMethods.RECT rClip = new NativeMethods.RECT(clipRectangle);
             // Draw background
             if (rightToLeft) NativeMethods.SetLayout(memoryHdc, 1);
             NativeMethods.DrawThemeBackground(rnd.Handle, memoryHdc, rnd.Part, rnd.State, ref rBounds, ref rClip);
             NativeMethods.SetLayout(memoryHdc, 0);
         }
     );
 }
 public static extern void GetThemeMargins(IntPtr hTheme, IntPtr hdc, int iPartId, int iStateId,
                                           int iPropId, IntPtr prc, out NativeMethods.RECT pMargins);
 public static void DrawGlowingText(this VisualStyleRenderer rnd, IDeviceContext dc, Rectangle bounds, string text, Font font, Color color, System.Windows.Forms.TextFormatFlags flags)
 {
     DrawWrapper(rnd, dc, bounds,
         delegate(IntPtr memoryHdc) {
             // Create and select font
             using (NativeMethods.SafeDCObjectHandle fontHandle = new NativeMethods.SafeDCObjectHandle(memoryHdc, font.ToHfont()))
             {
                 // Draw glowing text
                 NativeMethods.DrawThemeTextOptions dttOpts = new NativeMethods.DrawThemeTextOptions(true);
                 dttOpts.TextColor = color;
                 dttOpts.GlowSize = 10;
                 dttOpts.AntiAliasedAlpha = true;
                 NativeMethods.RECT textBounds = new NativeMethods.RECT(4, 0, bounds.Right - bounds.Left, bounds.Bottom - bounds.Top);
                 NativeMethods.DrawThemeTextEx(rnd.Handle, memoryHdc, rnd.Part, rnd.State, text, text.Length, (int)flags, ref textBounds, ref dttOpts);
             }
         }
     );
 }
 public static extern int DrawThemeIcon(IntPtr hTheme, IntPtr hdc, int iPartId, int iStateId,
                                        ref NativeMethods.RECT pRect, IntPtr himl, int iImageIndex);
 public static extern int DrawThemeTextEx(IntPtr hTheme, IntPtr hdc, int iPartId, int iStateId,
                                          string text, int iCharCount, int dwFlags, ref NativeMethods.RECT pRect, ref DrawThemeTextOptions pOptions);
 public static extern int DrawThemeBackground(IntPtr hTheme, IntPtr hdc, int iPartId, int iStateId,
                                              ref NativeMethods.RECT pRect, ref NativeMethods.RECT pClipRect);
Exemplo n.º 10
0
 public static extern bool InvalidateRect(IntPtr hWnd, [In] ref NativeMethods.RECT rect, [MarshalAs(UnmanagedType.Bool)] bool bErase);
Exemplo n.º 11
0
 public static extern bool GetClientRect(IntPtr hWnd, [In, Out] ref NativeMethods.RECT rect);
Exemplo n.º 12
0
 internal static extern int MapWindowPoints(IntPtr hWndFrom, IntPtr hWndTo, [In, Out] ref NativeMethods.RECT rect, [MarshalAs(UnmanagedType.U4)] int cPoints);
Exemplo n.º 13
0
 public static System.Drawing.Rectangle MapRectangle(this System.Windows.Forms.IWin32Window ctrl, System.Drawing.Rectangle rectangle, System.Windows.Forms.IWin32Window newWin = null)
 {
     NativeMethods.RECT ir = rectangle;
     MapWindowPoints(ctrl == null ? IntPtr.Zero : ctrl.Handle, newWin == null ? IntPtr.Zero : newWin.Handle, ref ir, 2);
     return(ir);
 }