Solved

ShellNotifyIcon - CTRL + DoubleClick

Posted on 2001-07-23
8
253 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
 
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

762 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

23 Experts available now in Live!

Get 1:1 Help Now