1: Attribute VB_Name = "Module1" 2: Declare Function SetSysModalWindow Lib "User32" (ByVal hWnd As Integer) As Integer 3: Declare Sub SetWindowText Lib "User32" Alias "SetWindowTextA" (ByVal hWnd As Integer, ByVal lpString As String) 4: Declare Function GetWindowTextLength Lib "User32" Alias "GetWindowTextLengthA" (ByVal hWnd%) As Integer 5: Declare Function GetWindow Lib "User32" (ByVal hWnd As Integer, ByVal wCmd As Integer) As Integer 6: Declare Function GetWindowText Lib "User32" Alias "GetWindowTextA" (ByVal hWnd%, ByVal lpSting$, ByVal nMaxCount%) As Integer 7: Declare Function Shell_NotifyIcon& Lib "shell32.DLL" (ByVal lMessage&, NID As NOTIFYICONDATA) 8: Declare Function SHAppBarMessage& Lib "shell32.DLL" (ByVal dwMessage&, pData As APPBARDATA) 9: Declare Function FindWindow% Lib "User32" Alias "FindWindowA" (ByVal lpClassName As Any, ByVal lpCaption As Any) 10: Declare Function SendMessage& Lib "User32" Alias "SendMessageA" (ByVal hWnd%, ByVal wMsg%, ByVal wParam%, ByVal lParam As Long) 11: Declare Function ShowWindow Lib "User32" (ByVal hWnd As Integer, ByVal nCmdShow As Integer) As Integer 12: 13: 14: Type NOTIFYICONDATA 15: lStructureSize As Long 16: hWnd As Long 17: lID As Long 18: lFlags As Long 19: lCallBackMessage As Long 20: hIcon As Long 21: sTip As String * 64 22: End Type 23: 24: Type lRect 25: Left As Long 26: Top As Long 27: Right As Long 28: Bottom As Long 29: End Type 30: 31: Type APPBARDATA 32: lStructureSize As Long 33: hWnd As Long 34: lCallBackMessage As Long 35: lEdge As Long 36: rc As lRect 37: lParam As Long 38: End Type 39: 40: 41: 42: Global idShell_NotifyIcon& 43: Global idSHAppBarMessage& 44: 45: Global Const NIM_ADD = 0& 46: Global Const NIM_DELETE = 2& 47: Global Const NIM_MODIFY = 1& 48: Global Const NIF_ICON = 2& 49: Global Const NIF_MESSAGE = 1& 50: Global Const NIF_TIP = 4& 51: 52: Global Const ABM_GETTASKBARPOS = &H5& 53: 54: Global structNotify As NOTIFYICONDATA 55: Global structBarData As APPBARDATA 56: 57: 'Message blaster callback stuff 58: Const WM_USER = &H400 59: Global Const UM_TASKBARMESSAGE = WM_USER + &H201 60: Global Const POSTPROCESS = 1 61: 62: Function GetWindowHwnd(cp$) 63: GetWindowHwnd = FindWindow(0&, cp$) 64: End Function 65: Sub SetWindowsText(Hwndr As Variant, t$) 66: SetWindowText Hwndr, t$ 67: 68: End Sub 69: Sub CloseProgram(Hwndr) 70: X& = SendMessage(Hwndr, &H112, &HF060, 0&) 71: End Sub 72: 73: 74: Sub ShowWindows(Hwndr, ToF) 75: If ToF Then s = ShowWindow(Hwndr, 1) Else s = ShowWindow(Hwndr, 0) 76: End Sub 77: Sub LoadTaskList(Where As ListBox) 78: Where.Clear 79: CurrWnd = GetWindow(Where.Parent.hWnd, 0) 80: While CurrWnd <> 0 81: Length = GetWindowTextLength(CurrWnd) 82: ListItem$ = Space$(Length + 1) 83: Length = GetWindowText(CurrWnd, ListItem$, Length + 1) 84: If Length > 0 Then 85: Where.AddItem ListItem$ 86: End If 87: CurrWnd = GetWindow(CurrWnd, 2) 88: X = DoEvents() 89: Wend 90: End Sub 91: Sub AddIcon(FormObject As Form, Icon As Variant, Tip$, MsgHk1 As Msghook) 92: 93: Dim ltemplong As Long 94: 95: 'Make sure the Explorer shell is running. If not, we can't use the taskbar 96: structBarData.lStructureSize = 36& 97: ltemplong = SHAppBarMessage(ABM_GETTASKBARPOS, structBarData) 98: If ltemplong <> 1 Then 99: Exit Sub 100: End If 101: 102: 'Set up the data structure for the Shell_NotifyIcon function 103: structNotify.lStructureSize = 88& 104: structNotify.hWnd = FormObject.hWnd 105: structNotify.lID = 0& 106: structNotify.lFlags = NIF_ICON Or NIF_MESSAGE Or NIF_TIP 107: structNotify.lCallBackMessage = UM_TASKBARMESSAGE 108: structNotify.hIcon = Icon 109: structNotify.sTip = Tip$ & Chr$(0) 110: ltemplong = Shell_NotifyIcon(NIM_ADD, structNotify) 111: 112: 'Setup the message blaster to call us when we 113: 'get a message from the shell notify icon 114: MsgHk1.HwndHook = FormObject.hWnd 115: MsgHk1.Message(UM_TASKBARMESSAGE) = True 116: End Sub 117: Sub DeleteIcon(FormObject As Form, MsgHk1 As Msghook) 118: 119: Dim ltemplong As Long 120: 121: 'Make sure the Explorer shell is running. If not, we can't use the taskbar 122: structBarData.lStructureSize = 36& 123: ltemplong = SHAppBarMessage(ABM_GETTASKBARPOS, structBarData) 124: If ltemplong <> 1 Then 125: Exit Sub 126: End If 127: 128: 'Set up the data structure for the Shell_NotifyIcon function 129: ltemplong = Shell_NotifyIcon(NIM_DELETE, structNotify) 130: 131: 'Setup the message blaster to call us when we 132: 'get a message from the shell notify icon 133: ' MsgHk1.HwndHook = FormObject.hWnd 134: ' MsgHk1.Message(UM_TASKBARMESSAGE) = False 135: End Sub 136: |