Win7 Jump List – II

The last time we stayed on the fact that we have a program that can “group” icons from taskbar. If you run it and understood, it was noticed that the program has one unpleasant flaw in the usability . When you set the program to run by default – it can not be seen. Required to rely on their memories and habits. So we will correct this deficiency.

As you probably noticed last time, the images I have shown are mini-icons-default applications and those applications I have several. So let us consider in more detail how to achieve this for you too.

Overlay

The easiest way, which enables you to draw an extra icon on top of existing – to use an overlay of the Win API Codec Pack. For this we need only to know the path to the object,in which will contain an icon. The way we are still taken from our class to store list elements LinkInfo

[Serializable]
public class LinkInfo {
    public string Name { get; set; }
    public string AppPath{ get; set; }
    public bool IsDefault{ get; set; }
}

So, the code for the overlay will look like:

private void SetOverlayIcon(LinkInfo linkInfo) {
    var icon = System.Drawing.Icon.ExtractAssociatedIcon(linkInfo.AppPath);
    TaskbarManager.Instance.SetOverlayIcon(this, icon, "Icon Name");
}

The first mode of action you pull out the icon from the resource. The second action is putting it on top of a working application icons.

This can be used for running the program and the overlay will look very good. I personally like. But when you quit all at once disappear = (And it’s certainly not happy, because I will not know that the default program to start.

Independent creation of icons

Yes, we’ll have some work to create icons themselves. Even more, in real time to create your new icon from the available material and make it of default for the program.

I have just showed you how to rip out icons from programs and it’s not a problem. Now we need to put them nicely to each other, and one of them reduced. Let’s start with the latter problem.

I think it is meaningful to ask here is not the absolute size and relative, that is, to be able to say, I decreased the icon-image by 50%. It turns out this is not so difficult. It is necessary to calculate how much these 50% will be in pixels, and ordered to redraw the calculated values.

public Bitmap ResizeBitmap(Bitmap b, int nWidth, int nHeight) {
    var w = (int) (b.Width*(nWidth/100M));
    var h = (int) (b.Height*(nHeight/100M));

    var result = new Bitmap(w, h);
    using (var g = Graphics.FromImage(result)) {
          g.DrawImage(b, 0, 0, w, h);
    }

    return result;
}

We’re getting icon image size. With such a repaint is likely to appear black opaque background and it can remove a single line of code:

mini.MakeTransparent();

Next you need to put the mini image on the current . For a good look I have made ​​a 2-pixel padding on the bottom and right.

public Bitmap OverlayBitmap(Bitmap background, Bitmap overlay) {
    using (var g = Graphics.FromImage(background)) {
         g.DrawImage(overlay, background.Width - overlay.Width - 2, background.Height - overlay.Height - 2);
    }
    return background;
}

Now we have the final image and you want to save as an icon. The original version was quite simple and I’m even glad that everything is so easily obtained.

var intPtr = bitmap.GetHicon();
System.Drawing.Icon.FromHandle(intPtr).Save(fileWriter);

We took a pointer to create icons, icons created and saved to disk. Yes, the icon will be created, but very poor quality, only 16 colors. This is clearly not what I wanted. It was necessary to look in the Internet on the subject of new knowledge and libraries) and a library was found – IconLib

Without going into details, the library can be applied as follows:

var sIcon = new MultiIcon().Add("Icon");
sIcon.CreateFrom(bitmap, IconOutputFormat.Vista);
sIcon.Save(iconPath);

Icon is a much better! In this it was decided to stop at will and is slightly worse than the original. Now you only have to replace the icon with the shortcut!

Creating shortcuts

.Net has no means to create and edit shortcuts.

Yes, there is an omission. I do not know why, but true. For a long time I used the library Interop.IWshRuntimeLibrary.dll and creating shortcuts in my whole suit. But the way has stopped working when used. Net 4.0, so it will not even talk about it and. Had once again to seek new ways to create shortcuts. If it was only a banal xml or some other human-readable format, but no.

In the end, I found an archive with source code, which unfortunately did not want to decompressed but luckily at the site you can view the source code. It turned out that it is necessary only two files and create a shortcut becomes to child’s play:

using (var shortcut = new ShellLink()) {
    shortcut.Target = appPath;
    shortcut.WorkingDirectory = Path.GetDirectoryName(appPath);
    shortcut.Description = name;
    shortcut.DisplayMode = ShellLink.LinkDisplayMode.edmNormal;
    shortcut.IconPath = iconPath;
    shortcut.Save(linkPath);
}

To me everything is clear without words. With Interop.IWshRuntimeLibrary.dll shortcuts created as follows:

WshShell shell = new WshShellClass();
IWshShortcut link =  (IWshShortcut)shell.CreateShortcut(shortcutFullName);

link.TargetPath = target;
link.Description = description;
link.Save();

About the program

During the development I have not managed to identify patterns in how the same to make the icons in the taskbar updated quickly. A couple of times managed to do, but to fix the result failed. Update icon is when you reboot, login, out of sleep.

When you fasten the program to the taskbar, the label is created at % USER_DIR% \ AppData \ Roaming \ Microsoft \ Internet Explorer \ Quick Launch \ User Pinned \ TaskBar, and accordingly there to look for the label and update it.

Now the program can only work with one sheet of programs and program by default, you can specify only one. The latter limitation is very easy to remove, but to an executable file has worked with several sheets and attached to the taskbar will probably more difficult. The fact that the jump list is created in relation to the window / program. And there is speculation that can create derived windows, and for them to create lists and attach them to the taskbar. So far I’ve just copypased program to another folder and rename the executable file, then set up another jump list)) the program helps me and yet do not want to bother with supplementary windows and others, as it is easier to configure everything by hand. Lazy programmer – a good programmer!

Source code, Application, Files for icons creation

Hard’n’heavy!

Tagged , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>