Nov 21, 2009

[tutorial] Visual Basic 6 Minimize To Tray - Minimize to Tray

free web hosting
Open Discussion > MODERATED AREA > Computers > Programming Languages > VB Programming

[tutorial] Visual Basic 6 Minimize To Tray - Minimize to Tray

zachtk8702
This example will "minimize" your program to the system tray when you click on a button, and restore it when you click the system tray icon.

For this example you'll need:
1 Form - Form1
1 button - Command1

Add a Module to your project, and ad this code:

CODE

' Create an Icon in System Tray Needs
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 WM_MOUSEMOVE = &H200
Public Const NIF_MESSAGE = &H1
Public Const NIF_ICON = &H2
Public Const NIF_TIP = &H4
Public Const WM_LBUTTONDBLCLK = &H203 'Double-click
Public Const WM_LBUTTONDOWN = &H201 'Button down
Public Const WM_LBUTTONUP = &H202 'Button up
Public Const WM_RBUTTONDBLCLK = &H206 'Double-click
Public Const WM_RBUTTONDOWN = &H204 'Button down
Public Const WM_RBUTTONUP = &H205 'Button up

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


Now at Form1 add this:
CODE

Code:
Dim nid As NOTIFYICONDATA ' trayicon variable

'----------------------
'--- command1 click ---
'----------------------
Private Sub Command1_Click()
minimize_to_tray
End Sub

'------------------------
'--- create tray icon ---
'------------------------
Sub minimize_to_tray()
Me.Hide
nid.cbSize = Len(nid)
nid.hwnd = Me.hwnd
nid.uId = vbNull
nid.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
nid.uCallBackMessage = WM_MOUSEMOVE
nid.hIcon = Me.Icon ' the icon will be your Form1 project icon
nid.szTip = "blablabla text u want to show when mouse over tray iicon" & vbNullChar
Shell_NotifyIcon NIM_ADD, nid
End Sub

'---------------------------------------------------
'-- Tray icon actions when mouse click on it, etc --
'---------------------------------------------------
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim msg As Long
Dim sFilter As String
msg = x / Screen.TwipsPerPixelX
Select Case msg
Case WM_LBUTTONDOWN
Me.Show ' show form
Shell_NotifyIcon NIM_DELETE, nid ' del tray icon
Case WM_LBUTTONUP
Case WM_LBUTTONDBLCLK
Case WM_RBUTTONDOWN
Case WM_RBUTTONUP
Me.Show
Shell_NotifyIcon NIM_DELETE, nid
Case WM_RBUTTONDBLCLK
End Select
End Sub

'------------------------------
'--- form Actions On unload ---
'------------------------------
Private Sub Form_Unload(Cancel As Integer)
Shell_NotifyIcon NIM_DELETE, nid ' del tray icon
end Sub



Instead of restore it when you click the tray icon, you can make it show a popup with some actions: maximize/close//about//etc!

 

 

 


Comment/Reply (w/o sign-up)

FeedBacker
AWESOME MAN, thank you for the help. FAR simpler then any other examples.

-Adam

Comment/Reply (w/o sign-up)

FeedBacker
Error%20%5C%22Invalid%20use%20of%20property%5C%22
[tutorial] Visual Basic 6 Minimize To Tray

Hello,
When I try this solution, I have error "Invalid use of property" on instruction minimize_to_tray.

Do you have a solution ?
Thanks & regards.

-Marcel

Comment/Reply (w/o sign-up)

FeedBacker
Great! Thank you for wonderful code.

-reply by Zoran Milobratović

Comment/Reply (w/o sign-up)

iGuest-fourtwunty
Great Work
[tutorial] Visual Basic 6 Minimize To Tray

This was exactly what I was looking for. Works great

-reply by fourtwunty

Comment/Reply (w/o sign-up)

iGuest-pols_1226
some problems
[tutorial] Visual Basic 6 Minimize To Tray

Hello.. If this script is nice.. But if I make a new project with simple button and a form for the testing of that code.. It works great, but if I integrate it to my project.. It doesn't work.. Any one would try to help me... Thx..



-reply by pols_1226

Comment/Reply (w/o sign-up)

iGuest-pols_1226
problem
[tutorial] Visual Basic 6 Minimize To Tray

Replying to iGuest



Hello.. If this script is nice.. But if I make a new project with simple button and a form for the testing of that code.. It works great, but if I integrate it to my project.. It doesn't work.. Any one would try to help me... Thx..



-reply by pols_1226

Comment/Reply (w/o sign-up)

iGuest-Harez
Hi, I have a question~

I created a flash file and I connected in vb through shockwave flash.
What I did was, I put in a maximized state so that once I run it, it appears in a maximized state but when I click the restore down button, It only showed the half part of the form and there's no scrollbar to drag for me to be able to see the other contents of the from~What shall I do?Pleas, I need your help.~thanks in advance~

God Bless~

-reply by Harez

Comment/Reply (w/o sign-up)

Evolix
What about the icon in the tray, can you change it or what?

Comment/Reply (w/o sign-up)

jason8100
QUOTE (Evolix @ Oct 18 2008, 03:07 PM) *
<br />What about the icon in the tray, can you change it or what?<br />
the icon in the tray is the same as the icon on your form in the left corner, so if you change the icon of the form by selecting your form and select icon and choose one.
i hope i helped you and sorry for my bad english i am dutch and 13 years old

Comment/Reply (w/o sign-up)



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

Similar Topics

Keywords : visual, basic, 6, minimize, tray, minimize, tray

  1. Tray Info Message
    Kind of popup thingie (8)
  2. Mysql In Visual Basic
    Mysql in visual basic (8)
    I'm am trying to create a script so that visual basic 6 can interact with mysql Any ideas?....
  3. Beginning Visual Basic
    (4)
    CAn anyone give me a guide on VB? I've decided to learn it and I need something to work with....
    thanks ....
  4. My Guidewriter
    Simple Visual Basic program to aid in making guides (3)
    I wrote this about 3 months ago for a different forum (Runescape Forums, one I'm currently a
    G-Mod of. ) and I figured I'd share it with you. All it is, is a text editor with built in
    buttons and menus for adding BBCodes. For example, if you wanted to make something bold, you type
    what you want, highlight it, find bold in the text menu and click it. The nicest thing is, you
    can save, and you don't have to worry about a forum failing after taking hours to write a guide.
    I highly suggest you try it if you write guides often, the members on RsForums really lo....
  5. Some Visual Basic 6.0 Uncompleted Projects
    (2)
    hi friends, i have some good complete and incomplete projects in visual basic 6.0. and now i
    want to sale them for some credit points. 100 credit points only....
  6. Visual Basic And Internet Transmission
    is it possible to encrypt a http request? (2)
    I've used VB before which is why im asking this in the VB forum and not any other forum because
    i know with any other language other than PHP i have no chance so i dont actually know if this is
    possible with VB WHat i want to do is change a HTTP request that is sent to a server so that a web
    filter cannot understand it and block the request. Before anyone says that i shouldnt do that its
    hacking etc...its not...im only doing it to see if it can be done. if i wanted to get around a
    filter i wouldnt bother making my own tool I'd use someone else (skript kiddy-ish ....
  7. Visual Basic 6
    (5)
    Well currently I have the working model edition for Visual Basic 6.0 which won't allow me to
    make .exe files. I was looking into buying the Learning Edition but I can't find it cheap or in
    stock anywhere. I want to try and find it for under $100 used or new. If anyone has it, and would
    like to make the .exe file for me if I send you the files that would be great, or if anyone could
    help me find it for cheap.....
  8. Visual Basic Express Edition Beta
    How does it work? (2)
    Hey, I'm using (sorta) Visual Basic Express Edition Beta 2 (long name, eh?), but I can't
    find any good tutorials on it; all of them are for visual basic.net... Is this the same thing? I
    don't think so, and if I'm right, where can I go to get help for it?....
  9. Visual Basic 6.0 Help Needed
    Adding lines to a textbox without delete (19)
    I need help with Visual Basic 6.0 and adding lines to a textbox without deleting any previous
    lines.. I've gotten as far as finding a way to add the lines, but it deletes the prevous entree.
    Help is appreciated!....
  10. Free Copy Of Visual Studio.net Pro
    STUDENTS ONLY (11)
    Visit THE SPOKE for your free copy of Visual Studio.NET.....
  11. [tutorial] Visual Basic 6 Removing List Duplicates
    Removing List Duplicates (3)
    Removing duplicates from lists is something that you'll have to put up with if you're, say,
    parsing names off Outwar. Many delete-duplicate for...next loops are very slow, especially when you
    have thousands of names to loop through several thousand times for each name on the list. This
    function that I made is, in my opinion, the best and quickest way to do it without too many annoying
    and slow for loops (good for lists 1k +). It compares lstA to lstB. Anything that is in both lists
    is added to lstC. To change it so that anything that isn't in both lists is ....
  12. [tutorial] Visual Basic 6 Downloading Images From A Webpage
    Downloading Images from a webpage (2)
    Here's how to grab an image off the internet easily. You'll need an Inet on your form to do
    this. You can always get rid of your string variables and substitute the actual strings: Code:
    CODE Dim localFile As String Dim remoteFile As String Dim fNum As Long Dim b() As Byte
    remoteFile = "http://www.site.com/image.jpg" localFile = "C:\image.jpg"       fNum = FreeFile b()
    = Inet1.OpenURL(remoteFile, icByteArray) Open localFile For Binary As #fNum Put #fNum, , b() Close
    #fNum MsgBox "Done" Hope this helps. added code bbcode ....

    1. Looking for visual, basic, 6, minimize, tray, minimize, tray

Searching Video's for visual, basic, 6, minimize, tray, minimize, tray
See Also,
advertisement


[tutorial] Visual Basic 6 Minimize To Tray - Minimize to Tray

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com