Results 1 to 11 of 11

Thread: minilize to the systray

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 1999
    Location
    Ruinen, Drente, Netherlands
    Posts
    192

    minimize to the systray

    How can I minimize a Form to the systemtray by
    clicking on a command button ?

    [Edited by Kars Lensen on 07-11-2000 at 01:36 PM]

  2. #2
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    See..the post above you..re: system icon bla bla
    Change the mouse event to this..
    you could put it into a cmdButton as well but
    you need all except for the popup menu junk
    and the msgbox...I'm sure you get the drift

    Code:
    minimze by clicking the icon in the system tray.
    
    Private Sub picSysTray_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
        'You can use the Hex of the X coord to findout if
        'there was any MouseButton activity
        '2D represents a Left Button Double Click
        '0F represents mouse down (zero)
        '1E represents mouse up
          If Right(Hex(x), 2) = "0F" Then
           
            'System tray Icon Double Clicked
            'If the Window is Minimized, Restore it,
            'Else Minimize it.
          WindowState = IIf(WindowState = vbNormal, vbMinimized, vbNormal)
          Text1.SetFocus
       End If
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  3. #3
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    here is the complete thing..sorry the boss was coming
    around the corner so I rushed my last post...
    Code:
    
    Option Explicit
    
    ' Constants required by Shell_NotifyIcon API call
          Private Const NIM_ADD = &H0
          Private Const NIM_MODIFY = &H1
          Private Const NIM_DELETE = &H2
          Private Const NIF_MESSAGE = &H1
          Private Const NIF_ICON = &H2
          Private Const NIF_TIP = &H4
          Private Const WM_MOUSEMOVE = &H200
          Private Const WM_LBUTTONDOWN = &H201     'Button down
          Private Const WM_LBUTTONUP = &H202       'Button up
          Private Const WM_LBUTTONDBLCLK = &H203   'Double-click
          Private Const WM_RBUTTONDOWN = &H204     'Button down
          Private Const WM_RBUTTONUP = &H205       'Button up
          Private Const WM_RBUTTONDBLCLK = &H206   'Double-click
    
    'API call
          Private Declare Function SetForegroundWindow Lib "user32" _
          (ByVal hwnd As Long) As Long
          
          Private Declare Function Shell_NotifyIcon Lib "shell32" _
          Alias "Shell_NotifyIconA" _
          (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
    
        Const WM_NCLBUTTONDOWN = &HA1
        Const HTCAPTION = 2
        
    'variable declaration
          Private nid As NOTIFYICONDATA
    
    'Show form icon in system tray
    
    ' User defined type required by Shell_NotifyIcon API call
          Private 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
    
    
    Private Sub Form_Load()
           Me.Show
           Me.Refresh
           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 = App.ProductName & " " & App.Major & "." & App.Minor & ", Build " & App.Revision & vbNullChar
           End With
           Shell_NotifyIcon NIM_ADD, nid
       
    End Sub
    
    Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    'You can use the Hex of the X coord to findout if
        'there was any MouseButton activity
        '2D represents a Left Button Double Click
        '0F represents mouse down (zero)
        '1E represents mouse up
          If Right(Hex(X), 2) = "0F" Then
           
            'System tray Icon Double Clicked
            'If the Window is Minimized, Restore it,
            'Else Minimize it.
          WindowState = IIf(WindowState = vbNormal, vbMinimized, vbNormal)
        
       End If
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
       
      ' Remove Icon from System Tray
      'if you use another unload put this there as well
      
      Shell_NotifyIcon NIM_DELETE, nid
       
    End Sub

    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Apr 1999
    Location
    Ruinen, Drente, Netherlands
    Posts
    192

    Re: <?>

    Thanks, but how do i this with me commandbutton ?

  5. #5
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    You can not minimize anything to system tray, if you say minimize it will probably go under the taskbar, in your command button, put
    Code:
    yourform.windowstate=vbminimized
    where yourform is your forms name
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Apr 1999
    Location
    Ruinen, Drente, Netherlands
    Posts
    192
    Originally posted by kedaman
    You can not minimize anything to system tray, if you say minimize it will probably go under the taskbar, in your command button, put
    Code:
    yourform.windowstate=vbminimized
    where yourform is your forms name
    Thanks Kedeman, thats what I want.. (of course, it would be nice if it was just a small icon in the system tray but I am satisfied this far)

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Apr 1999
    Location
    Ruinen, Drente, Netherlands
    Posts
    192
    THANKS to ALL of you !! It works fine now.

  8. #8
    New Member
    Join Date
    Jul 2000
    Posts
    9

    Question

    i do the samething. that the code i put.

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

    and when i click on my icontray

    Private Sub Tray1_DblClick(ByVal Button As Long)
    Me.Visible = True
    End Sub

    But the problem is when i dblClik on the icon my form appear like 1 sec in the windowsBar and dessapear after...I cant see my form.

    What is the problem?

    Sorry for my english.


  9. #9
    Member
    Join Date
    Apr 1999
    Posts
    56
    Im not exactly sure what's happening but I think something similar has happened to me before. If you double click, I think your form gains focus and then loses focus again to the icon. That's what I've been assuming but I really don't know how to fix it. Try, adding me.setfocus in the tray doubleclick event.

  10. #10
    New Member
    Join Date
    Jul 2000
    Posts
    9
    Originally posted by Jimlin41
    Im not exactly sure what's happening but I think something similar has happened to me before. If you double click, I think your form gains focus and then loses focus again to the icon. That's what I've been assuming but I really don't know how to fix it. Try, adding me.socus in the tray doubleclick event.
    Ok, i gonna try something else. if i found the answer i come back to post it. thanks

  11. #11
    Hyperactive Member BramVandenbon's Avatar
    Join Date
    Jan 2002
    Location
    Belgium
    Posts
    502
    dear mags,

    simple question simple answer ...

    When you maximize the form, it also runs the resize code ...
    Maximazing is also a way of resizing !!!
    ____________________________________________

    Please rate my messages. Thank you!
    ____________________________________________
    Bram Vandenbon
    http://www.bramvandenbon.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width