|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
im been trying for ages and i can't seem to be able to make a button which will send my application to the system tray
. could some one give me a idiot guild in how to do this or a very basic code in which i can teach my self by (thank you in advanced Jamie |
|
#2
|
|||
|
|||
|
Well, this question was on the board a couple of days ago. Actually you are not sending the app to the systray. You just hide the window and set an icon in the tray. You can look at the thread System Tray
|
|
#3
|
|||
|
|||
not really a newbie guide ![]() |
|
#4
|
|||
|
|||
|
If I sed you a demo I am sure you wouldn't learn anything. But I can guide you through the process if you want but it must be you who writes the code. OK?
|
|
#5
|
|||
|
|||
|
sure ok umm well if ya email the guide to me ill get back to you
im outta time tonight ...Address : Stvsrmat@aol.com Thank you in adv. ![]() Jamie |
|
#6
|
|||
|
|||
|
Well, my thought was you write code, post it on the board, we comment on you code.
First step: Create a project with a form and all controls you want on the form. I suppose you are not a beginner since you want to start with this coding. Am I right? |
|
#7
|
||||
|
||||
|
IamaVBNewbie
The administrators are going to tell you this anyway, so I'll tell you. You need to pick more descriptive names for your posts. |
|
#8
|
|||
|
|||
|
Quote:
Iv got all buttons etc. but it is more then 1 form. so basicly i do kinda need coding .Thank you in advanced Jamie |
|
#9
|
|||
|
|||
|
OK IamaVBNewbie, I have coded a demo for you.
1. Start a standard exe project. 2. Name the form "frmSysTrayIcon" 3. Insert a commandbutton "Command1" 4. Add a module. Name it "mSysTrayIcon" 5. Past the first part to form code editor. 6. Past the rest to module code editor. Now you can hide the form and get an icon in systray by clicking the command button or the minimize button in sysmenu. By the way. The most elegant way is a button click sending a SendMessage to window process. But I don't know how to set the SC_MINIMIZE to high word of wParam and how to and wParam with 0FFFFh. Who knows? Form code: Code:
Option Explicit
Private Sub Command1_Click()
' SendMessage frmSysTrayIcon.hwnd, WM_SYSCOMMAND, SC_MINIMIZE, 0
note.cbSize = Len(note)
note.hwnd = frmSysTrayIcon.hwnd
note.uID = IDI_TRAY
note.uFlags = NIF_ICON + NIF_MESSAGE + NIF_TIP
note.uCallbackMessage = WM_SHELLNOTIFY
note.hIcon = LoadIcon(ByVal 0&, IDI_WINLOGO)
note.szTip = "Test Form" & Chr$(0)
Shell_NotifyIcon NIM_ADD, note
frmSysTrayIcon.Hide
End Sub
Private Sub Form_Load()
hPopupMenu = CreatePopupMenu
AppendMenu hPopupMenu, MF_STRING, IDM_RESTORE, "&Restore"
AppendMenu hPopupMenu, MF_STRING, IDM_EXIT, "E&xit Program"
OldWndProc = SetWindowLong(frmSysTrayIcon.hwnd, GWL_WNDPROC, AddressOf WindowProc)
End Sub
Module code: Code:
Option Explicit
Public Const GWL_WNDPROC = (-4)
Public Const WM_SYSCOMMAND = &H112
Public Const SC_MINIMIZE = &HF020&
Public Const SC_RESTORE = &HF120&
Public Const SC_CLOSE = &HF060&
Public Const IDI_TRAY = 0
Public Const NIF_MESSAGE = &H1
Public Const NIF_ICON = &H2
Public Const NIF_TIP = &H4
Public Const WM_USER = &H400
Public Const WM_SHELLNOTIFY = WM_USER + 5
Public Const IDI_WINLOGO = 32517
Public Const WM_COMMAND = &H111
Public Const NIM_ADD = &H0
Public Const NIM_DELETE = &H2
Public Const WM_RBUTTONDOWN = &H204
Public Const WM_LBUTTONDBLCLK = &H203
Public Const IDM_RESTORE = 1000
Public Const IDM_EXIT = 1010
Public Const MF_STRING = &H0&
Public Const TPM_RIGHTALIGN = &H8&
Public Const TPM_RIGHTBUTTON = &H2&
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 Type POINTAPI
x As Long
y As Long
End Type
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
(ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" _
(ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function LoadIcon Lib "user32" Alias "LoadIconA" _
(ByVal hInstance As Long, ByVal lpIconName As Long) As Long
Public Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" _
(ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
Public Declare Function CreatePopupMenu Lib "user32" () As Long
Public Declare Function TrackPopupMenu Lib "user32" _
(ByVal hMenu As Long, ByVal wFlags As Long, ByVal x As Long, ByVal y As Long, ByVal nReserved As Long, ByVal hwnd As Long, ByVal lprc As Any) As Long
Public Declare Function AppendMenu Lib "user32" Alias "AppendMenuA" _
(ByVal hMenu As Long, ByVal wFlags As Long, ByVal wIDNewItem As Long, ByVal lpNewItem As Any) As Long
Public Declare Function DestroyMenu Lib "user32" _
(ByVal hMenu As Long) As Long
Public Declare Function GetCursorPos Lib "user32" _
(lpPoint As POINTAPI) As Long
Public Declare Function SetForegroundWindow Lib "user32" _
(ByVal hwnd As Long) As Long
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Any) As Long
Public hPopupMenu As Long
Public OldWndProc As Long
Public note As NOTIFYICONDATA
Dim pt As POINTAPI
Public Function WindowProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If uMsg = WM_SYSCOMMAND Then
If wParam = SC_MINIMIZE Then
note.cbSize = Len(note)
note.hwnd = frmSysTrayIcon.hwnd
note.uID = IDI_TRAY
note.uFlags = NIF_ICON + NIF_MESSAGE + NIF_TIP
note.uCallbackMessage = WM_SHELLNOTIFY
note.hIcon = LoadIcon(ByVal 0&, IDI_WINLOGO)
note.szTip = "Test Form" & Chr$(0)
Shell_NotifyIcon NIM_ADD, note
frmSysTrayIcon.Hide
ElseIf wParam = SC_CLOSE Then
If MsgBox("Close form?", vbYesNo Or vbQuestion) = vbYes Then
Unload frmSysTrayIcon
DestroyMenu hPopupMenu
End If
Else
WindowProc = CallWindowProc(OldWndProc, hwnd, uMsg, wParam, lParam)
End If
ElseIf uMsg = WM_COMMAND Then
If lParam = 0 Then
If wParam = IDM_RESTORE Then
frmSysTrayIcon.Show
ElseIf wParam = IDM_EXIT Then
Unload frmSysTrayIcon
DestroyMenu hPopupMenu
End If
Shell_NotifyIcon NIM_DELETE, note
End If
WindowProc = CallWindowProc(OldWndProc, hwnd, uMsg, wParam, lParam)
ElseIf uMsg = WM_SHELLNOTIFY Then
If wParam = IDI_TRAY Then
If lParam = WM_RBUTTONDOWN Then
GetCursorPos pt
SetForegroundWindow hwnd
TrackPopupMenu hPopupMenu, TPM_RIGHTALIGN + TPM_RIGHTBUTTON, _
pt.x, pt.y, 0, hwnd, ByVal 0&
ElseIf lParam = WM_LBUTTONDBLCLK Then
frmSysTrayIcon.Show
Shell_NotifyIcon NIM_DELETE, note
End If
End If
Else
WindowProc = CallWindowProc(OldWndProc, hwnd, uMsg, wParam, lParam)
End If
End Function
Good luck with the code. |
|
#10
|
|||
|
|||
|
I attach the project
|
|
#11
|
|||
|
|||
|
wopppy thats a bigger code then i though . ty m8 .. iv not got time to test it now
ill do it @ college thank you very much |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Visual Basic Programming > Help me please :(( |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|