• Welcome to Valhalla Legends Archive.
 

[VB] Minimize to Tray - Help

Started by Spilled, August 25, 2005, 03:20 AM

Previous topic - Next topic

Spilled

I have been using the minimize to tray source i found upon this forum, i have ran into a problem and seeking your guys help once again. after having it minimized to tray for awhile it disappears but it's still running in my processes. Any ideas guys? Thanks in advance!

Code:

     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

     Global Const NIM_ADD = &H0
     Global Const NIM_MODIFY = &H1
     Global Const NIM_DELETE = &H2
     Global Const WM_MOUSEMOVE = &H200
     Global Const NIF_MESSAGE = &H1
     Global Const NIF_ICON = &H2
     Global Const NIF_TIP = &H4
     Global Const WM_LBUTTONDBLCLK = &H203   'Double-click
     Global Const WM_LBUTTONDOWN = &H201     'Button down
     Global Const WM_LBUTTONUP = &H202       'Button up

     'Right-click constants.
     Global Const WM_RBUTTONDBLCLK = &H206   'Double-click
     Global Const WM_RBUTTONDOWN = &H204     'Button down
     Global Const WM_RBUTTONUP = &H205       'Button up

     Declare Function Shell_NotifyIcon Lib "shell32" _
        Alias "Shell_NotifyIconA" _
        (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
     Global nid As NOTIFYICONDATA

Sub AddToTray(TrayIcon, TrayText As String, TrayForm As Form)
        'Set the individual values of the NOTIFYICONDATA data type.
        nid.cbSize = Len(nid)
        nid.hwnd = TrayForm.hwnd
        nid.uId = vbNull
        nid.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
        nid.uCallBackMessage = WM_MOUSEMOVE
        nid.hIcon = TrayIcon 'You can replace form1.icon with loadpicture=("icon's file name")
        nid.szTip = TrayText & vbNullChar

        'Call the Shell_NotifyIcon function to add the icon to the taskbar
        'status area.
        Shell_NotifyIcon NIM_ADD, nid
        TrayForm.Hide
End Sub

Sub ModifyTray(TrayIcon, TrayText As String, TrayForm As Form)
        nid.cbSize = Len(nid)
        nid.hwnd = TrayForm.hwnd
        nid.uId = vbNull
        nid.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
        nid.uCallBackMessage = WM_MOUSEMOVE
        nid.hIcon = TrayIcon
        nid.szTip = TrayText & vbNullChar
        Shell_NotifyIcon NIM_MODIFY, nid
End Sub

Sub RemoveFromTray()
Shell_NotifyIcon NIM_DELETE, nid
End Sub

Function RespondToTray(x As Single)
         RespondToTray = 0
         Dim msg As Long
         Dim sFilter As String
         If frmMain.ScaleMode <> 3 Then msg = x / Screen.TwipsPerPixelX Else: msg = x
         Select Case msg
            Case WM_LBUTTONDOWN
            Case WM_LBUTTONUP
            Case WM_LBUTTONDBLCLK 'Left button double-clicked
                RespondToTray = 1
            Case WM_RBUTTONDOWN 'Right button pressed
                RespondToTray = 2
            Case WM_RBUTTONUP
            Case WM_RBUTTONDBLCLK
         End Select
End Function
Sub ShowFormAgain(TrayForm As Form)
    Call RemoveFromTray
        TrayForm.Show
End Sub

QwertyMonster

Why use that code? Why don't you use "System Tray Icon" in your Components folder. And then let's say we have a menu named mnuHide


Private Sub mnuHide_Click()
MySysTrayName.intray = true
MyForm.Hide
End Sub


And if you want it back


Private Sub MySysTrayName_Mousedown() '<-- One click and its back. You can have two clicks, or hover over.
MySysTrayName.intray = False                               
MyForm.Show
End Sub


And you can set the tooltip also for it, for like if you hover across it, it says "LoLBoT!! v1".

Yegg

Maybe he doesn't want it to rely on another file? Visual Basic 6 relies on enough files as it is (mostly .ocx).

Warrior

Maybe he doesn't care, just hasn't seen the alternative provided by QwertyMonster :p
Quote from: effect on March 09, 2006, 11:52 PM
Islam is a steaming pile of fucking dog shit. Everything about it is flawed, anybody who believes in it is a terrorist, if you disagree with me, then im sorry your wrong.

Quote from: Rule on May 07, 2006, 01:30 PM
Why don't you stop being American and start acting like a decent human?

QwertyMonster

I provided how he could do it, if he wants to do it that way, he can. I'm not saying "USE IT!!!! OR ELSE I EAT YOUR CHILDREN!!!11".

Spilled

Yegg: Thank You

Why rely on another file when i can code it myself? Anywayz, back to the topic, does anyone have any idea why this would be occuring?

Joe[x86]

1) You should rely on another file because, as this topic is here, you can't code it yourself =p

2) You should rely on another file because if Microsoft releases a patch for a bug in it, you dont need to release a new bot.

3) This is general VB programming, not specifically Battle.net Bot Development.
Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.

Tazo

if it takes some time for it to disappear, id say explorer is crashing..someone posted how to make your icon reappear if this happens, search for it.

Warrior

Quote from: Joex86] link=topic=12615.msg125535#msg125535 date=1125056473]
1) You should rely on another file because, as this topic is here, you can't code it yourself =p

2) You should rely on another file because if Microsoft releases a patch for a bug in it, you dont need to release a new bot.

3) This is general VB programming, not specifically Battle.net Bot Development.

Reasons 1 and 2 are stupid. You are correct on 3.

While he can't initially code it himself, perhaps he will see what he is doing wrong.
Microsoft is unlikely to find a bug in MINIMIZING TO SYSTEM TRAY.
Quote from: effect on March 09, 2006, 11:52 PM
Islam is a steaming pile of fucking dog shit. Everything about it is flawed, anybody who believes in it is a terrorist, if you disagree with me, then im sorry your wrong.

Quote from: Rule on May 07, 2006, 01:30 PM
Why don't you stop being American and start acting like a decent human?

Joe[x86]

QuoteMicrosoft is unlikely to find a bug in MINIMIZING TO SYSTEM TRAY.

Pfft, it could apply to other things too, though. =p
Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.

Kp

Quote from: Warrior on August 26, 2005, 09:49 PMMicrosoft is unlikely to find a bug in MINIMIZING TO SYSTEM TRAY.

Agreed.  They usually only find bugs after exploits for the bug have been in the wild for days or weeks. :)  Exploiting any problem in the system tray code would be unlikely, since you'd generally have the ability to do much nastier things if you have the ability to manipulate the notification icons.
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!