?
Solved

How to detect double-click on desktop window?

Posted on 2010-09-15
6
Medium Priority
?
1,530 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 23

Accepted Solution

by:
Kamaraj Subramanian earned 2000 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

719 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