Putting a custom icon into the form caption bar - minimize to tray
Hi!
I wonder how this can be done? I've just made a very small programmer's utility for generating Property Procedure listings from a list of variables, and I wonder how I can keep this form handy at all times. A tray icon could be handy. I already have the trayicon class and it's working, but I need to hide the form from a custom command button procedure instead of by minimizing.
Actually, I already have a tray icon class that does the work. However, the problem is that I have to minimize my application to the tray somehow. If I just minimize the form, I can hide it without a problem, but when I double-click the icon in the tray, I want the form to show up again, which is not possible (unless there is a method of showing the form after it has been minimized without clicking on the task bar icon).
I figured the best way would be to add a small button next to the minimize button near the form's X button. When the user clicks it, I hide the form and show the icon in the tray. When the user double-clicks the system tray icon, I delete the icon from the systray and show the form again.
I know this can be done with API, but I don't want to spend another day getting it done if there's a ready-made solution.
You can subclass the form and whenever the Shell_NotifyIcon's CallbackMessage comes up, UNHIDE and reset the windowstate property to 0 for a normal form.
MicroBasic Dragon Shadow Trainer
There is no good or evil in the world...only programmers and fools .
Thanks for the tip. I actually thought about setting WindowState to vbNormal, but I thought the property is read-only. I had to make a form-level boolean variable to know whether the form is minimized so when I double-click the systray icon and the resize event occurs, it doesn't put the app into the systray again.
The easiest way that I know of is this: go to www.kedaman.com and download the kedatray ocx Kedaman has made. It works really good, and it's really simple to use. Then in the form_resize() sub add this code.
Code:
Private Sub Form_Resize()
If Form1.WindowState = vbMinimized Then
Form1.Hide 'if you minimize it, it hides it
ElseIf Form1.WindowState = vbNormal Then
Form1.Show 'shows the form when you bring it back
End If
End Sub
Private Sub Trayicon1_MouseDblClick(Button As Variant)
Form1.WindowState = vbNormal 'sets the window visible again
Form1.Show 'shows the form when you double click the icon in the tray
End Sub