Solved

ShellNotifyIcon - CTRL + DoubleClick

Posted on 2001-07-23
8
264 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
[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
  • 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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 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…

730 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