Let's say I have only the title of a window (a Windows 2000 command console if it makes a difference). How can I minimize it to the system tray, and restore it when the system tray icon for it is clicked?
Printable View
Let's say I have only the title of a window (a Windows 2000 command console if it makes a difference). How can I minimize it to the system tray, and restore it when the system tray icon for it is clicked?
Okay...how can I hide the window at least given just its title?
Heres how, I Think.
Note : I just wrote the code so im not sure if i spelled everything correctly. :)
''Code Starts Here
''This code should go into a bas
Public Declare Function ShowWindow Lib "user32.dll" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Public Declare Function FindWindow Lib "user32" Alias _
"FindWindowA" (ByVal lpClassName As String, ByVal _
lpWindowName As String) As Long
Public HiddenWindow as long
Public sub WindowToSys(title as string, picturebox DisplayIcon)
HiddenWindow = FindWindow(vbNullString, title)
if HiddenWindow <> 0 then
StartIcon DisplayIcon,title
ShowWindow HiddenWindow, 0
end if
end sub
'''''''''''''''''''''''''''''''''''''''
'Put this code in its own bas file called SYSICON Please
Option Explicit
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 Const NIM_ADD = &H0
Private Const NIM_MODIFY = &H1
Private Const NIM_DELETE = &H2
Private Const WM_MOUSEMOVE = &H200
Private Const NIF_MESSAGE = &H1
Private Const NIF_ICON = &H2
Private Const NIF_TIP = &H4
Private Declare Function Shell_NotifyIcon Lib "shell32" _
Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid _
As NOTIFYICONDATA) As Boolean
Dim t As NOTIFYICONDATA
Public Sub stopIcon()
Shell_NotifyIcon NIM_DELETE, t
End Sub
Public Sub UpdateIcon(pic As PictureBox)
Static i As Long, img As Long
t.cbSize = Len(t)
t.hwnd = pic.hwnd
t.uId = 1&
t.uFlags = NIF_ICON
t.hIcon = pic.Picture
Shell_NotifyIcon NIM_MODIFY, t
'i = i + 1
'If i = 2 Then i = 0
End Sub
Public Sub StartIcon(pic As PictureBox, title As String)
t.cbSize = Len(t)
t.hwnd = pic.hwnd
t.uId = 1&
t.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
t.ucallbackMessage = WM_MOUSEMOVE
t.hIcon = pic.Picture
t.szTip = title & Chr$(0)
Shell_NotifyIcon NIM_ADD, t
End Sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Put this code into that picturebox you sent the WindowToSys
'Make sure it has a 32 X 32 Picture in it.
'May have to change the name
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbKeyLButton and HiddenWindow<>0 Then
ShowWindow HiddenWindow, 1
StopIcon
HiddenWindow=0
End If
End Sub
Thanks, I'll try out the ShowWindow (I was looking for HideWindow API :D). I would have replied earlier but my tasbar was giving me issues and I couldn't have reliably tested the code. :o
Yee-haw, it works. :)