Autor Beitrag
ISOmorph
Hält's aus hier
Beiträge: 1



BeitragVerfasst: Di 10.01.12 11:28 
Hallo zusammen,

ich kenne mich ganz gut in JAVA aus, aber habe bisher noch nie mit C# gearbeitet

Zu meinem persönlichen Nutzen, würde ich gerne ein kleines Programm entwickeln, welches die icons systemweit in den Titelleisten und in der Taskleiste von Windows ausblendet. Ich möchte dass nicht in JAVA schreiben weil man da nur über unnötige Umwege an die Windows API kommt. Ein zu Windows XP Zeiten noch funktionierendes Beispiel (in AutoHotKey geschrieben) könnt ihr hier sehen: www.askvg.com/how-to...and-taskbar-buttons/

Hier ist der Code den ich mir dank verschiedenen Quellen zusammengereimt habe:

ausblenden volle Höhe C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace IconKiller
{
    class IconKiller
    {
        /// <summary>
        /// filter function
        /// </summary>
        public delegate bool EnumDelegate(IntPtr hWnd, int lParam);

        /// <summary>
        /// check if windows visible
        /// </summary>>
        [DllImport("user32.dll")]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool IsWindowVisible(IntPtr hWnd);

        /// <summary>
        /// return windows text
        /// </summary>
        [DllImport("user32.dll", EntryPoint = "GetWindowText",
        ExactSpelling = false, CharSet = CharSet.Auto, SetLastError = true)]
        public static extern int GetWindowText(IntPtr hWnd, StringBuilder lpWindowText, int nMaxCount);

        /// <summary>
        /// enumarator on all desktop windows
        /// </summary>
        [DllImport("user32.dll", EntryPoint = "EnumDesktopWindows",
        ExactSpelling = false, CharSet = CharSet.Auto, SetLastError = true)]
        public static extern bool EnumDesktopWindows(IntPtr hDesktop, EnumDelegate lpEnumCallbackFunction, IntPtr lParam);

        /// <summary>
        /// Load icon
        /// </summary>
        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        static extern IntPtr LoadImage(IntPtr hInst, string lpsz, IntPtr uType, IntPtr cxDesired, IntPtr cyDesired, IntPtr fuLoad);

        /// <summary>
        /// send message to windows
        /// </summary>
        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);

        /// <summary>
        /// entry point of the program
        /// </summary>

        private const string FILE = "blank.ico";
        private const UInt32 WM_SETICON = 0x80;
        private const int IMAGE_ICON = 1;
        private const int LR_DEFAULTSIZE = 0x40;
        private const int ICON_SMALL = 0;
       
        static void Main(string[] args)
        {
            // Load external icon file
            IntPtr icon = LoadImage(new IntPtr(0), FILE, new IntPtr(IMAGE_ICON), new IntPtr(0), new IntPtr(0), new IntPtr(LR_DEFAULTSIZE));

            // Enumerate all windows
            EnumDelegate filter = delegate(IntPtr hWnd, int lParam)
            {
                // Get the windows title
                StringBuilder strbTitle = new StringBuilder(255);
                int nLength = GetWindowText(hWnd, strbTitle, strbTitle.Capacity + 1);
                string strTitle = strbTitle.ToString();

                // Choose all active windows with a title
                if (IsWindowVisible(hWnd) && string.IsNullOrEmpty(strTitle) == false && strTitle != "Start" && strTitle != "Program Manager")
                {
                    // Output the windows title and send a message to replace the icon
                    Console.WriteLine(strTitle);
                    SendMessage(hWnd, WM_SETICON, new IntPtr(ICON_SMALL), icon);
                }
                return true;
            };

            Console.Read();
        }
    }
}


Das ziehen des Strings aus der Titelleiste funktioniert tadellos, aber die icons bleiben bestehen. Kann mir vielleicht jemand weiterhelfen, der sich besser in C# und der WIndows API auskennt? Vielen lieben Dank im voraus.

ISOmorph