|
-
January 16th, 2012, 07:20 AM
#1
Removing titlebar and taskbar icons
Hi all,
I'm a fairly competent java developer, but have next no knowledge about c#.
For my own personal use, I'd like to code an app that disables the icons on the titlebars of all visible windows of the windows os. I want all icons of the taskbar gone (exept the system tray area). This is how it should look when it's done: http://www.askvg.com/how-to-remove-p...skbar-buttons/ (this little autohotkey script is broken in win 7)
I use PInvoke to enumerate all visible windows to send a message to them to replace their icon by a blank one.
This is what I got so far from various code sniplets I found on the interwebs:
Code:
using System;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace RemoveAllApplicationIcons
{
class Program
{
// Import the needed Windows-API functions:
// ... for enumerating all running desktop windows
[DllImport("user32.dll")]
static extern bool EnumDesktopWindows(IntPtr hDesktop, EnumDesktopWindowsDelegate lpfn, IntPtr lParam);
private delegate bool EnumDesktopWindowsDelegate(IntPtr hWnd, int lParam);
// ... for getting window informations only from a handle
[DllImport("user32.dll")]
private static extern int GetWindowText(IntPtr hWnd, StringBuilder title, int size);
[DllImport("user32.dll")]
private static extern bool IsWindowVisible(IntPtr hWnd);
// ... for loading an icon
[DllImport("user32.dll")]
static extern IntPtr LoadImage(IntPtr hInst, string lpsz, uint uType, int cxDesired, int cyDesired, uint fuLoad);
// ... for sending messages to other windows
[DllImport("user32.dll")]
static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
// Setup some "global" variables
/// Pointer to an empty icon used to replace all other application icons.
static IntPtr m_pIcon = IntPtr.Zero;
// List of filter window-titles
static string[] m_astrFilter = new string[] { "Start", "Program Manager" };
static void Main(string[] args)
{
// Load the empty icon (from a file in this example)
string strIconFilePath = @"C:\blank.ico"; // Replace with a valid path on your system!
const int IMAGE_ICON = 1;
const int LR_LOADFROMFILE = 0x10;
IntPtr pIcon = LoadImage(IntPtr.Zero, strIconFilePath, IMAGE_ICON, 0, 0, LR_LOADFROMFILE);
// enumerate all desktop windows
EnumDesktopWindows(IntPtr.Zero, new EnumDesktopWindowsDelegate(EnumDesktopWindowsCallback), IntPtr.Zero);
Console.ReadKey();
}
private static bool EnumDesktopWindowsCallback(IntPtr hWnd, int lParam)
{
// Get window title
StringBuilder title = new StringBuilder(256);
GetWindowText(hWnd, title, 256);
string strTitle = title.ToString();
// Get window visibillity
bool bVisible = IsWindowVisible(hWnd);
// window meets all criteria?
if (bVisible && // ... visible
!String.IsNullOrEmpty(strTitle) && // ... has title
!m_astrFilter.Contains(strTitle)) // ... not in filter list
{
// replace icon now
SendMessage(hWnd, 0x80, IntPtr.Zero, m_pIcon);
Console.WriteLine(title); // for debugging only
}
return true;
}
}
}
I get all the windows I want to send a message to (titles appear in the output) and the screen flashes when I execute the compiled exe, but all the icons remain unchanged.
I would appreciate any help to get rid of those pesky icons. Thank you,
ISOmorph
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|