Solved

ShellNotifyIcon - CTRL + DoubleClick

Posted on 2001-07-23
8
261 Views
Last Modified: 2010-05-02
Hi,

I am using the shellnotifyicon method of putting an icon in the sytem tray. I can catch right clicks and double clicks just fine, but how can I detect if the ctrl key is held down?

Zaphod.
0
Comment
Question by:Z_Beeblebrox
  • 4
  • 2
  • 2
8 Comments
 
LVL 6

Expert Comment

by:JonFish85
ID: 6310985
Private Declare Function GetAsyncKeyState Lib "user32" Alias "GetAsyncKeyState" (ByVal vKey As Long) As Integer
Private Const VK_CONTROL = &H11


then try this:

If GetAsyncKeyState(VK_CONTROL) <> 0 Then
  'Ctrl Key down...
End If
0
 
LVL 7

Author Comment

by:Z_Beeblebrox
ID: 6311002
Hmmmmmm, this is very strange.

That code works well except for one small problem. If I press ctrl and then double click on the icon, thats fine. If immediately after that I double click without holding ctrl, it says that ctrl is depressed. If I do it again with no ctrl, it works. What is going on?

Zaphod.
0
 
LVL 6

Expert Comment

by:JonFish85
ID: 6311012
try changing this:
If GetAsyncKeyState(VK_CONTROL) <> 0 The
to

If GetAsyncKeyState(VK_CONTROL) > 0 Then
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 7

Author Comment

by:Z_Beeblebrox
ID: 6311029
Nope, that doesn't work. Now it says I have no ctrl until I release ctrl, then the next one says ctrl.

Zaphod.
0
 
LVL 3

Expert Comment

by:casassus
ID: 6311563
What are you using to get retrieve the dbl click event.

The method i use, is to retrieve the result in the MouseMove Event from a form.
And i can know if the CTRL key is in use.

0
 
LVL 7

Author Comment

by:Z_Beeblebrox
ID: 6312421
Hi,

I am use shellnotifyicon, which you pass in the function name to be called whenever the user does anything to the icon. I then check the flags to see what they did. The code that I am using can be seen here:

http://www.mvps.org/vbnet/code/subclass/shellnotifybasic.htm

Zaphod.
0
 
LVL 3

Accepted Solution

by:
casassus earned 50 total points
ID: 6312620
You can do it more easy.

In a bas module
Option Explicit

Type NOTIFYICONDATA
        cbSize As Long
        hwnd As Long
        uID As Long
        uFlags As Long
        uCallbackMessage As Long
        hIcon As Long
        szTip As String * 64
End Type

Public Nid As NOTIFYICONDATA

Public Const NIM_ADD = &H0
Public Const NIM_MODIFY = &H1
Public Const NIM_DELETE = &H2

Public Const NIF_MESSAGE = &H1
Public Const NIF_ICON = &H2
Public Const NIF_TIP = &H4

Public Const WM_MOUSEMOVE = &H200
Public Const WM_LBUTTONDOWN = &H201     'Button down
Public Const WM_LBUTTONUP = &H202       'Button up
Public Const WM_LBUTTONDBLCLK = &H203   'Double-click
Public Const WM_RBUTTONDOWN = &H204     'Button down
Public Const WM_RBUTTONUP = &H205       'Button up
Public Const WM_RBUTTONDBLCLK = &H206   'Double-click

Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long


In a form

Private Sub Form_Load()

With Nid
    .cbSize = Len(Nid)
    .hwnd = Me.hwnd
    .uID = vbNull
    .uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
    .uCallbackMessage = WM_MOUSEMOVE
    .hIcon = Me.Icon
    .szTip = "Hello" & vbNullChar
End With
Call Shell_NotifyIcon(NIM_ADD, Nid)

end sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

Dim Result As Long
Dim msg As Long
       'the value of X will vary depending upon the scalemode setting
If Me.ScaleMode = vbPixels Then
    msg = X
Else
    msg = X / Screen.TwipsPerPixelX
End If

Select Case msg
Case WM_LBUTTONUP        '514 restore form window
Case WM_LBUTTONDBLCLK    '515 restore form window
    Me.WindowState = vbNormal
    Me.Show
Case WM_RBUTTONUP        '517 display popup menu
    ' My menu
    Me.PopupMenu mnuFichier, , , , mnuFichierAfficher
case WM_RBUTTONDBLCLK
    if Shift =2 then
        'Do what you want
    end if
End Select

End Sub
0
 
LVL 7

Author Comment

by:Z_Beeblebrox
ID: 6317349
casassus:

That worked great. It really simplified my code as well.

Thanks,

Zaphod.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

810 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