• Welcome to Valhalla Legends Archive.
 

Minamizing to Tray

Started by TeEhEiMaN, May 24, 2003, 09:22 PM

Previous topic - Next topic

TeEhEiMaN

Can someone tell me how to minamize to tray by clicking a button for VB.

Thanks
TeEhEiMaN

TriCk

I know how to minimize but i dunno how to make it come back up anyway heres the code for that ...

Make a module Called Systray ( or something ) and put this in it

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



Private Sub Form_Resize()
       
   On Error Resume Next
   If Me.WindowState = vbMinimized Then
           Me.Hide
           With NID
               .cbSize = Len(NID)
               .hwnd = frmChat.hwnd
               .uID = vbNull
               .uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
               .uCallbackMessage = WM_MOUSEMOVE
               .hIcon = frmChat.Icon
               .szTip = "StealthBot v1.39 Test Edition" & vbNullChar
           End With
      Shell_NotifyIcon NIM_ADD, NID
   Else
      Shell_NotifyIcon NIM_DELETE, NID
   End If
'        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
'        cboSend.Width = Me.ScaleWidth - txtPre.Width - txtPost.Width
'        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
'        txtPre.Width = Me.ScaleWidth - cboSend.Width - txtPost.Width

End Sub

TriCk

I took that one out of a StealthBot code i had
Enjoy ^^

Stealth

It may be important to note that that code ceased to function, for as-yet unknown reasons, after my 1.4 public release.

It is discussed here: http://forum.valhallalegends.com/phpbbs/index.php?board=5;action=display;threadid=334
- Stealth
Author of StealthBot

TriCk

Stealth
It worked for me...
And TeEhEiMaN

timbo

Private Sub Form_Resize()
   If Me.WindowState = vbMinimized Then Me.Hide
End Sub

TeEhEiMaN

its a really bad minamize to tray tho, Its impossible to bring back, Kinda useless, If anyone knows any better ones please post

OcTaViuS


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 Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
Public nid As NOTIFYICONDATA
     
Sub Initialise(mee As Form)  'Place in form load
   With nid
       .cbSize = Len(nid)
       .hwnd = mee.hwnd
       .uId = vbNull
       .uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
       .uCallBackMessage = WM_MOUSEMOVE
       .hIcon = mee.Icon
       .szTip = " Right Click Mouse Button " & vbNullChar
   End With
   Shell_NotifyIcon NIM_ADD, nid
   mee.Hide
   App.TaskVisible = False

End Sub

Sub PopMenu(mee As Form, x As Single)  'Place in form mouse move
   Dim Msg As Long
   Msg = x / Screen.TwipsPerPixelX

   Select Case Msg
       Case WM_LBUTTONDBLCLK:
         
       Case WM_LBUTTONDOWN:
               
       Case WM_LBUTTONUP:
           mee.PopupMenu mee.mnuPopMenu
       Case WM_RBUTTONDBLCLK:
           
       Case WM_RBUTTONDOWN:
           
       Case WM_RBUTTONUP:
           mee.PopupMenu mee.mnuPopMenu
       
       End Select
End Sub

Sub CloseApp() 'Place in form unload
   Shell_NotifyIcon NIM_DELETE, nid
End Sub

Sub Down(mee As Form)  'Place in form resize
   If mee.WindowState = vbMinimized Then mee.Hide
End Sub


OcTaViuS

ok, ignore the code i just posted its too confusing lol.

i got a method that works, im just trying to reword it so even the biggest newb can understand it.

timbo

i was assuming you knew how to up a tasktray icon already...  i was just nudging you in a possible direction.  you could set the shellnotifyicon in the same if or you could do it at formload.

MrRaza

Again, the forum search option will help you alot. This topic has been covered countless times. You all will soon realize how useful msdn, google and the search page are.

Also if your blind(or stupid), here's a link:  http://forum.valhallalegends.com/phpbbs/index.php?board=17;action=search

OcTaViuS

ok here goes. the biggest newb wont understand but owell.  this is what im now using in my bot.

first u gotta declare it and shyt. put this in a module.

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
     
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 Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
Public nid As NOTIFYICONDATA



U'll need to create a menu for the popup menu when u right click the tray icon.  I named mine 'pop_systray' and added 'connect' 'disconnect' 'maximize' and 'exit' to it for dropdown option thingys.

put this in Form_Load() to keep the menu from showing in the menu bar

pop_systray.Visible = False



my bot minimizes to the tray when you click 'minimize to tray' (named mnusystray) from the menubar.  heres the code for when u click it.

Private Sub mnusystray_Click()
       Me.WindowState = vbMinimized     'minimizes to taskbar
       Me.Hide     'hides form from taskbar
       With nid     'settings for system tray
           .cbSize = Len(nid)
           .hwnd = Me.hwnd
           .uId = vbNull
           .uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
           .uCallBackMessage = WM_MOUSEMOVE
           .hIcon = Me.Icon      'use form's icon in tray
           .szTip = "VeGCHaT Version 1.00 Created By: VeGBoT Products" & vbNullChar      'tooltip text
       End With
    Shell_NotifyIcon NIM_ADD, nid      'adds icon to tray
End Sub



now u gotta add the code to show the right click popup menu, aswell there is also code to maximize from double clicking the icon.

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
   Dim result, Action As Long
   
   'there are two display modes and we need to find out which one the application is using
   
   If Me.ScaleMode = vbPixels Then
       Action = X
   Else
       Action = X / Screen.TwipsPerPixelX
   End If
   
Select Case Action

   Case WM_LBUTTONDBLCLK      'If The Left Button Double Clicks The Icon...
       Me.WindowState = vbNormal      'This will put back into taskbar
           result = SetForegroundWindow(Me.hwnd)
       Me.Show      'this will maximize the form
       Shell_NotifyIcon NIM_DELETE, nid      'this will remove the icon from tray
   
   Case WM_RBUTTONUP      'If The Right Button Is Clicked...
       result = SetForegroundWindow(Me.hwnd)
       PopupMenu pop_systray      'the hidden menu from the menubar becomes your popup menu, cool huh?
   
   End Select
   
End Sub



Heres the code if they click 'Exit' (named 'popExit') from the popup menu

Private Sub popExit_click()
   unload me
End Sub



And if they click 'Maximize' (named 'popMax')...

Private Sub popMax_click()
Dim result As Long
       Me.WindowState = vbNormal
           result = SetForegroundWindow(Me.hwnd)
       Me.Show
       Shell_NotifyIcon NIM_DELETE, nid
End Sub



if they click 'Connect' (named 'popConnect')...

Private Sub popConnect_click()
   'your code to connect the bot
End Sub



And if they click 'Disconnect' (named 'popDisconnect')...

Private Sub popDisconnect_click()
   'your code to disconnect the bot
End Sub



Im pretty sure i mentioned everything on how i did it so that code should work. hope it dont sound too confusing  ;)

OcTaViuS

Quote from: MrRaza on May 25, 2003, 04:24 PM
Again, the forum search option will help you alot. This topic has been covered countless times. You all will soon realize how useful msdn, google and the search page are.

Also if your blind(or stupid), here's a link:  http://forum.valhallalegends.com/phpbbs/index.php?board=17;action=search

msdn is confusing, google takes a long time, and the search doesnt have any (correct) information on this topic.

MrRaza

Then your doing it all wrong.

Zakath

MSDN is an invaluable resource. You're doing Windows programming - well, MSDN contains the definitions for all the API functions that drive a Windows application, as well as details for every standard function in VB. You say it's too confusing...well, learn to use it.

Incidentally, you're incorrect about the search. It's quite easy to find one of several topics where solutions to your exact problem were presented.
Quote from: iago on February 02, 2005, 03:07 PM
Yes, you can't have everybody...contributing to the main source repository.  That would be stupid and create chaos.

Opensource projects...would be dumb.