Best FlaUI code snippet using FlaUI.Core.WindowsAPI.User32.GetIconInfo
CaptureUtilities.cs
Source:CaptureUtilities.cs
...91 if (hicon == IntPtr.Zero)92 {93 return null;94 }95 if (!User32.GetIconInfo(hicon, out var iconInfo))96 {97 return null;98 }99 // Calculate the position respecting the hotspot offset100 position.X = cursorInfo.ptScreenPos.X - iconInfo.xHotspot;101 position.Y = cursorInfo.ptScreenPos.Y - iconInfo.yHotspot;102 using (var maskBitmap = Image.FromHbitmap(iconInfo.hbmMask))103 {104 // Special handling for monchome icons105 if (maskBitmap.Height == maskBitmap.Width * 2)106 {107 var cursor = new Bitmap(maskBitmap.Width, maskBitmap.Width, PixelFormat.Format32bppArgb);108 var black = Color.FromArgb(255, 0, 0, 0); //cannot compare Color.Black because of different names109 var white = Color.FromArgb(255, 255, 255, 255); //cannot compare Color.White because of different names...
User32.cs
Source:User32.cs
...6970 [DllImport("user32.dll", SetLastError = true)]71 public static extern bool DestroyIcon(IntPtr hIcon);7273 [DllImport("user32.dll", EntryPoint = "GetIconInfo")]74 public static extern bool GetIconInfo(IntPtr hIcon, out ICONINFO piconinfo);7576 [DllImport("user32.dll")]77 public static extern bool ReleaseDC(IntPtr hWnd, IntPtr hDc);7879 [DllImport("user32.dll")]80 public static extern IntPtr GetDesktopWindow();8182 [DllImport("user32.dll")]83 public static extern IntPtr GetWindowDC(IntPtr ptr);84 }85#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member86}
...
GetIconInfo
Using AI Code Generation
1using FlaUI.Core.WindowsAPI;2using System;3using System.Drawing;4using System.Runtime.InteropServices;5using System.Windows.Forms;6{7 {8 public Form1()9 {10 InitializeComponent();11 }12 private void button1_Click(object sender, EventArgs e)13 {14 var iconHandle = User32.GetClassLongPtr(Handle, User32.GCL_HICON);15 var iconInfo = new User32.ICONINFO();16 User32.GetIconInfo(iconHandle, ref iconInfo);17 var icon = Icon.FromHandle(iconHandle);18 pictureBox1.Image = icon.ToBitmap();19 }20 }21}
GetIconInfo
Using AI Code Generation
1using FlaUI.Core.WindowsAPI;2using System;3using System.Drawing;4using System.Runtime.InteropServices;5{6 {7 public Form1()8 {9 InitializeComponent();10 }11 private void Form1_Load(object sender, EventArgs e)12 {13 Icon i = SystemIcons.Asterisk;14 IconInfo info = new IconInfo();15 User32.GetIconInfo(i.Handle, ref info);16 Bitmap bmp = Bitmap.FromHbitmap(info.hbmColor);17 pictureBox1.Image = bmp;18 }19 }20}21byte[] bitmapData;22using (var stream = new MemoryStream())23{24 bitmap.Save(stream, ImageFormat.Bmp);25 bitmapData = stream.ToArray();26}27string str = Convert.ToBase64String(bitmapData);28byte[] data = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };29using (FileStream fs = new FileStream("C:\\test\\test.bin", FileMode.Create))30{31 fs.Write(data, 0, data.Length);32}33byte[] data = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };34using (FileStream fs = new FileStream("C:\\test\\test.bin", FileMode.Create))35{36 fs.Write(data, 0, data.Length);37}
GetIconInfo
Using AI Code Generation
1using System;2using System.Drawing;3using System.Runtime.InteropServices;4using System.Windows.Forms;5{6 {7 [DllImport("user32.dll", SetLastError = true)]8 public static extern bool GetIconInfo(IntPtr hIcon, out ICONINFO pIconInfo);9 [DllImport("user32.dll", SetLastError = true)]10 public static extern IntPtr GetForegroundWindow();11 [DllImport("user32.dll", SetLastError = true)]12 public static extern IntPtr GetWindowDC(IntPtr hWnd);13 [DllImport("user32.dll", SetLastError = true)]14 public static extern IntPtr ReleaseDC(IntPtr hWnd, IntPtr hDC);15 [DllImport("user32.dll", SetLastError = true)]16 public static extern IntPtr GetWindowRect(IntPtr hWnd, ref RECT rect);17 public static Bitmap GetWindowImage(IntPtr hWnd)18 {19 IntPtr hDC = GetWindowDC(hWnd);20 RECT rect = new RECT();21 GetWindowRect(hWnd, ref rect);22 int width = rect.right - rect.left;23 int height = rect.bottom - rect.top;24 Bitmap bmp = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);25 Graphics graphics = Graphics.FromImage(bmp);26 IntPtr hGraphics = graphics.GetHdc();27 bool result = PrintWindow(hWnd, hGraphics, 0);28 graphics.ReleaseHdc(hGraphics);29 ReleaseDC(hWnd, hDC);30 return bmp;31 }32 [DllImport("user32.dll")]33 private static extern bool PrintWindow(IntPtr hwnd, IntPtr hDC, uint nFlags);34 [StructLayout(LayoutKind.Sequential)]35 {36 public bool fIcon;37 public int xHotspot;38 public int yHotspot;39 public IntPtr hbmMask;40 public IntPtr hbmColor;41 }42 [StructLayout(LayoutKind.Sequential)]43 {44 public int left;45 public int top;46 public int right;47 public int bottom;48 }49 }50}51using System;52using System.Drawing;53using System.Drawing.Imaging;54using System.Runtime.InteropServices;55using System.Windows.Forms;56{57 {58 [DllImport("user32.dll", SetLastError = true)]
GetIconInfo
Using AI Code Generation
1using System;2using System.Drawing;3using System.Runtime.InteropServices;4{5 {6 [DllImport("user32.dll", SetLastError = true)]7 internal static extern bool GetIconInfo(IntPtr hIcon, out IconInfo pIconInfo);8 }9}10using System;11using System.Drawing;12using System.Runtime.InteropServices;13{14 {15 [DllImport("user32.dll", SetLastError = true)]16 internal static extern bool GetIconInfo(IntPtr hIcon, out IconInfo pIconInfo);17 }18}19using System;20using System.Drawing;21using System.Runtime.InteropServices;22{23 {24 [DllImport("user32.dll", SetLastError = true)]25 internal static extern bool GetIconInfo(IntPtr hIcon, out IconInfo pIconInfo);26 }27}28using System;29using System.Drawing;30using System.Runtime.InteropServices;31{32 {33 [DllImport("user32.dll", SetLastError = true)]34 internal static extern bool GetIconInfo(IntPtr hIcon, out IconInfo pIconInfo);35 }36}37using System;38using System.Drawing;39using System.Runtime.InteropServices;40{41 {42 [DllImport("user32.dll", SetLastError = true)]43 internal static extern bool GetIconInfo(IntPtr hIcon, out IconInfo pIconInfo);44 }45}46using System;47using System.Drawing;48using System.Runtime.InteropServices;49{50 {51 [DllImport("user32.dll", SetLastError = true)]52 internal static extern bool GetIconInfo(IntPtr hIcon, out IconInfo pIconInfo);53 }54}
GetIconInfo
Using AI Code Generation
1[DllImport("user32.dll")]2static extern bool GetIconInfo(IntPtr hIcon, out ICONINFO pIconInfo);3[DllImport("user32.dll")]4static extern int GetWindowLong(IntPtr hWnd, int nIndex);5[DllImport("user32.dll")]6static extern IntPtr GetWindowDC(IntPtr hWnd);7[DllImport("user32.dll")]8static extern IntPtr ReleaseDC(IntPtr hWnd, IntPtr hDC);9[DllImport("user32.dll")]10static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);11[DllImport("user32.dll")]12static extern bool GetClientRect(IntPtr hWnd, out RECT lpRect);13[DllImport("user32.dll")]14static extern bool GetCursorPos(out POINT lpPoint);15[DllImport("user32.dll")]16static extern IntPtr GetWindowDC(IntPtr hWnd);17[DllImport("user32.dll")]18static extern IntPtr ReleaseDC(IntPtr hWnd, IntPtr hDC);19[DllImport("user32.dll")]20static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);21[DllImport("user32.dll")]22static extern bool GetClientRect(IntPtr hWnd, out RECT lpRect);23[DllImport("user32.dll")]24static extern bool GetCursorPos(out POINT lpPoint);25[DllImport("user32.dll")]26static extern IntPtr GetWindowDC(IntPtr hWnd);27[DllImport("user32.dll")]28static extern IntPtr ReleaseDC(IntPtr hWnd, IntPtr hDC);
GetIconInfo
Using AI Code Generation
1using System;2using System.Drawing;3using System.Windows.Forms;4using FlaUI.Core.WindowsAPI;5{6 {7 public static void Main(string[] args)8 {9 IntPtr hwnd = User32.GetDesktopWindow();10 IntPtr hIcon = User32.GetClassLongPtr(hwnd, User32.GCLP_HICONSM);11 User32.IconInfo iconInfo = new User32.IconInfo();12 User32.GetIconInfo(hIcon, ref iconInfo);13 Bitmap bmp = Bitmap.FromHbitmap(iconInfo.hbmColor);14 Bitmap bmpMask = Bitmap.FromHbitmap(iconInfo.hbmMask);15 bmp.Save(@"C:\Users\Public\Documents\Icon.bmp");16 bmpMask.Save(@"C:\Users\Public\Documents\IconMask.bmp");17 }18 }19}20using System;21using System.Drawing;22using System.Windows.Forms;23using FlaUI.Core.WindowsAPI;24{25 {26 public static void Main(string[] args)27 {28 IntPtr hwnd = User32.GetDesktopWindow();29 IntPtr hIcon = User32.GetClassLongPtr(hwnd, User32.GCLP_HICONSM);30 User32.IconInfo iconInfo = new User32.IconInfo();31 User32.GetIconInfo(hIcon, ref iconInfo);32 Bitmap bmp = Bitmap.FromHbitmap(iconInfo.hbmColor);33 Bitmap bmpMask = Bitmap.FromHbitmap(iconInfo.hbmMask);34 bmp.Save(@"C:\Users\Public\Documents\Icon.bmp");35 bmpMask.Save(@"C:\Users\Public\Documents\IconMask.bmp");36 }37 }38}39using System;40using System.Drawing;41using System.Windows.Forms;42using FlaUI.Core.WindowsAPI;43{44 {45 public static void Main(string[] args)46 {47 IntPtr hwnd = User32.GetDesktopWindow();48 IntPtr hIcon = User32.GetClassLongPtr(hwnd, User32.GCLP_HICONSM);49 User32.IconInfo iconInfo = new User32.IconInfo();50 User32.GetIconInfo(hIcon, ref iconInfo);
GetIconInfo
Using AI Code Generation
1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using FlaUI.Core.WindowsAPI;7{8 {9 static void Main(string[] args)10 {11 IntPtr hWnd = User32.FindWindow(null, "Untitled - Notepad");12 if (hWnd != IntPtr.Zero)13 {14 User32.ICONINFO iconInfo = new User32.ICONINFO();15 User32.GetIconInfo(User32.GetClassLongPtr(hWnd, User32.GCL_HICON), ref iconInfo);16 }17 {18 Console.WriteLine("Window not found");19 }20 }21 }22}23using System;24using System.Collections.Generic;25using System.Linq;26using System.Text;27using System.Threading.Tasks;28using FlaUI.Core.WindowsAPI;29{30 {31 static void Main(string[] args)32 {33 IntPtr hWnd = User32.FindWindow(null, "Untitled - Notepad");34 if (hWnd != IntPtr.Zero)35 {36 User32.GetClassLongPtr(hWnd, User32.GCL_HICON);37 }38 {39 Console.WriteLine("Window not found");40 }41 }42 }43}
GetIconInfo
Using AI Code Generation
1using FlaUI.Core.WindowsAPI;2using System;3using System.Drawing;4using System.Runtime.InteropServices;5{6 {7 static void Main(string[] args)8 {9 IntPtr handle = User32.FindWindow(null, "Untitled - Notepad");10 if (handle != IntPtr.Zero)11 {12 User32.GetIconInfo(handle, out User32.ICONINFO iconInfo);13 if (iconInfo.hbmColor != IntPtr.Zero)14 {15 Bitmap bitmap = Imaging.CreateBitmapSourceFromHBitmap(iconInfo.hbmColor, IntPtr.Zero, System.Windows.Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());16 bitmap.Save("C:\\Users\\Public\\Documents\\FlaUI\\TestImage.png");17 }18 }19 }20 }21}
GetIconInfo
Using AI Code Generation
1{2 {3 public Form1()4 {5 InitializeComponent();6 IntPtr hIcon = this.Handle;7 FlaUI.Core.WindowsAPI.User32.ICONINFO iconInfo = new FlaUI.Core.WindowsAPI.User32.ICONINFO();8 FlaUI.Core.WindowsAPI.User32.GetIconInfo(hIcon, ref iconInfo);9 IntPtr hIcon2 = iconInfo.hIcon;10 Icon icon = Icon.FromHandle(hIcon2);11 this.Icon = icon;12 }13 }14}15{16 {17 public Form1()18 {19 InitializeComponent();20 IntPtr hIcon = this.Handle;21 FlaUI.Core.WindowsAPI.User32.ICONINFO iconInfo = new FlaUI.Core.WindowsAPI.User32.ICONINFO();22 FlaUI.Core.WindowsAPI.User32.GetIconInfo(hIcon, ref iconInfo);23 IntPtr hIcon2 = iconInfo.hIcon;24 Icon icon = Icon.FromHandle(hIcon2);25 this.Icon = icon;26 }27 }28}29 {30 [DllImport("user32.dll", SetLastError = true)]31 internal static extern bool GetIconInfo(IntPtr hIcon, out IconInfo pIconInfo);32 }33}34using System;35using System.Drawing;36using System.Runtime.InteropServices;37{38 {39 [DllImport("user32.dll", SetLastError = true)]40 internal static extern bool GetIconInfo(IntPtr hIcon, out IconInfo pIconInfo);41 }42}
GetIconInfo
Using AI Code Generation
1using System;2using System.Drawing;3using System.Windows.Forms;4using FlaUI.Core.WindowsAPI;5{6 {7 public static void Main(string[] args)8 {9 IntPtr hwnd = User32.GetDesktopWindow();10 IntPtr hIcon = User32.GetClassLongPtr(hwnd, User32.GCLP_HICONSM);11 User32.IconInfo iconInfo = new User32.IconInfo();12 User32.GetIconInfo(hIcon, ref iconInfo);13 Bitmap bmp = Bitmap.FromHbitmap(iconInfo.hbmColor);14 Bitmap bmpMask = Bitmap.FromHbitmap(iconInfo.hbmMask);15 bmp.Save(@"C:\Users\Public\Documents\Icon.bmp");16 bmpMask.Save(@"C:\Users\Public\Documents\IconMask.bmp");17 }18 }19}20using System;21using System.Drawing;22using System.Windows.Forms;23using FlaUI.Core.WindowsAPI;24{25 {26 public static void Main(string[] args)27 {28 IntPtr hwnd = User32.GetDesktopWindow();29 IntPtr hIcon = User32.GetClassLongPtr(hwnd, User32.GCLP_HICONSM);30 User32.IconInfo iconInfo = new User32.IconInfo();31 User32.GetIconInfo(hIcon, ref iconInfo);32 Bitmap bmp = Bitmap.FromHbitmap(iconInfo.hbmColor);33 Bitmap bmpMask = Bitmap.FromHbitmap(iconInfo.hbmMask);34 bmp.Save(@"C:\Users\Public\Documents\Icon.bmp");35 bmpMask.Save(@"C:\Users\Public\Documents\IconMask.bmp");36 }37 }38}39using System;40using System.Drawing;41using System.Windows.Forms;42using FlaUI.Core.WindowsAPI;43{44 {45 public static void Main(string[] args)46 {47 IntPtr hwnd = User32.GetDesktopWindow();48 IntPtr hIcon = User32.GetClassLongPtr(hwnd, User32.GCLP_HICONSM);49 User32.IconInfo iconInfo = new User32.IconInfo();50 User32.GetIconInfo(hIcon, ref iconInfo);
GetIconInfo
Using AI Code Generation
1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using FlaUI.Core.WindowsAPI;7{8 {9 static void Main(string[] args)10 {11 IntPtr hWnd = User32.FindWindow(null, "Untitled - Notepad");12 if (hWnd != IntPtr.Zero)13 {14 User32.ICONINFO iconInfo = new User32.ICONINFO();15 User32.GetIconInfo(User32.GetClassLongPtr(hWnd, User32.GCL_HICON), ref iconInfo);16 }17 {18 Console.WriteLine("Window not found");19 }20 }21 }22}23using System;24using System.Collections.Generic;25using System.Linq;26using System.Text;27using System.Threading.Tasks;28using FlaUI.Core.WindowsAPI;29{30 {31 static void Main(string[] args)32 {33 IntPtr hWnd = User32.FindWindow(null, "Untitled - Notepad");34 if (hWnd != IntPtr.Zero)35 {36 User32.GetClassLongPtr(hWnd, User32.GCL_HICON);37 }38 {39 Console.WriteLine("Window not found");40 }41 }42 }43}
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!