?
Solved

ShellNotifyIcon - CTRL + DoubleClick

Posted on 2001-07-23
8
Medium Priority
?
272 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 200 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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 Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

765 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