PITBULLCJR
Dec 15th, 1999, 07:05 AM
Ok I have been working on this for a little while. I want this for to go to the system tray whenever you try to unload it or minimize it if you maximize it it does nothing. Well thats what I want it to do. I have gotten it so that if the try to resize the form it wont let them and if they unload the form it goes to the system tray and you can bring it back up but if they hit the minimize button it will go to the system tray and then when I go to double click on it like I usually do it will just disaper. Which is weird. Here is all of the code for my thingy.
Code:
Under the form I want to do this to.
Private Sub Command2_Click()
'********************************Confirm Exit
cc2 = MsgBox("Are you sure you want to exit login?", vbYesNo, "Login Cancel")
If cc2 = vbYes Then
CreateIcon
Pass.Hide
End If
End Sub
Public Sub CreateIcon()
Dim erg As Long
Dim Tic As NOTIFYICONDATA
Tic.cbSize = Len(Tic)
Tic.hwnd = Picture1.hwnd
Tic.uID = 1&
Tic.uFlags = NIF_DOALL
Tic.uCallbackMessage = WM_MOUSEMOVE
Tic.hIcon = Picture1.Picture
Tic.szTip = "Desktop Settings" & Chr$(0)
erg = Shell_NotifyIcon(NIM_ADD, Tic)
End Sub
Public Sub DeleteIcon()
Dim erg As Long
Dim Tic As NOTIFYICONDATA
Tic.cbSize = Len(Tic)
Tic.hwnd = Picture1.hwnd
Tic.uID = 1&
erg = Shell_NotifyIcon(NIM_DELETE, Tic)
End Sub
Private Sub Form_Resize()
Select Case Me.WindowState
Case vbMinimized
CreateIcon
Pass.Hide
Exit Sub
Case vbMaximized
Pass.WindowState = vbNormal
Exit Sub
End Select
If Pass.Height <> 1800 Then
Pass.Height = 1800
End If
If Pass.Width <> 3555 Then
Pass.Width = 3555
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
Blank.Show
End Sub
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
X = X / Screen.TwipsPerPixelX
Select Case X
Case WM_LBUTTONDBLCLK
Pass.Show
DeleteIcon
End Select
End Sub
Under the blank form
Public Sub CreateIcon()
Dim erg As Long
Dim Tic As NOTIFYICONDATA
Tic.cbSize = Len(Tic)
Tic.hwnd = Picture1.hwnd
Tic.uID = 1&
Tic.uFlags = NIF_DOALL
Tic.uCallbackMessage = WM_MOUSEMOVE
Tic.hIcon = Picture1.Picture
Tic.szTip = "Desktop Settings" & Chr$(0)
erg = Shell_NotifyIcon(NIM_ADD, Tic)
End Sub
Public Sub DeleteIcon()
Dim erg As Long
Dim Tic As NOTIFYICONDATA
Tic.cbSize = Len(Tic)
Tic.hwnd = Picture1.hwnd
Tic.uID = 1&
erg = Shell_NotifyIcon(NIM_DELETE, Tic)
End Sub
Private Sub Form_Load()
End Sub
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
X = X / Screen.TwipsPerPixelX
Select Case X
Case WM_LBUTTONDBLCLK
Pass.Show
DeleteIcon
End Select
End Sub
Private Sub Timer1_Timer()
Blank.Height = 0
Blank.Width = 0
If Blank.Visible = True Then
Blank.Hide
CreateIcon
End If
End Sub
Under The Module
Global cc2 As String
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
'Make your own constant, e.g.:
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
The reason for the Blank form is so that when they hit the unload it will not work if you say just createicon and pass.hide so what i said was show the blank form and have that one hide and createicon. so that works fine but the only thing wrong is when you minimize it it will not come back. Also if i do not exit sub under the form_resize() then when you maximize or minimize it will show an error because it can not change the form size back to those sizes since it is max or min. If you could help me i would be greatful.
Code:
Under the form I want to do this to.
Private Sub Command2_Click()
'********************************Confirm Exit
cc2 = MsgBox("Are you sure you want to exit login?", vbYesNo, "Login Cancel")
If cc2 = vbYes Then
CreateIcon
Pass.Hide
End If
End Sub
Public Sub CreateIcon()
Dim erg As Long
Dim Tic As NOTIFYICONDATA
Tic.cbSize = Len(Tic)
Tic.hwnd = Picture1.hwnd
Tic.uID = 1&
Tic.uFlags = NIF_DOALL
Tic.uCallbackMessage = WM_MOUSEMOVE
Tic.hIcon = Picture1.Picture
Tic.szTip = "Desktop Settings" & Chr$(0)
erg = Shell_NotifyIcon(NIM_ADD, Tic)
End Sub
Public Sub DeleteIcon()
Dim erg As Long
Dim Tic As NOTIFYICONDATA
Tic.cbSize = Len(Tic)
Tic.hwnd = Picture1.hwnd
Tic.uID = 1&
erg = Shell_NotifyIcon(NIM_DELETE, Tic)
End Sub
Private Sub Form_Resize()
Select Case Me.WindowState
Case vbMinimized
CreateIcon
Pass.Hide
Exit Sub
Case vbMaximized
Pass.WindowState = vbNormal
Exit Sub
End Select
If Pass.Height <> 1800 Then
Pass.Height = 1800
End If
If Pass.Width <> 3555 Then
Pass.Width = 3555
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
Blank.Show
End Sub
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
X = X / Screen.TwipsPerPixelX
Select Case X
Case WM_LBUTTONDBLCLK
Pass.Show
DeleteIcon
End Select
End Sub
Under the blank form
Public Sub CreateIcon()
Dim erg As Long
Dim Tic As NOTIFYICONDATA
Tic.cbSize = Len(Tic)
Tic.hwnd = Picture1.hwnd
Tic.uID = 1&
Tic.uFlags = NIF_DOALL
Tic.uCallbackMessage = WM_MOUSEMOVE
Tic.hIcon = Picture1.Picture
Tic.szTip = "Desktop Settings" & Chr$(0)
erg = Shell_NotifyIcon(NIM_ADD, Tic)
End Sub
Public Sub DeleteIcon()
Dim erg As Long
Dim Tic As NOTIFYICONDATA
Tic.cbSize = Len(Tic)
Tic.hwnd = Picture1.hwnd
Tic.uID = 1&
erg = Shell_NotifyIcon(NIM_DELETE, Tic)
End Sub
Private Sub Form_Load()
End Sub
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
X = X / Screen.TwipsPerPixelX
Select Case X
Case WM_LBUTTONDBLCLK
Pass.Show
DeleteIcon
End Select
End Sub
Private Sub Timer1_Timer()
Blank.Height = 0
Blank.Width = 0
If Blank.Visible = True Then
Blank.Hide
CreateIcon
End If
End Sub
Under The Module
Global cc2 As String
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
'Make your own constant, e.g.:
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
The reason for the Blank form is so that when they hit the unload it will not work if you say just createicon and pass.hide so what i said was show the blank form and have that one hide and createicon. so that works fine but the only thing wrong is when you minimize it it will not come back. Also if i do not exit sub under the form_resize() then when you maximize or minimize it will show an error because it can not change the form size back to those sizes since it is max or min. If you could help me i would be greatful.