Solved

How to detect double-click on desktop window?

Posted on 2010-09-15
6
1,370 Views
Last Modified: 2013-12-16
Hello,

I am developing an VB.NET 2008 application, that will need to detect double clicks on desktop screen.

I am aware of the global mouse hook written in VB.NET, from the following internet page:
http://www.codeproject.com/KB/DLL/WindowsHookLib.aspx

but this always include clicks on buttons, icons and other items, and from the above example it seems that the desktop and the contained icons from the desktop, always have the same handle and classname.

What I need is to detect ONLY that double-clicks which are not connected with any action (those messages which system is not passing to any other application neither interpret by its own like double-clicks on icons).

Any ideas on how I could filter-out application/icons connected double clicks ?
Just double click on empty desktop area.

Thank you in advance.
0
Comment
Question by:mediasoftware
  • 3
  • 3
6 Comments
 
LVL 23

Accepted Solution

by:
Kamaraj Subramanian earned 500 total points
ID: 33687844

option Explicit



private Declare Function GetAsyncKeyState Lib "user32" _

        (byval vKey as Long) as Integer

private Const VK_LBUTTON = &H1

private Const VK_RBUTTON = &H2



private Sub Form_Load()

    Timer1.Interval = 100

End Sub



private Sub Timer1_Timer()

    If GetAsyncKeyState(VK_LBUTTON) then

        Label2.Caption = "Left Click"

    ElseIf GetAsyncKeyState(VK_RBUTTON) then

        Label2.Caption = "Right Click"

    else

        Label2.Caption = ""

    End If

End Sub

Open in new window

0
 
LVL 23

Expert Comment

by:Kamaraj Subramanian
ID: 33687846
0
 
LVL 23

Expert Comment

by:Kamaraj Subramanian
ID: 33687849
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:mediasoftware
ID: 33687929
Hello itkamaraj,

Maybe I was not explained too well. I effectively use the global mouse hook code from:
http://www.codeproject.com/KB/DLL/WindowsHookLib.aspx

and that code works extremely well.

The one and only problem that I do have is that I need to detect double clicks on desktop screen, not on the icons from the desktop, but double clicks on empty desktop area.

Thank you in advance.
0
 

Author Comment

by:mediasoftware
ID: 33697288
Thank you itkamaraj.

I was followed the links and it's seems to put me in the right direction. Here are the conclusions I ended up with:

To distinguish clicks on desktop if they are on icons or empty place, one way, will probably follows these steps:

First, it should need to obtain information about the desktop icons such as location and size.

Secondly, it would needed for the mouse hook to get the double clicks and the desktop window handle. When a double click event is fired it would need to check if the handle is the desktop handle, if it is, that means the user clicked on desktop not on a window.

Next, if the click is on desktop window than it would needed to compare the icons information (icon size and location) to see if mouse is inside the icon bounds. If it is, that means the click is on the icon.

So the main thing here is to get the icon information. One way to get this information is to use API’s. One thread from the following internet page, might be quite useful: http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/d7df8a4d-fc0f-4b62-80c9-7768756456e6.

That seems to be one way to accomplish this task.

Thank you again, itkamaraj.
0
 

Author Closing Comment

by:mediasoftware
ID: 33697294
Looking forward to work with you.

Thank you, itkamaraj.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now