1 Attachment(s)
VB6 - Sample Tray Activation
Attached is a sample program that uses a Tray Icon to activate a program. It uses dilettante's "NotifyIcon" program.
http://www.vbforums.com/showthread.p...ght=notifyicon
I have left his explanations in the User Control intact. When first activated, the "Tray" program starts as a Icon in the system tray surrounded by red. A balloon will appear stating "Connecting to Server". It will normally time out, but I am using a timer to simulate establishing a connection. This causes the balloon to disappear and the red background on the Icon to also disappear. Moving the mouse over the Icon will show "Connected to Server". Ten seconds later, a second timer is used to simulate an incoming message, which will flash with instructions.
Clicking on the Tray Icon will activate a program called "Sample.exe". You will have to compile that program first before it can be activated.
To return the "Tray" program to it's normal state, or to exit the program, right click on the Tray Icon.
J.A. Coutts
Updated 12/06/2017
Re: VB6 - Sample Tray Activation
thanks.good example
load sample.exe,read the message. Close the program , at the same time start the time2 control again,may need Inter-process communication
Re: VB6 - Sample Tray Activation
This sample program has been modified to change the window that is being subclassed from the UserControl to the main form. The reason for doing this is because only the top level form receives "WM_POWERBROADCAST" messages from the operating system. To test this function, run the Tray Icon program and then let the system go to sleep. When you wake up the system, you should see 2 or 3 Debug messages (4, 7, & 18) depending on how the system was resumed. According to Microsoft, you have about 2 seconds to perform a function after receiving a "PBT_APMSUSPEND" (&H4) message.
Also, the flashing balloon was changed to a steady balloon because of the way that Windows 10 now handles "Toasts".
J.A. Coutts
Re: VB6 - Sample Tray Activation
your code have a bug
UserControl_Initialize
return hwnd=0
fix
Code:
Public Sub Show()
' MsgBox UserControl.Parent.hwnd '& "----" & UserControl.Container.hwnd
Debug.Print FrmHandle
SaveSetting "S Msg", "Settings", "H_Msg", CStr(FrmHandle)
SetProp FrmHandle, "12345", UserControl.hWnd
SubclassMe FrmHandle, Me
now can return hwnd right.
Re: VB6 - Sample Tray Activation
Quote:
Originally Posted by
xxdoc123
your code have a bug
UserControl_Initialize
return hwnd=0
Not a bug. That code was experimental and unused. Initialize should be:
Code:
Private Sub UserControl_Initialize()
nid.cbSize = LenB(nid)
End Sub
Public Sub Show()
SubclassMe FrmHandle, Me
With nid
.hWnd = FrmHandle
.uId = FrmHandle
.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE Or NIF_INFO
.hIcon = mpicIcon.Handle
.uCallBackMessage = WM_APP_NIF
.szTip = mstrToolTip & vbNullChar
End With
Shell_NotifyIcon NIM_ADD, VarPtr(nid)
mblnShown = True
End Sub
Unlike the UserControl handle, the form handle is not available at the time the UserControl is initialized.
J.A. Coutts
1 Attachment(s)
Re: VB6 - Sample Tray Activation
Attached is a simplified version of the Tray Activation program. It does not use a User Control or subclassing, and is based on PCNotifyIcon by Richard L. McCutchen. Instead it uses a single Class module. The User interface with the Tray Icon is achieved through the only visible part; the icon image. As far as I know, the only thing directly usable is the MouseMove event, and from that he was able to determine Left and Right Button Down. The original code used the Double Click events, but I was unable to make those work on Win 8.1, and I really didn't need them. I then added the Context Menu and the Balloon routines. Usage is pretty much the same as the original sample. So far I have tested it on Win Vista, Win 8.1, & Win 10.
J.A. Coutts
Re: VB6 - Sample Tray Activation
Thanks for sharing.
It is working fine in XP
However the Sample project gives run time error 13, on this line -
IcoHwnd = GetSetting("S Msg", "Settings", "H_Msg")
This also happens when I run Sample project directly (not being called from the Tray application)
I have never used the Registry, so the solution is not jumping off the page at me.
Thanks,
Rob
Re: VB6 - Sample Tray Activation
Quote:
Originally Posted by
Bobbles
Thanks for sharing.
It is working fine in XP
However the Sample project gives run time error 13, on this line -
IcoHwnd = GetSetting("S Msg", "Settings", "H_Msg")
This also happens when I run Sample project directly (not being called from the Tray application)
I have never used the Registry, so the solution is not jumping off the page at me.
Thanks,
Rob
Any reference to IcoHwnd can be commented out. It was used to test a different program.
J.A. Coutts
Re: VB6 - Sample Tray Activation
Thanks JA,
appears to have fixed the problem
Rob