Results 1 to 6 of 6

Thread: [RESOLVED] Minimize button question.

  1. #1

    Thread Starter
    Hyperactive Member stilekid007's Avatar
    Join Date
    Apr 2005
    Location
    DUDE! I'm your neighbor! HELLO!!!
    Posts
    388

    Resolved [RESOLVED] Minimize button question.

    Hello,

    Is there any way to make the minimize button in the top right hand corner of the app's form to minimize it to the system tray?

    Currently my program is in the system tray and can minimize it by clicking a cmd button which merely hides the form.

    Is there anyway to do something similar with the real minimize button?

    Thank you and have a great day!
    Stilekid007
    Quote Originally Posted by stilekid007
    I RATE ALL HELPFULL POSTS!

  2. #2
    Frenzied Member wiz126's Avatar
    Join Date
    Jul 2005
    Location
    Mars,Milky Way... Chit Chat Posts: 5,733
    Posts
    1,080

    Re: Minimize button question.

    just place the system try code in this place:

    VB Code:
    1. Private Sub Form_Resize()
    2. If Me.WindowState = 1 Then
    3.             'code here
    4. End If
    5. End Sub
    Last edited by wiz126; Nov 1st, 2005 at 11:05 PM.
    1) If your post has been adequately answered please click in your post on "Mark Thread Resolved".
    2) If someone has been useful to you please show your respect by rating their posts.
    3) Please use [highlight="VB"] 'your code goes in here [/highlight] tags when posting code.
    4) Before posting your question, make sure you checked this links:
    MICROSOFT MSDN -- VB FORUMS SEARCH

    5)Support Classic VB - A PETITION TO MICROSOFT

    ___________________________________________________________________________________
    THINGS TO KNOW ABOUT VB: || VB Examples/Demos
    What are Classes?
    || -
    Where to place a sub/function?(global) || Webbrowser control

  3. #3
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Minimize button question.

    Sure....
    VB Code:
    1. Private Sub Form_Resize()
    2.     If Me.WindowState = vbMinimized Then
    3.         Me.Hide
    4.         Me.WindowState = vbNormal
    5.     End If
    6. End Sub

  4. #4
    Frenzied Member wiz126's Avatar
    Join Date
    Jul 2005
    Location
    Mars,Milky Way... Chit Chat Posts: 5,733
    Posts
    1,080

    Re: Minimize button question.

    here is how to move it to system tray when your app is mimimized:

    also the right click menu in my code is "m" you need to change it to what ever:

    VB Code:
    1. 'declaration for putting the application to system tray
    2. Private Type NOTIFYICONDATA
    3.     cbSize As Long
    4.     hwnd As Long
    5.     uId As Long
    6.     uFlags As Long
    7.     uCallBackMessage As Long
    8.     hIcon As Long
    9.     szTip As String * 64
    10. End Type
    11.  
    12.     'declare constants
    13. Private Const NIM_ADD = &H0
    14. Private Const NIM_MODIFY = &H1
    15. Private Const NIM_DELETE = &H2
    16.  
    17. 'The following constant is the message sent when a mouse event occurs
    18. 'within the rectangular boundaries of the icon in the taskbar status area.
    19.  
    20. Private Const WM_MOUSEMOVE = &H200
    21.  
    22. 'The following constants are the flags that indicate the valid
    23. 'members of the NOTIFYICONDATA data type.
    24. Private Const NIF_MESSAGE = &H1
    25. Private Const NIF_ICON = &H2
    26. Private Const NIF_TIP = &H4
    27.  
    28. 'The following constants are used to determine the mouse input on the
    29. 'the icon in the taskbar status area.
    30.  
    31.     'Left-click constants.
    32. Private Const WM_LBUTTONDBLCLK = &H203   'Double-click
    33. Private Const WM_LBUTTONDOWN = &H201     'Button down
    34. Private Const WM_LBUTTONUP = &H202       'Button up
    35.  
    36.     'Right-click constants.
    37. Private Const WM_RBUTTONDBLCLK = &H206   'Double-click
    38. Private Const WM_RBUTTONDOWN = &H204     'Button down
    39. Private Const WM_RBUTTONUP = &H205       'Button up
    40.  
    41.     'Declare the API function call.
    42. Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
    43.  
    44. 'Dimension a variable as the user-defined data type.
    45. Dim nid As NOTIFYICONDATA
    46. 'write the following in the form load event
    47. 'if ur application as MDI write in MDI_Load else the first form_load event
    48.  
    49. Private Sub Form_Resize()
    50. If Me.WindowState = 1 Then
    51. Me.Hide
    52.     nid.cbSize = Len(nid)
    53.         nid.hwnd = Me.hwnd
    54.         nid.uId = vbNull
    55.         nid.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
    56.         nid.uCallBackMessage = WM_MOUSEMOVE
    57.         nid.hIcon = Me.Icon
    58.    'u can give a tool tip text here
    59.         nid.szTip = "My System Tray Message" & vbNullChar
    60.        'Call the Shell_NotifyIcon function to add the icon to the System Tray
    61.  
    62.         Shell_NotifyIcon NIM_ADD, nid
    63.         MsgBox "In system tray"
    64.  
    65. End If
    66. End Sub
    67. 'create a menu by using menu editor
    68. '   one main menu by Caption"Menu" name "M"
    69. '   one sub menu by name caption "Exit" name "Ex"
    70. 'make the Menu invisible by changing the "visibility" option in properties window
    71.  
    72. 'write the following in MouseMove event
    73. Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    74. Dim msg As Long
    75. Dim sFilter As String
    76. msg = X / Screen.TwipsPerPixelX
    77.     Select Case msg
    78.         Case WM_LBUTTONDOWN
    79.         '      Me.PopupMenu M   'if u want u can call the popup menu
    80.         Case WM_LBUTTONUP
    81.         Case WM_LBUTTONDBLCLK
    82.         Case WM_RBUTTONDOWN
    83.         Case WM_RBUTTONUP
    84.             Me.PopupMenu m  'call the popup menu
    85.         Case WM_RBUTTONDBLCLK
    86.     End Select
    87. End Sub
    1) If your post has been adequately answered please click in your post on "Mark Thread Resolved".
    2) If someone has been useful to you please show your respect by rating their posts.
    3) Please use [highlight="VB"] 'your code goes in here [/highlight] tags when posting code.
    4) Before posting your question, make sure you checked this links:
    MICROSOFT MSDN -- VB FORUMS SEARCH

    5)Support Classic VB - A PETITION TO MICROSOFT

    ___________________________________________________________________________________
    THINGS TO KNOW ABOUT VB: || VB Examples/Demos
    What are Classes?
    || -
    Where to place a sub/function?(global) || Webbrowser control

  5. #5
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Minimize button question.

    @Wiz: I think he already had the icon in the systray and just wanted his app to disappear from the taskbar when it was minimized.

  6. #6

    Thread Starter
    Hyperactive Member stilekid007's Avatar
    Join Date
    Apr 2005
    Location
    DUDE! I'm your neighbor! HELLO!!!
    Posts
    388

    Re: Minimize button question.

    Hey guys!

    Ok, thit is exactly what I needed,

    VB Code:
    1. Private Sub Form_Resize()
    2.     If Me.WindowState = vbMinimized Then
    3.         Me.Hide
    4.         Me.WindowState = vbNormal
    5.     End If
    6. End Sub

    Yes I already have the icon in the system tray. I was working with the form resize option but I was missing a line of code.

    Thanks guys!

    Stilekid007
    Quote Originally Posted by stilekid007
    I RATE ALL HELPFULL POSTS!

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