Solved

How to detect double-click on desktop window?

Posted on 2010-09-15
6
1,492 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 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 

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

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

Question has a verified solution.

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

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

622 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