public static void UseSystemImageList(ListView control) { IntPtr large, small; int x, y; if (control.LargeImageList == null) { control.LargeImageList = new ImageList(); } if (control.SmallImageList == null) { control.SmallImageList = new ImageList(); } Shell32.FileIconInit(true); if (!Shell32.Shell_GetImageLists(out large, out small)) { throw new Exception("Failed to get system image list"); } ComCtl32.ImageList_GetIconSize(large, out x, out y); control.LargeImageList.ImageSize = new Size(x, y); ComCtl32.ImageList_GetIconSize(small, out x, out y); control.SmallImageList.ImageSize = new Size(x, y); User32.SendMessage(control.Handle, MSG.LVM_SETIMAGELIST, (int)LVSIL.LVSIL_NORMAL, LargeImageList); User32.SendMessage(control.Handle, MSG.LVM_SETIMAGELIST, (int)LVSIL.LVSIL_SMALL, SmallImageList); }
/// <summary> /// Initialises the specified parent folder. /// </summary> /// <param name="parentFolder">The parent folder.</param> public void Initialise(ShellItem parentFolder) { // If we're not double buffered, we want to be. if (!DoubleBuffered) { DoubleBuffered = true; } // Clear children. Items.Clear(); // Clear the map. itemsToFolders.Clear(); // Work out the types to show. var childTypes = ChildTypes.Files; if (ShowHiddenFilesAndFolders) { childTypes |= ChildTypes.Hidden; } if (ShowFolders) { childTypes |= ChildTypes.Folders; } // Go through the children. foreach (var child in parentFolder.GetChildren(childTypes)) { // Do we need to create the icon for the item? if (shellIconIndexesToCacheIconIndexes.ContainsKey(child.IconIndex) == false) { // Get the shell icon for the item. var smallIcon = Icon.FromHandle(ComCtl32.ImageList_GetIcon(ShellImageList.GetImageList(ShellImageListSize.Small), child.IconIndex, 0)); var largeIcon = Icon.FromHandle(ComCtl32.ImageList_GetIcon(ShellImageList.GetImageList(ShellImageListSize.Large), child.IconIndex, 0)); // Create it and add it. var mappedIndex = SmallImageList.Images.Count; SmallImageList.Images.Add(smallIcon); LargeImageList.Images.Add(largeIcon); shellIconIndexesToCacheIconIndexes[child.IconIndex] = mappedIndex; } // Create an item. var item = new ListViewItem { Text = child.DisplayName, ImageIndex = shellIconIndexesToCacheIconIndexes[child.IconIndex] }; // Map it. itemsToFolders[item] = child; // Insert the item. Items.Add(item); // Fire the event handler. FireOnShellItemAdded(item); } }
// will ensure that the toolTip window was created public void CreateToolTipHandle() { if (tipWindow == null || tipWindow.Handle == IntPtr.Zero) { var icc = new ComCtl32.INITCOMMONCONTROLSEX { dwICC = ComCtl32.ICC.TAB_CLASSES }; ComCtl32.InitCommonControlsEx(ref icc); var cparams = new CreateParams { Parent = dataGrid.Handle, ClassName = NativeMethods.TOOLTIPS_CLASS, Style = NativeMethods.TTS_ALWAYSTIP }; tipWindow = new NativeWindow(); tipWindow.CreateHandle(cparams); User32.SendMessageW(tipWindow, User32.WindowMessage.TTM_SETMAXTIPWIDTH, IntPtr.Zero, (IntPtr)SystemInformation.MaxWindowTrackSize.Width); User32.SetWindowPos( new HandleRef(tipWindow, tipWindow.Handle), User32.HWND_NOTOPMOST, flags: User32.SWP.NOSIZE | User32.SWP.NOMOVE | User32.SWP.NOACTIVATE); User32.SendMessageW(tipWindow, User32.WindowMessage.TTM_SETDELAYTIME, (IntPtr)ComCtl32.TTDT.INITIAL, (IntPtr)0); } }
/// <summary> /// Sets the image list. /// </summary> /// <param name="this">The list view instance.</param> /// <param name="imageListType">Type of the image list.</param> /// <param name="imageListHandle">The image list handle.</param> public static void SetImageList(this ListView @this, ImageListType imageListType, IntPtr imageListHandle) { // If we're using the group header image list (not wrapped by .NET), // just go straight to the Win32 API - we'll be using it from there // anyway. if (imageListType == ImageListType.GroupHeader) { // Set the image list. User32.SendMessage(@this.Handle, LVM_SETIMAGELIST, (uint)imageListType, imageListHandle); // That's all we need to do. return; } // Get the image list details. int cx, cy; ComCtl32.ImageList_GetIconSize(imageListHandle, out cx, out cy); var imageCount = ComCtl32.ImageList_GetImageCount(imageListHandle); // This isn't actually enough for a Winforms list view - we actually need to create a copy of the // image list. var imageList = new ImageList(); imageList.ImageSize = new Size(cx, cy); for (int i = 0; i < imageCount; i++) { // Get the icon. var hIcon = ComCtl32.ImageList_GetIcon(imageListHandle, i, 0); // Create it. var icon = Icon.FromHandle(hIcon); // Add it. imageList.Images.Add(icon); } // Set the image list. switch (imageListType) { case ImageListType.Normal: @this.LargeImageList = imageList; break; case ImageListType.Small: @this.SmallImageList = imageList; break; case ImageListType.State: @this.StateImageList = imageList; break; default: throw new ArgumentOutOfRangeException("imageListType"); } }
public ImageList(Int32 size) { var CLSID_ImageList = Guid.Parse("7C476BA2-02B1-48f4-8048-B24619DDC058"); var refIImageList2 = typeof(IImageList).GUID; var IID_IUnknown = new Guid("00000000-0000-0000-C000-000000000046"); var ptr = IntPtr.Zero; //var result = Ole32.CoCreateInstance(ref CLSID_ImageList, IntPtr.Zero, Ole32.CLSCTX.INPROC_SERVER, ref IID_IUnknown, out ptr); ptr = ComCtl32.ImageList_Create(size, size, 0x00000020 | 0x00010000 | 0x00020000, 0, 1); this._ImageList = (IImageList2)Marshal.GetObjectForIUnknown(ptr); this.Handle = ptr; }
private ImageListStreamer(SerializationInfo info, StreamingContext context) { SerializationInfoEnumerator sie = info.GetEnumerator(); if (sie is null) { return; } while (sie.MoveNext()) { if (string.Equals(sie.Name, "Data", StringComparison.OrdinalIgnoreCase)) { #if DEBUG try { #endif byte[] dat = (byte[])sie.Value; if (dat != null) { // We enclose this imagelist handle create in a theming scope. IntPtr userCookie = ThemingScope.Activate(Application.UseVisualStyles); try { using MemoryStream ms = new MemoryStream(Decompress(dat)); lock (internalSyncObject) { ComCtl32.InitCommonControls(); nativeImageList = new ImageList.NativeImageList(new Ole32.GPStream(ms)); } } finally { ThemingScope.Deactivate(userCookie); } if (nativeImageList.Handle == IntPtr.Zero) { throw new InvalidOperationException(SR.ImageListStreamerLoadFailed); } } #if DEBUG } catch (Exception e) { Debug.Fail("ImageList serialization failure: " + e.ToString()); throw; } #endif } } }
bool EnsureCreated() { if (Handle == IntPtr.Zero) { if (!_parent.IsHandleCreated) { return(false); } CreateParams cparams = new CreateParams { Caption = string.Empty, Style = (int)(User32.WS.VISIBLE | User32.WS.CHILD), ClassStyle = (int)User32.CS.DBLCLKS, X = 0, Y = 0, Width = 0, Height = 0, Parent = _parent.Handle }; CreateHandle(cparams); var icc = new ComCtl32.INITCOMMONCONTROLSEX { dwICC = ComCtl32.ICC.TAB_CLASSES }; ComCtl32.InitCommonControlsEx(ref icc); cparams = new CreateParams { Parent = Handle, ClassName = ComCtl32.WindowClasses.TOOLTIPS_CLASS, Style = (int)ComCtl32.TTS.ALWAYSTIP }; _tipWindow = new NativeWindow(); _tipWindow.CreateHandle(cparams); User32.SendMessageW(_tipWindow, (User32.WM)ComCtl32.TTM.SETMAXTIPWIDTH, 0, SystemInformation.MaxWindowTrackSize.Width); User32.SetWindowPos( new HandleRef(_tipWindow, _tipWindow.Handle), User32.HWND_TOP, flags: User32.SWP.NOSIZE | User32.SWP.NOMOVE | User32.SWP.NOACTIVATE); User32.SendMessageW(_tipWindow, (User32.WM)ComCtl32.TTM.SETDELAYTIME, (nint)ComCtl32.TTDT.INITIAL, 0); } return(true); }
public static void DrawSmallImage(Graphics g, Point point, int imageIndex, bool selected) { uint flags = (uint)(imageIndex >> 16); IntPtr hdc = g.GetHdc(); try { if (selected) { flags |= (int)ILD.BLEND50; } ComCtl32.ImageList_Draw(SmallImageList, imageIndex & 0xffff, hdc, point.X, point.Y, flags); } finally { g.ReleaseHdc(); } }
internal override bool Create(IntPtr parentHandle) { //if(this.ControlId == 0) //{ // LastControlId +=1; // this.ControlId = LastControlId; //} if (this.CommonControlType != CommonControls.ICC_UNDEFINED) { InitCommonControlsEx ccInit = new InitCommonControlsEx(this.CommonControlType); ComCtl32.InitCommonControlsEx(ref ccInit); } this.ParentHandle = parentHandle; this.Handle = User32.CreateWindowEx(0, "static", this.Text, this.Style, this.Left, this.Top, this.Width, this.Height, this.ParentHandle, (IntPtr)this.ControlId, IntPtr.Zero, IntPtr.Zero); return(true); }
public static void DrawString(this Graphics graphics, VisualStyleElement element, string s, int x, int y, int w, int h) { if (element.TextShadowType == TextShadowType.Continuous) { var textColor = (uint)Get0BGR(element.TextColor.Value); var shadowColor = (uint)Get0BGR(element.TextShadowColor.Value); var rect = new RECT(x, y, x + w, y + h); var hdc = graphics.GetHdc(); var hFont = element.Font.ToHfont(); Gdi32.SelectObject(hdc, hFont); Gdi32.SetTextColor(hdc, textColor); ComCtl32.DrawShadowText(hdc, s, (uint)s.Length, rect, 0, textColor, shadowColor, element.TextShadowOffset.X, element.TextShadowOffset.Y); Gdi32.DeleteObject(hFont); graphics.ReleaseHdc(hdc); } else { using var textBrush = new SolidBrush(element.TextColor.Value); graphics.DrawString(s, element.Font, textBrush, x, y); } }
public ImageListEx(Int32 size) { var ptr = IntPtr.Zero; this._CurrentSize = size; ptr = ComCtl32.ImageList_Create(size, size, 0x00000020 | 0x00010000 | 0x00020000, 0, 1); this._IImageList = (IImageList2)Marshal.GetObjectForIUnknown(ptr); this.Handle = ptr; this._IconLoadingThread = new Thread(_IconsLoadingThreadRun) { IsBackground = true, Priority = ThreadPriority.Normal }; this._IconLoadingThread.IsBackground = true; this._IconLoadingThread.SetApartmentState(ApartmentState.STA); this._IconLoadingThread.Start(); this._IconCacheLoadingThread = new Thread(_IconCacheLoadingThreadRun) { IsBackground = true, Priority = ThreadPriority.BelowNormal }; this._IconCacheLoadingThread.SetApartmentState(ApartmentState.STA); this._IconCacheLoadingThread.IsBackground = true; this._IconCacheLoadingThread.Start(); this._OverlaysLoadingThread = new Thread(_OverlaysLoadingThreadRun) { IsBackground = true, Priority = ThreadPriority.BelowNormal }; this._OverlaysLoadingThread.SetApartmentState(ApartmentState.STA); this._OverlaysLoadingThread.IsBackground = true; this._OverlaysLoadingThread.Start(); this._UpdateSubitemValuesThread = new Thread(_UpdateSubitemValuesThreadRun) { Priority = ThreadPriority.BelowNormal }; this._UpdateSubitemValuesThread.SetApartmentState(ApartmentState.STA); this._UpdateSubitemValuesThread.IsBackground = true; this._UpdateSubitemValuesThread.Start(); this._RedrawingThread = new Thread(_RedrawingThreadRun) { IsBackground = true, Priority = ThreadPriority.Normal }; this._RedrawingThread.SetApartmentState(ApartmentState.STA); this._RedrawingThread.IsBackground = true; this._RedrawingThread.Start(); var defIconInfo = new Shell32.SHSTOCKICONINFO() { cbSize = (UInt32)Marshal.SizeOf(typeof(Shell32.SHSTOCKICONINFO)) }; Shell32.SHGetStockIconInfo(Shell32.SHSTOCKICONID.SIID_APPLICATION, Shell32.SHGSI.SHGSI_SYSICONINDEX, ref defIconInfo); this._ExeFallBackIndex = defIconInfo.iSysIconIndex; Shell32.SHGetStockIconInfo(Shell32.SHSTOCKICONID.SIID_SHIELD, Shell32.SHGSI.SHGSI_SYSICONINDEX, ref defIconInfo); this._ShieldIconIndex = defIconInfo.iSysIconIndex; Shell32.SHGetStockIconInfo(Shell32.SHSTOCKICONID.SIID_SHARE, Shell32.SHGSI.SHGSI_SYSICONINDEX, ref defIconInfo); this._SharedIconIndex = defIconInfo.iSysIconIndex; Shell32.SHGetStockIconInfo(Shell32.SHSTOCKICONID.SIID_FOLDER, Shell32.SHGSI.SHGSI_SYSICONINDEX, ref defIconInfo); this._FolderFallBackIndex = defIconInfo.iSysIconIndex; Shell32.SHGetStockIconInfo(Shell32.SHSTOCKICONID.SIID_DOCNOASSOC, Shell32.SHGSI.SHGSI_SYSICONINDEX, ref defIconInfo); this._DefaultFallBackIndex = defIconInfo.iSysIconIndex; var basePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); this._VideAddornerWide = FileSystemListItem.ToFileSystemItem(IntPtr.Zero, Path.Combine(basePath, "video_addorner_wide.png")); this._VideAddorner = FileSystemListItem.ToFileSystemItem(IntPtr.Zero, Path.Combine(basePath, "video_addorner.png")); }
public void Dispose() { ComCtl32.IntImageList_Destroy(this.Handle); Dispose(true); GC.SuppressFinalize(this); }
/// <summary> /// Sets the valid range for the specified field in the IP address control. /// </summary> /// <param name="field">A zero-based field index to which the range will be applied.</param> /// <param name="minValue">The lower limit of the range (inclusive).</param> /// <param name="maxValue">The upper limit of the range (inclusive).</param> /// <exception cref="System.ArgumentOutOfRangeException">field - Field must be a value from 0 to 3.</exception> public bool SetFieldRange(int field, byte minValue, byte maxValue) { if (field < 0 || field > 3) { throw new ArgumentOutOfRangeException(nameof(field), @"Field must be a value from 0 to 3."); } return(SendMessage(ComCtl32.IPAddressMessage.IPM_SETRANGE, (UIntPtr)field, ComCtl32.MAKEIPRANGE(minValue, maxValue)).ToInt32() > 0); }
protected override void OnHandleCreated(EventArgs e) { base.OnHandleCreated(e); System.Windows.Forms.ImageList il = new System.Windows.Forms.ImageList(); il.ImageSize = new System.Drawing.Size(48, 48); System.Windows.Forms.ImageList ils = new System.Windows.Forms.ImageList(); ils.ImageSize = new System.Drawing.Size(16, 16); this.IconSize = 48; ComCtl32.INITCOMMONCONTROLSEX icc = new ComCtl32.INITCOMMONCONTROLSEX(); icc.dwSize = Marshal.SizeOf(typeof(ComCtl32.INITCOMMONCONTROLSEX)); icc.dwICC = 1; var res = ComCtl32.InitCommonControlsEx(ref icc); this.LVHandle = User32.CreateWindowEx(0, "SysListView32", "", User32.WindowStyles.WS_CHILD | User32.WindowStyles.WS_CLIPCHILDREN | User32.WindowStyles.WS_CLIPSIBLINGS | (User32.WindowStyles)User32.LVS_EDITLABELS | (User32.WindowStyles)User32.LVS_OWNERDATA, 0, 0, this.ClientRectangle.Width, this.ClientRectangle.Height, this.Handle, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); User32.ShowWindow(this.LVHandle, User32.ShowWindowCommands.Show); LVCOLUMN column = new LVCOLUMN(); column.mask = LVCF.LVCF_FMT | LVCF.LVCF_TEXT | LVCF.LVCF_WIDTH | LVCF.LVCF_SUBITEM; column.cx = 100; column.iSubItem = 0; column.pszText = "Name"; column.fmt = LVCFMT.LEFT; User32.SendMessage(this.LVHandle, MSG.LVM_INSERTCOLUMN, 0, ref column); LVCOLUMN column2 = new LVCOLUMN(); column2.mask = LVCF.LVCF_FMT | LVCF.LVCF_TEXT | LVCF.LVCF_WIDTH | LVCF.LVCF_SUBITEM; column2.cx = 100; column2.iSubItem = 1; column2.pszText = "Type"; column2.fmt = LVCFMT.LEFT; User32.SendMessage(this.LVHandle, MSG.LVM_INSERTCOLUMN, 1, ref column2); LVCOLUMN column3 = new LVCOLUMN(); column3.mask = LVCF.LVCF_FMT | LVCF.LVCF_TEXT | LVCF.LVCF_WIDTH | LVCF.LVCF_SUBITEM; column3.cx = 100; column3.iSubItem = 2; column3.pszText = "Size"; column3.fmt = LVCFMT.LEFT; User32.SendMessage(this.LVHandle, MSG.LVM_INSERTCOLUMN, 2, ref column3); LVCOLUMN column4 = new LVCOLUMN(); column4.mask = LVCF.LVCF_FMT | LVCF.LVCF_TEXT | LVCF.LVCF_WIDTH | LVCF.LVCF_SUBITEM; column4.cx = 100; column4.iSubItem = 3; column4.pszText = "Date Modified"; column4.fmt = LVCFMT.LEFT; User32.SendMessage(this.LVHandle, MSG.LVM_INSERTCOLUMN, 3, ref column4); User32.SendMessage(this.LVHandle, MSG.LVM_SETIMAGELIST, 0, il.Handle); User32.SendMessage(this.LVHandle, MSG.LVM_SETIMAGELIST, 1, ils.Handle); UxTheme.SetWindowTheme(this.LVHandle, "Explorer", 0); Navigate((ShellItem)KnownFolders.Desktop); User32.SendMessage(this.LVHandle, MSG.LVM_SetExtendedStyle, (int)ListViewExtendedStyles.HeaderInAllViews, (int)ListViewExtendedStyles.HeaderInAllViews); //WinAPI.SendMessage(handle, WinAPI.LVM.LVM_SetExtendedStyle, (int)WinAPI.ListViewExtendedStyles.LVS_EX_AUTOAUTOARRANGE, (int)WinAPI.ListViewExtendedStyles.LVS_EX_AUTOAUTOARRANGE); User32.SendMessage(this.LVHandle, MSG.LVM_SetExtendedStyle, (int)ListViewExtendedStyles.LVS_EX_DOUBLEBUFFER, (int)ListViewExtendedStyles.LVS_EX_DOUBLEBUFFER); }