Click here to Skip to main content
Email Password   helpLost your password?

Introduction

The tool can be used as a short cut for launching applications using mouse.
There aren't many technical things to tell in this article. Most of the things are available on the Internet and I searched and used them. I will give the links in this article.

The techniques used are:

  1. Mouse hook
  2. How to get icons from EXE

Background

Thanks to Stephen Toub for the useful article on how to hook the mouse in C#.

How to Use

Using the Code

Mouse Hook

Please follow the above article for the mouse hook process.

The main window has two delegates that will be called by the mouse hook methods.
One for show and hide the window. ShowHide(int x, int y) will show or hide the window in mouse middle click.

The second one is for scrolling the window. ScrollIcon() will increase the page number of the window.

private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
{
    if (nCode >= 0 &&
         MouseMessages.WM_LBUTTONUP == (MouseMessages)wParam)
    {
         //MSLLHOOKSTRUCT hookStruct = (MSLLHOOKSTRUCT)
         //Marshal.PtrToStructure(lParam, typeof(MSLLHOOKSTRUCT));
         //Console.WriteLine(hookStruct.pt.x + ", " + hookStruct.pt.y);
         showhide(0,0);
    }
    else if (nCode >= 0 &&
         MouseMessages.WM_MBUTTONDOWN == (MouseMessages)wParam)
    {
         MSLLHOOKSTRUCT hookStruct = (MSLLHOOKSTRUCT)
	Marshal.PtrToStructure(lParam, typeof(MSLLHOOKSTRUCT));
         showhide(hookStruct.pt.x, hookStruct.pt.y);
         return (IntPtr)(-1);
    }
    else if (nCode >= 0 &&
         MouseMessages.WM_MOUSEWHEEL == (MouseMessages)wParam)
    {
         if (scrolIcon() == true)
         {
             return (IntPtr)(-1);
         }
    }
    return CallNextHookEx(_hookID, nCode, wParam, lParam);
}		

Transparent Window

The second part to consider in the tool is a transparent window containing a matrix of buttons.To make a transparent window in WPF is very simple. Below is the XAML code. Make AllowsTransparency = true and Background='Transparent".

<Window x:Class="ZWheel.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="180" Width="180"  WindowStyle="None" 
		AllowsTransparency="True"
    Background="Transparent" Visibility="Hidden" 
	Icon="/ZWheel;component/ZWheel.ico" Topmost="False" ShowInTaskbar="False">

Get Icons from Filename

The following code is used to get the icons from the file name:

[DllImport("Shell32.dll")]
public extern static int ExtractIconEx(string libName, int iconIndex,
IntPtr[] largeIcon, IntPtr[] smallIcon, int nIcons);

public static Icon GetIconFromPath(string filePath)
{
    int numIcons = 10;//if you want 10 icons for example

    IntPtr[] largeIcon = new IntPtr[numIcons];
    IntPtr[] smallIcon = new IntPtr[numIcons];

    //retrieve icon from array
    Icon smallIco = null;

    try
    {
        if (Directory.Exists(filePath) == true)
        {
             ExtractIconEx("shell32.dll", 0, largeIcon, smallIcon, numIcons);
             smallIco = System.Drawing.Icon.FromHandle(smallIcon[4]);
        }
        else
        {
             ExtractIconEx(filePath, 0, largeIcon, smallIcon, numIcons);
             smallIco = System.Drawing.Icon.FromHandle(smallIcon[0]);
        }
    }
    catch (Exception)
    { }

    return (smallIco);
} 

Put the Icon in the Button

To put the icon on the button, declare each button with an image as below. Get the System.Drawing.icon for the file using the above code. Create a bitmap from the icon and assign the image.Source property as shown in the code below:

 <Button Name="P1_Btn00" Grid.Column="0" Grid.Row="0" Click="Btn_Click">
        <Image Name="IC_Btn00" Stretch="None"  />
 </Button> 
btnIcon = GetIcon.GetIconFromPath(btnInfo.Path);

Bitmap bmp = btnIcon.ToBitmap();
MemoryStream strm = new MemoryStream();
bmp.Save(strm, System.Drawing.Imaging.ImageFormat.Png);
strm.Seek(0, SeekOrigin.Begin);
PngBitmapDecoder pbd = new PngBitmapDecoder
	(strm, BitmapCreateOptions.None, BitmapCacheOption.Default);
btnImage.Source = pbd.Frames[0];

Improvements

I know there is nothing much in the code. I put it just to get some comments on the tool for its improvement. I would also like some ideas to use it in Notebook.

History

You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
GeneralDrag and drop
oned2
9:55 31 Dec '08  
It would be cool if the app allowed drag-n-drop of files to create new shortcuts...

Overall, cool idea. I like the simplicity of the app.

modified on Wednesday, December 31, 2008 3:53 PM

GeneralRe: Drag and drop
_anil_
3:19 1 Jan '09  
Yes its already implimented in the new version. I have send the mail for update. But may be due to New year its taking some time. Just download the 1.0.0.2 version when its available. It has drag and drop between buttons, and also from explorer to buttons.
I will notify when its available.

Regards
Anil

GeneralRe: Drag and drop
_anil_
0:24 6 Jan '09  
Hi
Please check the new version. Its having the Drag and Drop option.

Regards
Anil

GeneralVersion 1.0.0.1 Release
_anil_
22:13 23 Dec '08  
1. The new version will launch the application with double click on the Tray icon.(For non wheel mouse)
2. Right click on the buttons will move between pages.( For non wheel mouse )
3. Option to start application during startup.

Regards
Anil

General[Message Deleted]
georgejh
3:04 23 Dec '08  

GeneralRe: This methodology is under copyright sisnce 1998
_anil_
3:42 23 Dec '08  
I have developed it for my use and for learning WPF. Its some thing similar to your application but very simple one than yours.
If Microsoft had patent for notpad it doesn't mean that we are not allow to develop out editor. Wink

Regards
Anil

General[Message Deleted]
georgejh
3:50 23 Dec '08  

GeneralRe: This methodology is under copyright sisnce 1998
_anil_
3:55 23 Dec '08  
Search for shortcut in download.com and you will find 100 of application with this idea... Big Grin

Regards
Anil

General[Message Deleted]
georgejh
4:11 23 Dec '08  

General[Message Deleted]
georgejh
4:13 23 Dec '08  

GeneralRe: This methodology is under copyright sisnce 1998
_anil_
4:53 23 Dec '08  
Yes I will test the vdesk if you give me and if I feel that is good enough for people to use.
But I will not remove the article from here. Poke tongue you can try other way.
Why I don't want to remove is, people don't like to use MSword for the things they can do in notepad. That is why notepad is there from starting of Windows. Your application has lots of functionality, but one don't need all always.

Regards
Anil

GeneralRe: This methodology is under copyright sisnce 1998
Alex Kvachev
6:36 23 Dec '08  
Hi Georgi,
I'm not into to defending original article, but to make your claim valid you should provide some proof/link to copyright material and valid patent information. Other than that you provide just a link to some horrible web site that give no clear idea what is your application about. What is making me dought that you are saying that applivcation is under development for 10 years and for that period of time you failed to produce something that is well known and usefull. There are hundreds of application launcers in there and most of them compete with each other by means of usability to user, not a claim they are unique copyrighted idea. Copyrighting bycicle is a dead end.
Show me how cool you app comparing to others, prove that it will make my user experience better and I will buy it. If you can not do than, you point is just an attempt to gain advantage over somebody else hard work.
GeneralVote 3
johannesnestler
23:29 22 Dec '08  
1. SourceCode doesn't work. Icon is missing (you use it on the window), no prob - I removed the line. But I don't know what a SettingData object or a Setting-Window is, can't find a reference or a type definition. So it was impossible to compile or run your source. Another question: why did you open the NotifyIcon ContextMenü for "yourself" and didn't use notifyIcon.ContextMenu = ?
-> Please provide a Project containing all references and resources.

2. Article is very poor. You do not mention how to use your app - or anything about the code except the obvious. (Your article isn't about mouse-hooks i think...)

3. Application: I'd provide a way to open the menu without the Mouse-Wheel Click. I agree most people have Wheel-Mouse, but not all!
So a additional ContextMenu entry on the NotifyIcon wouldn't be a bad idea.
If I open the Settings window the first time - it appears in the background. What the hell have you done here?
Another problem when I close the settings window: The mouse cursor and the window freezes for some seconds. I think it's a problem with your hooking!

Don't understand me wrong. I like your idea for this application. I think it's useful and somehow it works. But given the mentioned problems I can only vote 3. Anyway - Thank you for sharing - and with a little more work this can be a realy cool app I will use!
GeneralRe: Vote 3 [modified]
_anil_
3:37 23 Dec '08  
Thank you very much for your comments.
I will upload the whole code.
I know there are bugs, cause I did it on WPF and which I am just learning.
I develop the application in 4 hours and wrote the article in 15 min. I will update the new version soon, and also will improve the article.

Regards
Anil
modified on Tuesday, December 23, 2008 8:47 AM

GeneralRe: Vote 3
_anil_
22:15 23 Dec '08  
Please try the new version. I have given the whole source code also. Smile

Regards
Anil


Last Updated 5 Jan 2009 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2010