On 11-14-2002 The Hobo was kind enough to post this code, It works great for the most part but I can't seem to get the button on the title bar to do anything. Could somone assist me and point me in the right sirection.
Thanks
Here is the post:
System Tray and Title Bar Button
This (really long) code is something I wrote awhile ago to demonstrate how to 1) add a button to the title bar, and 2) minimize the form to the system tray.
VB Code:
'form code:
Option Explicit
Private Sub Form_Load()
Init
End Sub
Private Sub Form_Unload(Cancel As Integer)
RemoveIcon
Terminate
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim msg As Long
msg = x / Screen.TwipsPerPixelX
Select Case msg
'Case WM_LBUTTONDOWN
'Case WM_LBUTTONUP
Case WM_LBUTTONDBLCLK
Me.Visible = True
Me.WindowState = 0
'Case WM_RBUTTONDOWN
'Case WM_RBUTTONUP
'Case WM_RBUTTONDBLCLK
End Select
End Sub
Public Sub ButtonPressed()
AddIcon Me, "test"
End Sub
'module code:
Option Explicit
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
(ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, _
lpRect As Rect) As Long
Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, _
ByVal hWndNewParent As Long) As Long
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, _
ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx _
As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Declare Function SetWindowsHookEx Lib "user32" Alias _
most peple I've ever seen do this use a picture box to store the image instead of the form itself, anyhows to get the icon to do something, you need to do code in the form for the click events.
In the MouseUp event, you would do a me.popup menu thingy.
In the DblClick Event you would do form.visible = true
If I can find an example I'll post it later.
It Never Fails. Everytime I try to make a program idiot proof, the world makes a better idiot.
Originally posted by Dalceon he did leave something out.
most peple I've ever seen do this use a picture box to store the image instead of the form itself, anyhows to get the icon to do something, you need to do code in the form for the click events.
In the MouseUp event, you would do a me.popup menu thingy.
In the DblClick Event you would do form.visible = true
If I can find an example I'll post it later.
He is having problems with the button being placed in the title bar, not the icon being placed in the system tray. Unless I am confused...
Button is there.... Just when I press it nothing happens. If I place another button on the form and call the ButtonPressed sub... it works... I get an icon on the tray. I would like to get the same results with the title bar button your code puts there.
Thanks
Last edited by CoderNewbie; Jul 8th, 2003 at 01:39 PM.
I think the problem is with the fact that your use of SetParent. I don't know of any other way to put a button in the titlebar, but if you comment out the SetParent line, the button works at least. It must screw up which window is receiving the WM_COMMAND message. You'll probably have to subclass the button, too.
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Ahh Forget the post before this. If I comment out that line its no longer in the title bar... but the button works... If Hobo doesn't have a fix for this... its back to the drawing board for me. Thanks for the input... and thanks Hobo for taking the time to look at it.
Originally posted by CoderNewbie Any luck on this Hobo? If not let me know so I can figure another way to tray my program. Thanks man.
Whoops. I forgot all about this.
I'm not sure if I left something out when I posted this code, but attached is the source that I had on my hard drive. I ran the code and it works perfectly for me.
The subclassing code seems very strange, never seen anythibng like that before...
The code doesn't work on my PC either...it doesn't trap the button being clicked...starting to think it's the subclassing...will have a look laterz...