Solved

How to detect double-click on desktop window?

Posted on 2010-09-15
6
1,393 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

910 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

25 Experts available now in Live!

Get 1:1 Help Now