System Tray Minimize code failure

11Stealth
11Stealth used Ask the Experts™
on
Using code from another posting on EE, I set up a system to minimize my program into the system tray. It worked fine for awhile. Recently I made some changes to the Form_Resize code, and now you cannot get the program OUT of the system tray by doubleclicking on it. Here's all the code that is involved.

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

    Public 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

'constants required by Shell_NotifyIcon API call:
    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

    Public Declare Function SetForegroundWindow Lib "user32" _
    (ByVal hwnd As Long) As Long

    Public nid As NOTIFYICONDATA

'Main form:
Private Sub Form_Resize()
        txtPre.Top = rtbChat.Height
        txtPost.Top = rtbChat.Height
        txtPost.Left = cboSend.Width + 700
        lblCurrentChannel.Left = rtbChat.Width
        lblCurrentChannel.Width = lvChannel.Width
        lvChannel.Left = rtbChat.Width
        cboSend.Top = rtbChat.Height
        txtPost.Left = cboSend.Width + 700
    If Me.WindowState = vbMinimized Then
            Me.Hide
            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 = "TIP!" & vbNullChar
            End With
        Shell_NotifyIcon NIM_ADD, nid
    Else
        Shell_NotifyIcon NIM_DELETE, nid
        cboSend.SetFocus
        rtbChat.Width = Me.ScaleWidth - lvChannel.Width
        rtbChat.Height = Me.ScaleHeight - cboSend.Height
        txtPre.Height = Me.ScaleHeight - rtbChat.Height
        txtPost.Height = Me.ScaleHeight - rtbChat.Height
        lvChannel.Height = Me.ScaleHeight - lblCurrentChannel.Height - cboSend.Height '  (lblCurrentChannel.Height + cboSend.Height + (3 * Screen.TwipsPerPixelX))
        cboSend.Width = Me.ScaleWidth - txtPre.Width - txtPost.Width
    End If
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, y As Single)
    'this procedure receives the callbacks from the System Tray icon.
    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_LBUTTONDBLCLK    '515 restore form window
       Me.WindowState = vbNormal
       Result = SetForegroundWindow(Me.hwnd)
       Me.Show
      Case WM_RBUTTONUP        '517 display popup menu
       Result = SetForegroundWindow(Me.hwnd)
       Me.PopupMenu mnuTray
     End Select
End Sub

I realize this question should be worth a lot more than 75 points, but I don't have them to give. Any help is greatly appreciated.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
hi,
 just now i checked your code. i am not getting any error, can u pls give me the details ?

Author

Commented:
Other sources tell me the code is correct as well. The problem lies not necessarily in the code but in the fact that MouseMove is no longer (at one point it was) fired when the user moves their cursor over the tray icon.. Any ideas on what could prevent this from happening?

Again, thank you for the help.
Author of the Year 2009

Commented:
Hi 11Stealth,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Refund points and save as a 0-pt PAQ.

11Stealth, Please DO NOT accept THIS comment as an answer.
EXPERTS: Post a comment if you are certain that an expert deserves credit.  Explain why.
==========
DanRollins -- EE database cleanup volunteer

Author

Commented:
Please do. It has been abandoned and a solution was difficult to come about, but for the information of anyone interested I was required to integrate a system of subclassing to trap the necessary events; something was eating them with this method.
Commented:
Per recommendation,

PashaMod
CS Moderator

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial