|
論壇說明 |
歡迎您來到『史萊姆論壇』 ^___^ 您目前正以訪客的身份瀏覽本論壇,訪客所擁有的權限將受到限制,您可以瀏覽本論壇大部份的版區與文章,但您將無法參與任何討論或是使用私人訊息與其他會員交流。若您希望擁有完整的使用權限,請註冊成為我們的一份子,註冊的程序十分簡單、快速,而且最重要的是--註冊是完全免費的! 請點擊這裡:『註冊成為我們的一份子!』 |
|
主題工具 | 顯示模式 |
2005-06-22, 12:19 PM | #1 |
版區管理員
|
用Visual Basic 6.0設計TrayIcon
本程式是參考 王國榮先生 所著的Visual Basic 6.0 Windows API講座
不過有一點遺憾,就是在結束時若以End指令結束會出現錯誤 若按表單的關閉鈕則不會,不知是VB的Bug還是小王子的系統有問題 請建一個選單(名稱:Menu): Caption = "選單" Visible = 0 'False Begin VB.Menu Exit Caption = "還原" End 另外再新增一個模組... Form1.frm內容: 語法:
VERSION 5.00 Begin VB.Form Form1 Caption = "Form1" ClientHeight = 3195 ClientLeft = 165 ClientTop = 450 ClientWidth = 4680 LinkTopic = "Form1" ScaleHeight = 3195 ScaleWidth = 4680 StartUpPosition = 3 '系統預設值 Begin VB.Menu Menu Caption = "選單" Visible = 0 'False Begin VB.Menu Exit Caption = "還原" End End End Attribute VB_Name = "Form1" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Private Sub Exit_Click() SetWindowLong Me.hWnd, GWL_WNDPROC, prevWndProc ' 刪除圖示 Dim nid As NOTIFYICONDATA nid.cbSize = Len(nid) nid.hWnd = Me.hWnd nid.uID = uID Shell_NotifyIcon NIM_DELETE, nid Me.Show End Sub Private Sub Form_Load() prevWndProc = GetWindowLong(Me.hWnd, GWL_WNDPROC) SetWindowLong Me.hWnd, GWL_WNDPROC, AddressOf WndProc Dim nid As NOTIFYICONDATA nid.cbSize = Len(nid) nid.hWnd = Me.hWnd nid.uID = uID nid.uFlags = NIF_ICON + NIF_TIP + NIF_MESSAGE nid.hIcon = Me.Icon nid.szTip = "TrayIcon" nid.uCallbackMessage = uMessage Shell_NotifyIcon NIM_ADD, nid Me.Hide Exit Sub End Sub 語法:
Attribute VB_Name = "Module1" Option Explicit Public Const GWL_WNDPROC = (-4) Public Const WM_USER = &H400 Public Const WM_LBUTTONDBLCLK = &H203 Public Const WM_LBUTTONUP = &H202 Public Const WM_RBUTTONDBLCLK = &H206 Public Const WM_RBUTTONUP = &H205 Public Const NIM_ADD = 0 Public Const NIM_MODIFY = 1 Public Const NIM_DELETE = 2 Public Const NIF_MESSAGE = 1 Public Const NIF_ICON = 2 Public Const NIF_TIP = 4 Public Const uID = 9998 Public Const uMessage = WM_USER + 100 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 Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long Public prevWndProc As Long Function WndProc(ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long If Msg = WM_USER + 100 Then If lParam = WM_LBUTTONUP Then Form1.WindowState = vbNormal Form1.Show ElseIf lParam = WM_RBUTTONUP Then Form1.PopupMenu Form1.Menu End If End If WndProc = CallWindowProc(prevWndProc, hWnd, Msg, wParam, lParam) End Function |
送花文章: 1530,
|
2005-06-23, 06:16 AM | #5 (permalink) | |
長老會員
|
引用:
語法:
SetWindowLong Me.hWnd, GWL_WNDPROC, prevWndProc 試試加個DoEvxxx(忘了怎麼拼了) <參考> |
|
__________________ 地獄變現記 [人身得來不易,願大家能尊重生命--勿傷胎命][好淫者請好自為之吧--割鳥] 南泉禪師道: 「道不屬知,不屬不知。知是妄覺,不知是無記。若真達不疑之道,猶如太虛,廓然蕩豁,豈可強是非邪?」 德山宣鑒禪師: 「如果明白無事,則勿妄求,妄求而得,亦非得也。汝但無事於心,無心於事,則虛而靈,空而妙。若毛端許,言之本末者,皆為自欺。何故?毫氂繫念,三塗業因。瞥爾情生,萬劫羈鎖。聖名凡號,盡是虛聲。殊相劣形,皆是幻色。汝欲求之,得無累乎?」 |
||
送花文章: 5469,
|
2005-06-23, 07:23 AM | #7 (permalink) |
版區管理員
|
語法:
VERSION 5.00 Begin VB.Form Form1 Caption = "Form1" ClientHeight = 3195 ClientLeft = 165 ClientTop = 450 ClientWidth = 4680 LinkTopic = "Form1" ScaleHeight = 3195 ScaleWidth = 4680 StartUpPosition = 3 '系統預設值 Begin VB.Menu Menu Caption = "選單" Visible = 0 'False Begin VB.Menu Exit Caption = "離開" End End End Attribute VB_Name = "Form1" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Private Sub Exit_Click() Unload Me End Sub Private Sub Form_Load() prevWndProc = GetWindowLong(Me.hWnd, GWL_WNDPROC) SetWindowLong Me.hWnd, GWL_WNDPROC, AddressOf WndProc Dim nid As NOTIFYICONDATA nid.cbSize = Len(nid) nid.hWnd = Me.hWnd nid.uID = uID nid.uFlags = NIF_ICON + NIF_TIP + NIF_MESSAGE nid.hIcon = Me.Icon nid.szTip = "TrayIcon" nid.uCallbackMessage = uMessage Shell_NotifyIcon NIM_ADD, nid Me.Hide Exit Sub End Sub Private Sub Form_Unload(Cancel As Integer) SetWindowLong Me.hWnd, GWL_WNDPROC, prevWndProc ' 刪除圖示 Dim nid As NOTIFYICONDATA nid.cbSize = Len(nid) nid.hWnd = Me.hWnd nid.uID = uID Shell_NotifyIcon NIM_DELETE, nid Me.Show End Sub 大家試試吧 |
送花文章: 1530,
|