|
-
Jul 11th, 2000, 09:00 AM
#1
Thread Starter
New Member
How can I create a program that launches a window,
runs through a dialog and then closes the window and runs
in the background. I'd like to have application controls
through the use of the System Tray Icon and a shortcut menu
launched from it!
Tips? Pointers? Examples?
Thanks in advance... -Serp
-
Jul 11th, 2000, 12:19 PM
#2
Junior Member
Tray icon
You can put an icon in the system tray by using the following code, you will need a picture box on the form with the icon in it, just make it invisible to the user. When the icon is in the tray make the form invisible.
'API function for adding icon to system tray
Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias _
"Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As _
NOTIFYICONDATA) As Long
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 NIF_MESSAGE = &H1
Public Const NIF_ICON = &H2
Public Const NIF_TIP = &H4
Public Const NIF_DOALL = NIF_MESSAGE Or NIF_ICON Or NIF_TIP
Public Const WM_MOUSEMOVE = &H200
Public Const WM_LBUTTONDBLCLK = &H203
Public Const WM_LBUTTONDOWN = &H201
Public Const WM_RBUTTONDOWN = &H204
'Add the icon to the system tray
Dim TIC As NOTIFYICONDATA
Dim erg As Variant
TIC.cbSize = Len(TIC)
TIC.hWnd = Picture1(iIndex).hWnd
TIC.uID = 1&
TIC.uFlags = NIF_DOALL
TIC.uCallbackMessage = WM_MOUSEMOVE
TIC.hIcon = Picture1.Picture
erg = Shell_NotifyIcon(NIM_ADD, TIC)
'Remove the icon when you close down...
Dim erg As Variant
Dim TIC As NOTIFYICONDATA
TIC.cbSize = Len(TIC)
TIC.hWnd = Picture1.hWnd
TIC.uID = 1&
erg = Shell_NotifyIcon(NIM_DELETE, TIC)
'This function shows a popup menu when the user
'clicks over the tray icon:
Private Sub Picture1_MouseMove(Index As Integer, Button As _ Integer, Shift As Integer, X As Single, Y As Single)
Select Case ScaleX(X, vbTwips, vbPixels)
Case WM_LBUTTONDBLCLK
'Do something here if you wish
Case WM_RBUTTONDOWN
'Usually better to do it with a right click
PopupMenu mnuPopup
End Select
End Sub
Have fun !!
We watch in reverence as Narcissus is turned to a flower.
-
Jul 11th, 2000, 12:35 PM
#3
_______
<?>..took me too long...
Code:
'same house different color...
'add a menu and submenu to form1
'coy and paste this code
'change the menupopup to reflect your menu name
Option Explicit
' Constants required by Shell_NotifyIcon API call
Private Const NIM_ADD = &H0
Private Const NIM_MODIFY = &H1
Private Const NIM_DELETE = &H2
Private Const NIF_MESSAGE = &H1
Private Const NIF_ICON = &H2
Private Const NIF_TIP = &H4
Private Const WM_MOUSEMOVE = &H200
Private Const WM_LBUTTONDOWN = &H201 'Button down
Private Const WM_LBUTTONUP = &H202 'Button up
Private Const WM_LBUTTONDBLCLK = &H203 'Double-click
Private Const WM_RBUTTONDOWN = &H204 'Button down
Private Const WM_RBUTTONUP = &H205 'Button up
Private Const WM_RBUTTONDBLCLK = &H206 'Double-click
'API call
Private Declare Function SetForegroundWindow Lib "user32" _
(ByVal hwnd As Long) As Long
Private Declare Function Shell_NotifyIcon Lib "shell32" _
Alias "Shell_NotifyIconA" _
(ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
Const WM_NCLBUTTONDOWN = &HA1
Const HTCAPTION = 2
'variable declaration
Private nid As NOTIFYICONDATA
'Show form icon in system tray
' User defined type required by Shell_NotifyIcon API call
Private 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
Private Sub asdf_Click()
'this is my submenu item. should be mnuWhatever
Unload Me
End Sub
Private Sub Form_Load()
Me.Show
Me.Refresh
With nid
.cbSize = Len(nid)
.hwnd = Me.hwnd
.uId = vbNull
.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
.uCallBackMessage = WM_MOUSEMOVE
.hIcon = Me.Icon
.szTip = App.ProductName & " " & App.Major & "." & App.Minor & ", Build " & App.Revision & vbNullChar
End With
Shell_NotifyIcon NIM_ADD, nid
MsgBox "you can do all your junk here..ie call procedures etc."
'ie..shell ("C:\myapp.exe")
'set my menu to false my menu is Lateeda should be File or Whatever
lateeda.Visible = False
'when I am finished I set the form to invisible
Form1.Visible = False
End Sub
Private Sub Form_Unload(Cancel As Integer)
' Remove Icon from System Tray
'if you use another unload put this there as well
Shell_NotifyIcon NIM_DELETE, nid
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
'if mouse is left clicked
If Right(Hex(x), 2) = "0F" Then
'PopupMenu very bottom right of screen
PopupMenu lateeda, 0, Form1.ScaleWidth / 0.5, Form1.ScaleHeight / 0.5
End If
End Sub
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|