/// <summary> /// Sets the specified iconic thumbnail for the specified window. /// This is typically done in response to a DWM message. /// </summary> /// <param name="bitmap">The thumbnail bitmap.</param> public static void SetIconicThumbnail(this Form form, Bitmap bitmap) { HResult dwmSetIconicThumbnailResult = UnsafeNativeMethods.DwmSetIconicThumbnail( form.Handle, bitmap.GetHbitmap(), SafeNativeMethods.DWM_SIT_DISPLAYFRAME); dwmSetIconicThumbnailResult.ThrowIf(); }
/// <summary> /// Repopulates the application's jump list. /// Use this method after all current changes to /// the application's jump list have been introduced, /// and you want the list to be refreshed. /// </summary> /// <returns><b>true</b> if the list was refreshed; <b>false</b> /// if the operation was cancelled. The operation might have /// been cancelled if the <see cref="UserRemovedItems"/> event /// handler instructed us to cancel the operation.</returns> /// <remarks> /// If the user removed items from the jump list between the /// last refresh operation and this one, then the /// <see cref="UserRemovedItems"/> event will be invoked. /// If the event handler for this event instructed us to cancel /// the operation, then the current transaction is aborted, /// no items are added, and this method returns <b>false</b>. /// Check the return value to determine whether the jump list /// needs to be changed and the operation attempted again. /// </remarks> public bool Refresh() { if (!BeginList()) { return(false); //Operation was cancelled } _tasks.RefreshTasks(_customDestinationList); _destinations.RefreshDestinations(_customDestinationList); switch (EnabledAutoDestinationType) { case ApplicationDestinationType.Frequent: HResult appendKnownCategoryFrequentResult = _customDestinationList.AppendKnownCategory(KnownDestCategory.FREQUENT); appendKnownCategoryFrequentResult.ThrowIf(); break; case ApplicationDestinationType.Recent: HResult appendKnownCategoryRecentResult = _customDestinationList.AppendKnownCategory(KnownDestCategory.RECENT); appendKnownCategoryRecentResult.ThrowIf(); break; } CommitList(); return(true); }
public static void SetTaskbarOverlayIcon(this Form form, Icon icon, string description) { HResult result = TaskbarList.SetOverlayIcon( form.Handle, icon == null ? IntPtr.Zero : icon.Handle, description); result.ThrowIf(); }
/// <summary> /// Sets the specified peek (live preview) bitmap for the specified /// window. This is typically done in response to a DWM message. /// </summary> /// <param name="bitmap">The thumbnail bitmap.</param> /// <param name="displayFrame">Whether to display a standard window /// frame around the bitmap.</param> public static void SetPeekBitmap(this Form form, Bitmap bitmap, bool displayFrame) { HResult dwmSetIconicLivePreviewBitmapResult = UnsafeNativeMethods.DwmSetIconicLivePreviewBitmap( form.Handle, bitmap.GetHbitmap(), IntPtr.Zero, displayFrame ? SafeNativeMethods.DWM_SIT_DISPLAYFRAME : (uint)0); dwmSetIconicLivePreviewBitmapResult.ThrowIf(); }
protected override void WndProc(ref Message m) { switch (m.Msg) { case 0x1: /*WM_CREATE*/ { SubclassHWnd(base.Handle); HResult setThemeResult = Win32.SetWindowTheme(base.Handle, "explorer", null); setThemeResult.ThrowIf(); unchecked { Win32.SendMessage(base.Handle, (WindowMessage)LVM_SetExtendedListViewStyle, LVS_Ex_DoubleBuffer, LVS_Ex_DoubleBuffer); } break; } case 0x202: case 0x205: case 520: case 0x203: case 0x2a1: { base.DefWndProc(ref m); return; } } base.WndProc(ref m); }
/// <summary> /// Draws the specified overlay icon on the specified window's /// taskbar button. /// </summary> /// <param name="icon">The overlay icon.</param> /// <param name="description">The overlay icon description.</param> public static void SetTaskbarOverlayIcon(Icon icon, string description) { HResult result = TaskbarList.SetOverlayIcon( Program.HackerWindowHandle, icon == null ? IntPtr.Zero : icon.Handle, description); result.ThrowIf(); }
/// <summary> /// Specifies that only a portion of the window's client area /// should be used in the window's thumbnail. /// </summary> /// <param name="hwnd">The window.</param> /// <param name="clipRect">The rectangle that specifies the clipped region.</param> private static void SetThumbnailClip(this Form form, Rectangle clipRect) { //Example: SetThumbnailClip(this, new Rectangle(button.Location, button.Size)); Rect rect = new Rect(clipRect.Left, clipRect.Top, clipRect.Right, clipRect.Bottom); HResult setThumbnailClipResult = TaskbarList.SetThumbnailClip(form.Handle, ref rect); setThumbnailClipResult.ThrowIf(); }
/// <summary> /// Sets the specified peek (live preview) bitmap for the specified /// window. This is typically done in response to a DWM message. /// </summary> /// <param name="hwnd">The window handle.</param> /// <param name="bitmap">The thumbnail bitmap.</param> /// <param name="offset">The client area offset at which to display /// the specified bitmap. The rest of the parent window will be /// displayed as "remembered" by the DWM.</param> /// <param name="displayFrame">Whether to display a standard window /// frame around the bitmap.</param> public static void SetPeekBitmap(this Form form, Bitmap bitmap, Point offset, bool displayFrame) { var nativePoint = new POINT(offset.X, offset.Y); HResult dwmSetIconicLivePreviewResult = UnsafeNativeMethods.DwmSetIconicLivePreviewBitmap( form.Handle, bitmap.GetHbitmap(), ref nativePoint, displayFrame ? SafeNativeMethods.DWM_SIT_DISPLAYFRAME : (uint)0); dwmSetIconicLivePreviewResult.ThrowIf(); }
/// <summary> /// Gets the shell <b>IShellLink</b> representation /// of the object. /// </summary> /// <returns>An <b>IShellLink</b> up-cast to <b>object</b>.</returns> public object GetShellRepresentation() { IShellLinkW shellLink = (IShellLinkW) new CShellLink(); IPropertyStore propertyStore = (IPropertyStore)shellLink; PropVariant propVariant = new PropVariant(); if (IsSeparator) { propVariant.SetValue(true); HResult setValueResult = propertyStore.SetValue(ref PropertyKey.PKEY_AppUserModel_IsDestListSeparator, ref propVariant); setValueResult.ThrowIf(); propVariant.Clear(); propVariant.Dispose(); } else { HResult setPathResult = shellLink.SetPath(Path); setPathResult.ThrowIf(); if (!String.IsNullOrEmpty(IconLocation)) { HResult setIconLocationResult = shellLink.SetIconLocation(IconLocation, IconIndex); setIconLocationResult.ThrowIf(); } if (!String.IsNullOrEmpty(Arguments)) { HResult setArgumentsResult = shellLink.SetArguments(Arguments); setArgumentsResult.ThrowIf(); } if (!String.IsNullOrEmpty(WorkingDirectory)) { HResult setWorkingDirectoryResult = shellLink.SetWorkingDirectory(WorkingDirectory); setWorkingDirectoryResult.ThrowIf(); } HResult setShowCmdResult = shellLink.SetShowCmd((uint)ShowCommand); setShowCmdResult.ThrowIf(); propVariant.SetValue(Title); HResult setValueResult = propertyStore.SetValue(ref PropertyKey.PKEY_Title, ref propVariant); setValueResult.ThrowIf(); propVariant.Clear(); propVariant.Dispose(); } HResult commitResult = propertyStore.Commit(); commitResult.ThrowIf(); //Marshal.ReleaseComObject(propertyStore); return(shellLink); }
private static IPropertyStore InternalGetWindowPropertyStore(IntPtr hwnd) { IPropertyStore propStore; HResult shGetPropertyStoreResult = UnsafeNativeMethods.SHGetPropertyStoreForWindow( hwnd, ref SafeNativeMethods.IID_IPropertyStore, out propStore); shGetPropertyStoreResult.ThrowIf(); return(propStore); }
private const int TVS_EX_FADEINOUTEXPANDOS = 0x0040; //auto hide the +/- signs protected override void OnHandleCreated(System.EventArgs e) { if (OSVersion.IsAboveOrEqual(WindowsVersion.Vista)) { Win32.SendMessage(this.Handle, (WindowMessage)TVM_SETEXTENDEDSTYLE, 0, TVS_EX_FADEINOUTEXPANDOS); HResult setThemeResult = Win32.SetWindowTheme(this.Handle, "explorer", null); setThemeResult.ThrowIf(); } base.OnHandleCreated(e); }
/// <summary> /// Deletes all custom destinations from the application's jump list. /// </summary> public void ClearCustomDestinations() { try { HResult deleteListResult = _customDestinationList.DeleteList(_appId); deleteListResult.ThrowIf(); } catch (FileNotFoundException) { /*Means the list is empty, that's cool. */ } _destinations.Clear(); }
public static void IsNetworkError(string url, IntPtr hwnd) { if (OSVersion.IsAboveOrEqual(WindowsVersion.Vista)) { IntPtr ndfhandle = IntPtr.Zero; HResult ndfCreate = Win32.NdfCreateWebIncident(url, ref ndfhandle); ndfCreate.ThrowIf(); Win32.NdfExecuteDiagnosis(ndfhandle, hwnd); //Will throw error if user cancels Win32.NdfCloseIncident(ndfhandle); } }
private static void InternalEnableCustomWindowPreview(IntPtr hwnd, bool enable) { int t = enable ? 1 : 0; HResult setFirstAttributeResult = UnsafeNativeMethods.DwmSetWindowAttribute( hwnd, SafeNativeMethods.DWMWA_HAS_ICONIC_BITMAP, ref t, 4); setFirstAttributeResult.ThrowIf(); HResult setSecondAttributeResult = UnsafeNativeMethods.DwmSetWindowAttribute( hwnd, SafeNativeMethods.DWMWA_FORCE_ICONIC_REPRESENTATION, ref t, 4); setSecondAttributeResult.ThrowIf(); }
/// <summary> /// Deletes the specified application destination from the application's /// jump list. /// </summary> /// <param name="destination">The application destination.</param> public void DeleteApplicationDestination(IJumpListDestination destination) { IApplicationDestinations destinations = (IApplicationDestinations) new CApplicationDestinations(); if (!String.IsNullOrEmpty(_appId)) { HResult setAppIDResult = destinations.SetAppID(_appId); setAppIDResult.ThrowIf(); } HResult removeDestinationResult = destinations.RemoveDestination(destination.GetShellRepresentation()); removeDestinationResult.ThrowIf(); }
internal static IShellItem GetShellItemFromPath(string path) { if (String.IsNullOrEmpty(path)) { throw new ArgumentNullException( "path", "Shell item cannot be generated from null or empty path."); } IShellItem resultItem = default(IShellItem); Guid shellItemGuid = new Guid("43826D1E-E718-42EE-BC55-A1E261C37BFE"); HResult result = UnsafeNativeMethods.SHCreateItemFromParsingName( path, IntPtr.Zero, ref shellItemGuid, out resultItem); result.ThrowIf(); return(resultItem); }
internal void RefreshTasks(ICustomDestinationList destinationList) { if (_tasks.Count == 0) { return; } IObjectCollection taskCollection = (IObjectCollection) new CEnumerableObjectCollection(); foreach (IJumpListTask task in _tasks) { HResult addObjectResult = taskCollection.AddObject(task.GetShellRepresentation()); addObjectResult.ThrowIf(); } HResult addUserTasksResult = destinationList.AddUserTasks((IObjectArray)taskCollection); addUserTasksResult.ThrowIf(); }
/// <summary> /// Removes all application destinations (such as frequent and recent) /// from the application's jump list. /// </summary> public void ClearApplicationDestinations() { IApplicationDestinations destinations = (IApplicationDestinations) new CApplicationDestinations(); if (!String.IsNullOrEmpty(_appId)) { HResult setAppIDResult = destinations.SetAppID(_appId); setAppIDResult.ThrowIf(); } try { //This does not remove pinned items. HResult removeAllDestinationsResult = destinations.RemoveAllDestinations(); removeAllDestinationsResult.ThrowIf(); } catch (FileNotFoundException) { /* There are no destinations. That's cool. */ } }
internal void RefreshDestinations(ICustomDestinationList destinationList) { if (_categorizedDestinations.Count == 0) { return; } foreach (int key in _categorizedDestinations.Keys) { IObjectCollection categoryContents = (IObjectCollection) new CEnumerableObjectCollection(); var destinations = _categorizedDestinations[key]; foreach (IJumpListDestination destination in destinations) { HResult addObjectResult = categoryContents.AddObject(destination.GetShellRepresentation()); addObjectResult.ThrowIf(); } HResult appendCategoryResult = destinationList.AppendCategory( destinations.First().Category, (IObjectArray)categoryContents); appendCategoryResult.ThrowIf(); } }
/// <summary> /// Sets the specified window's thumbnail tooltip. /// </summary> /// <param name="hwnd">The window.</param> /// <param name="tooltip">The tooltip text.</param> private static void SetThumbnailTooltip(this Form form, string tooltip) { HResult setThumbnailTooltipResult = TaskbarList.SetThumbnailTooltip(form.Handle, tooltip); setThumbnailTooltipResult.ThrowIf(); }
public static void SetTaskbarProgressState(IntPtr hwnd, ThumbnailProgressState state) { HResult result = TaskbarList.SetProgressState(hwnd, (uint)state); result.ThrowIf(); }
public static void SetTaskbarProgress(IntPtr hwnd, ulong progress, ulong maximum) { HResult valueResult = TaskbarList.SetProgressValue(hwnd, progress, maximum); valueResult.ThrowIf(); }
/// <summary> /// Retrieves all application destinations belonging to the specified /// application destination type. /// </summary> /// <param name="type">The application destination type.</param> /// <returns>A copy of the application destinations belonging to /// the specified type; modifying the returned objects has no effect /// on the application's destination list.</returns> public IEnumerable <IJumpListDestination> GetApplicationDestinations(ApplicationDestinationType type) { if (type == ApplicationDestinationType.None) { throw new ArgumentException("ApplicationDestinationType can't be NONE"); } IApplicationDocumentLists destinations = (IApplicationDocumentLists) new CApplicationDocumentLists(); Guid iidObjectArray = typeof(IObjectArray).GUID; object obj; HResult getListResult = destinations.GetList((AppDocListType)type, 100, ref iidObjectArray, out obj); getListResult.ThrowIf(); List <IJumpListDestination> returnValue = new List <IJumpListDestination>(); Guid iidShellItem = typeof(IShellItem).GUID; Guid iidShellLink = typeof(IShellLinkW).GUID; IObjectArray array = (IObjectArray)obj; uint count; HResult getCountResult = array.GetCount(out count); getCountResult.ThrowIf(); for (uint i = 0; i < count; ++i) { try { array.GetAt(i, ref iidShellItem, out obj); } catch (Exception) //Wrong type { } if (obj == null) { HResult getAtResult = array.GetAt(i, ref iidShellLink, out obj); getAtResult.ThrowIf(); //This shouldn't fail since if it's not IShellItem //then it must be IShellLink. IShellLinkW link = (IShellLinkW)obj; ShellLink wrapper = new ShellLink(); StringBuilder sb = new StringBuilder(256); HResult getPathResult = link.GetPath(sb, sb.Capacity, IntPtr.Zero, 2); getPathResult.ThrowIf(); wrapper.Path = sb.ToString(); HResult getArgumentsResult = link.GetArguments(sb, sb.Capacity); getArgumentsResult.ThrowIf(); wrapper.Arguments = sb.ToString(); int iconId; HResult getIconLocationResult = link.GetIconLocation(sb, sb.Capacity, out iconId); getIconLocationResult.ThrowIf(); wrapper.IconIndex = iconId; wrapper.IconLocation = sb.ToString(); uint showCmd; HResult getShowCmdResult = link.GetShowCmd(out showCmd); getShowCmdResult.ThrowIf(); wrapper.ShowCommand = (WindowShowCommand)showCmd; HResult getWorkingDirectoryResult = link.GetWorkingDirectory(sb, sb.Capacity); getWorkingDirectoryResult.ThrowIf(); wrapper.WorkingDirectory = sb.ToString(); returnValue.Add(wrapper); } else //It's an IShellItem. { IShellItem item = (IShellItem)obj; ShellItem wrapper = new ShellItem(); string path; HResult getDisplayNameResult = item.GetDisplayName(SIGDN.SIGDN_FILESYSPATH, out path); getDisplayNameResult.ThrowIf(); wrapper.Path = path; //Title and Category are irrelevant here, because it's //an IShellItem. The user might want to see them, but he's //free to go to the IShellItem and look at its property store. returnValue.Add(wrapper); } } return(returnValue); }
public void Clear() { HResult clearResult = UnsafeNativeMethods.PropVariantClear(ref this); clearResult.ThrowIf(); }