Solved

ShellNotifyIcon - CTRL + DoubleClick

Posted on 2001-07-23
8
256 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
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.

 
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

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

932 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

13 Experts available now in Live!

Get 1:1 Help Now