• Welcome to Valhalla Legends Archive.
 

MouseMove

Started by Stealth, December 23, 2002, 08:58 AM

Previous topic - Next topic

Stealth

Any idea why the Form_MouseMove(Button As Integer, Shift As Integer, X As Single, y As Single) subroutine code isn't firing when the mouse is moved over the form? The code needs to run to retrieve my program from the system tray when it's minimized.. If you've ever used StealthBot v1.1.2 you'll know that the code used to work fine. The latest build uses the same code as 1.1.2 under Form_MouseMove, but the code doesn't execute when the mouse is moved. I ran the source in step-by-step mode (f8) to make sure, and the code just isn't running.

Here is the mousemove code.

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, y As Single)
        'receives the callbacks from the System Tray icon.
    Dim Result As Long
    Dim msg As Long
    
     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

Any help would be greatly appreciated.

Grok

#1
Value of msg?  Try adding to your Select..

Case Else
   MsgBox "My code works, I'm just not setting msg!",vbExclamation


Noodlez

#2
he set message
QuoteIf Me.ScaleMode = vbPixels Then
 msg = X
     Else
 msg = X / Screen.TwipsPerPixelX
     End If

anyway, i didnt read through your code to see whats wrong, but heres the simple code i use
Dim bleh As Long
bleh = x / Screen.TwipsPerPixelX
Select Case bleh
Case WM_LBUTTONDOWN:
Me.PopupMenu mnuSystray
End Select

Stealth

#3
Added a Case Else messagebox just to make sure, same thing. The code doesn't execute whatsoever. To be sure, I ran the program in "F8" mode, step by step, which lights up each line of code as it's executed. Once the form_load and form_resize procedures were done, I ran the mouse across it a number of times with no result. Minimizing it and clicking on the icon / moving over the icon also elicits no response.

Grok

#4
Point of my request was discovery.  You say he set message but look at what he set it to?  How do those compare to the cases in the select?

There's a more fundamental issue here.  "Does MouseMouse get fired on a minimized form?"  It does not on my system, does it on yours?

iago

#5
No (on xp)... maybe a change in the way mousemoves are handled?
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


Stealth

I've been playing around with the code, and it appears that if i replace the Form_Resize code in the latest version (where the tray icon doesn't work) with Form_Resize code from the last working version (1.1.2) the tray icon restores just fine. Therefore, the problem lies not in the Form_MouseMove code but in the Form_Resize code. Here it is.

Private Sub Form_Resize()
    On Error Resume Next
    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 = "StealthBot v1.1.2 Public Edition" & vbNullChar
            End With
       Shell_NotifyIcon NIM_ADD, nid
    Else
       Shell_NotifyIcon NIM_DELETE, nid
            rtbChat.Width = Me.ScaleWidth - lvChannel.Width
            rtbChat.Height = Me.ScaleHeight - cboSend.Height
            txtPre.Height = Me.ScaleHeight - rtbChat.Height
            txtPre.Top = rtbChat.Height
            txtPost.Height = Me.ScaleHeight - rtbChat.Height
            txtPost.Top = rtbChat.Height
            txtPost.Left = cboSend.Width + 700
            lblCurrentChannel.Left = rtbChat.Width
            lblCurrentChannel.Width = lvChannel.Width
            lvChannel.Left = rtbChat.Width
            lvChannel.Height = Me.ScaleHeight - lblCurrentChannel.Height - cboSend.Height
            cboSend.Top = rtbChat.Height
            cboSend.Width = Me.ScaleWidth - txtPre.Width - txtPost.Width
            txtPost.Left = cboSend.Width + 700
            cboSend.SetFocus
    End If
End Sub

 >:( I have no idea what's wrong with this code. It took me quite awhile to get things lined up as I wanted them, can any of you Visual Basic pros see some mistake that could cause the system tray icon code not to work properly?

Edited by Grok, added code tags.
- Stealth
Author of StealthBot

iago

put [code} and [/code} (with square brackets) around code.. looks nicer :D


This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


Stealth

#8
Thank you Grok. :) Any ideas? I've been screwing around with it and it's unbelievably frustrating because even after making the form_resize code exactly the same as in the previous build it refuses to work.
- Stealth
Author of StealthBot

Grok

#9
Well since it is not clear what nid is, I cannot begin to help you.

Stealth

#10
Apologies. Here's the module containing all the code referenced here.

QuoteDeclare 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
- Stealth
Author of StealthBot

Yoni

#11
.uCallBackMessage = WM_MOUSEMOVE
This will send a WM_MOUSEMOVE msg to your form when the mouse moves over the tray icon.
This is popular in VB because VB practically forwards WM_MOUSEMOVE to Form_MouseMove, after scaling wParam and lParam (which is why you had to divide by Screen.TwipsPerPixelX to get the actual message).
However, I guess when the form is minimized/hidden, something eats the WM_MOUSEMOVE messages.
I suggest you drop this idea and use a custom message (like, WM_APP + 1 or similar) and subclass your form to capture it. (Ugh... VB subclassing, here we go again)

Stealth

#12
Thank you Yoni. I've solved the problem by replacing the old WM_MouseMove structure with a subclass, and all is well. =)
- Stealth
Author of StealthBot