📄 49.asp
字号:
<P><FONT SIZE=+0>... 处理「按下滑鼠」讯息</FONT></P>
<P><FONT SIZE=+0>ElseIf lParam = WM_LBUTTONDBLCLK Then</FONT></P>
<P><FONT SIZE=+0>... 处理「双按滑鼠」讯息</FONT></P>
<P><FONT SIZE=+0>End If</FONT></P>
<P><FONT SIZE=+0>End If</FONT></P>
<P><FONT SIZE=+0>WndProcForIcon = CallWindowProc(prevWndProcForIcon, hWnd,
Msg, wParam, lParam)</FONT></P>
<P><FONT SIZE=+0>End Function</FONT></P>
<P> </P>
</DIR>
</UL>
<P>此一运作模式并不困难, 唯一要特别注意的事情是「讯息编号」(也就是 nid.uCallbackMessage
资料成员与视窗程序的 Msg 参数), 由於 Windows 已经定义了某些讯息(例如 WM_LBUTTONDOWN),
而这些讯息都具有特定意义, 因此我们选用的「讯息编号」绝对不可以与 Windows
已定义的讯息相冲突, 而要避免讯息的冲突, 程式可以使用编号在 WM_USER(=&H400=1024)
以後的讯息, 因为 WM_USER 以後的讯息编号属於 Windows 未定义的讯息。</P>
<P> </P>
<P>此一问题特别困难, 建议您仔细阅读笔者所完成的范例, 如果不太能瞭解其中的意义,
请翻开上一期的「Windows 的讯息系统」, 复习一下。</P>
<P> </P>
<H2>附录 ─ 呼叫本文 API 函数所需之宣告式</H2>
<P> </P>
<P><FONT SIZE=-1>Option Explicit</FONT></P>
<P><FONT SIZE=-1>' 问题</FONT> 1、2、3 所需之宣告</P>
<P><FONT SIZE=-1>Public Const FO_MOVE = &H1</FONT></P>
<P><FONT SIZE=-1>Public Const FO_COPY = &H2</FONT></P>
<P><FONT SIZE=-1>Public Const FO_DELETE = &H3</FONT></P>
<P><FONT SIZE=-1>Public Const FOF_NOCONFIRMATION = &H10</FONT></P>
<P><FONT SIZE=-1>Public Const FOF_NOCONFIRMMKDIR = &H200</FONT></P>
<P><FONT SIZE=-1>Public Const FOF_ALLOWUNDO = &H40</FONT></P>
<P><FONT SIZE=-1>Type SHFILEOPSTRUCT</FONT></P>
<P><FONT SIZE=-1>hWnd As Long</FONT></P>
<P><FONT SIZE=-1>wFunc As Long</FONT></P>
<P><FONT SIZE=-1>pFrom As String</FONT></P>
<P><FONT SIZE=-1>pTo As String</FONT></P>
<P><FONT SIZE=-1>fFlags As Integer</FONT></P>
<P><FONT SIZE=-1>fAborted As Boolean</FONT></P>
<P><FONT SIZE=-1>hNameMaps As Long</FONT></P>
<P><FONT SIZE=-1>sProgress As String</FONT></P>
<P><FONT SIZE=-1>End Type</FONT></P>
<P><FONT SIZE=-1>Declare Function SHFileOperation Lib "shell32.dll"
Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long</FONT></P>
<P><FONT SIZE=-1> </FONT></P>
<P><FONT SIZE=-1>' 问题</FONT> 4 所需之宣告</P>
<P><FONT SIZE=-1>Public Const GWL_WNDPROC = (-4)</FONT></P>
<P><FONT SIZE=-1>Public Const WM_RBUTTONDOWN = &H204</FONT></P>
<P><FONT SIZE=-1>Public Const WM_RBUTTONUP = &H205</FONT></P>
<P><FONT SIZE=-1>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</FONT></P>
<P><FONT SIZE=-1>Declare Function GetWindowLong Lib "user32"
Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long)
As Long</FONT></P>
<P><FONT SIZE=-1>Declare Function SetWindowLong Lib "user32"
Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long,
ByVal dwNewLong As Long) As Long</FONT></P>
<P><FONT SIZE=-1>Public prevWndProc As Long</FONT></P>
<P><FONT SIZE=-1> </FONT></P>
<P><FONT SIZE=-1>' 问题</FONT> 5 所需之宣告</P>
<P><FONT SIZE=-1>Declare Function GetWindowsDirectory Lib "kernel32"
Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal
nSize As Long) As Long</FONT></P>
<P><FONT SIZE=-1> </FONT></P>
<P><FONT SIZE=-1>' 问题</FONT> 6 所需之宣告</P>
<P><FONT SIZE=-1>Declare Function fCreateShellLink Lib "vb5stkit.DLL"
(ByVal folder As String, ByVal ShortCutName As String, ByVal ExePath As
String, ByVal Params As String) As Long</FONT></P>
<P><FONT SIZE=-1> </FONT></P>
<P><FONT SIZE=-1>' 问题</FONT> 7 所需之宣告</P>
<P><FONT SIZE=-1>Public Const SW_SHOWMINIMIZED = 2</FONT></P>
<P><FONT SIZE=-1>Public Const SW_SHOWMAXIMIZED = 3</FONT></P>
<P><FONT SIZE=-1>Public Const SW_SHOW = 5</FONT></P>
<P><FONT SIZE=-1>Declare Function ShellExecute Lib "shell32.dll"
Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpOperation
As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal
lpDirectory As String, ByVal nShowCmd As Long) As Long</FONT></P>
<P><FONT SIZE=-1> </FONT></P>
<P><FONT SIZE=-1>' 问题</FONT> 8 所需之宣告</P>
<P><FONT SIZE=-1>Public Const SYNCHRONIZE = &H100000</FONT></P>
<P><FONT SIZE=-1>Public Const INFINITE = &HFFFFFFFF</FONT></P>
<P><FONT SIZE=-1>Declare Function OpenProcess Lib "kernel32"
(ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId
As Long) As Long</FONT></P>
<P><FONT SIZE=-1>Declare Function CloseHandle Lib "kernel32"
(ByVal hObject As Long) As Long</FONT></P>
<P><FONT SIZE=-1>Declare Function WaitForSingleObject Lib "kernel32"
(ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long</FONT></P>
<P><FONT SIZE=-1> </FONT></P>
<P><FONT SIZE=-1>' 问题</FONT> 9、12 所需之宣告</P>
<P><FONT SIZE=-1>Public Const EM_GETLINECOUNT = &HBA</FONT></P>
<P><FONT SIZE=-1>Public Const EM_LINESCROLL = &HB6</FONT></P>
<P><FONT SIZE=-1>Declare Function SendMessage Lib "user32" Alias
"SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal
wParam As Long, lParam As Any) As Long</FONT></P>
<P><FONT SIZE=-1> </FONT></P>
<P><FONT SIZE=-1>' 问题</FONT> 10 所需之宣告</P>
<P><FONT SIZE=-1>Public Const DRIVE_REMOVABLE = 2</FONT></P>
<P><FONT SIZE=-1>Public Const DRIVE_FIXED = 3</FONT></P>
<P><FONT SIZE=-1>Public Const DRIVE_REMOTE = 4</FONT></P>
<P><FONT SIZE=-1>Public Const DRIVE_CDROM = 5</FONT></P>
<P><FONT SIZE=-1>Public Const DRIVE_RAMDISK = 6</FONT></P>
<P><FONT SIZE=-1>Declare Function GetDriveType Lib "kernel32"
Alias "GetDriveTypeA" (ByVal nDrive As String) As Long</FONT></P>
<P><FONT SIZE=-1> </FONT></P>
<P><FONT SIZE=-1>' 问题</FONT> 11 所需之宣告</P>
<P><FONT SIZE=-1>Public Const OFS_MAXPATHNAME = 128</FONT></P>
<P><FONT SIZE=-1>Public Const OF_READ = &H0</FONT></P>
<P><FONT SIZE=-1>Type OFSTRUCT</FONT></P>
<P><FONT SIZE=-1>cBytes As Byte</FONT></P>
<P><FONT SIZE=-1>fFixedDisk As Byte</FONT></P>
<P><FONT SIZE=-1>nErrCode As Integer</FONT></P>
<P><FONT SIZE=-1>Reserved1 As Integer</FONT></P>
<P><FONT SIZE=-1>Reserved2 As Integer</FONT></P>
<P><FONT SIZE=-1>szPathName(OFS_MAXPATHNAME) As Byte</FONT></P>
<P><FONT SIZE=-1>End Type</FONT></P>
<P><FONT SIZE=-1> </FONT></P>
<P><FONT SIZE=-1>Type SYSTEMTIME</FONT></P>
<P><FONT SIZE=-1>wYear As Integer</FONT></P>
<P><FONT SIZE=-1>wMonth As Integer</FONT></P>
<P><FONT SIZE=-1>wDayOfWeek As Integer</FONT></P>
<P><FONT SIZE=-1>wDay As Integer</FONT></P>
<P><FONT SIZE=-1>wHour As Integer</FONT></P>
<P><FONT SIZE=-1>wMinute As Integer</FONT></P>
<P><FONT SIZE=-1>wSecond As Integer</FONT></P>
<P><FONT SIZE=-1>wMilliseconds As Integer</FONT></P>
<P><FONT SIZE=-1>End Type</FONT></P>
<P><FONT SIZE=-1>Type FileTime</FONT></P>
<P><FONT SIZE=-1>dwLowDateTime As Long</FONT></P>
<P><FONT SIZE=-1>dwHighDateTime As Long</FONT></P>
<P><FONT SIZE=-1>End Type</FONT></P>
<P><FONT SIZE=-1> </FONT></P>
<P><FONT SIZE=-1>Type BY_HANDLE_FILE_INFORMATION</FONT></P>
<P><FONT SIZE=-1>dwFileAttributes As Long</FONT></P>
<P><FONT SIZE=-1>ftCreationTime As FileTime</FONT></P>
<P><FONT SIZE=-1>ftLastAccessTime As FileTime</FONT></P>
<P><FONT SIZE=-1>ftLastWriteTime As FileTime</FONT></P>
<P><FONT SIZE=-1>dwVolumeSerialNumber As Long</FONT></P>
<P><FONT SIZE=-1>nFileSizeHigh As Long</FONT></P>
<P><FONT SIZE=-1>nFileSizeLow As Long</FONT></P>
<P><FONT SIZE=-1>nNumberOfLinks As Long</FONT></P>
<P><FONT SIZE=-1>nFileIndexHigh As Long</FONT></P>
<P><FONT SIZE=-1>nFileIndexLow As Long</FONT></P>
<P><FONT SIZE=-1>End Type</FONT></P>
<P><FONT SIZE=-1>Type TIME_ZONE_INFORMATION</FONT></P>
<P><FONT SIZE=-1>bias As Long</FONT></P>
<P><FONT SIZE=-1>StandardName(32) As Integer</FONT></P>
<P><FONT SIZE=-1>StandardDate As SYSTEMTIME</FONT></P>
<P><FONT SIZE=-1>StandardBias As Long</FONT></P>
<P><FONT SIZE=-1>DaylightName(32) As Integer</FONT></P>
<P><FONT SIZE=-1>DaylightDate As SYSTEMTIME</FONT></P>
<P><FONT SIZE=-1>DaylightBias As Long</FONT></P>
<P><FONT SIZE=-1>End Type</FONT></P>
<P><FONT SIZE=-1> </FONT></P>
<P><FONT SIZE=-1>Declare Function GetTimeZoneInformation Lib "kernel32"
(lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long</FONT></P>
<P><FONT SIZE=-1>Declare Function OpenFile Lib "kernel32" (ByVal
lpFileName As String, lpReOpenBuff As OFSTRUCT, ByVal wStyle As Long) As
Long</FONT></P>
<P><FONT SIZE=-1>Declare Function GetFileInformationByHandle Lib "kernel32"
(ByVal hFile As Long, lpFileInformation As BY_HANDLE_FILE_INFORMATION)
As Long</FONT></P>
<P><FONT SIZE=-1>' Declare Function CloseHandle Lib "kernel32"
(ByVal hObject As Long) As Long</FONT></P>
<P><FONT SIZE=-1>Declare Function FileTimeToSystemTime Lib "kernel32"
(lpFileTime As FileTime, lpSystemTime As SYSTEMTIME) As Long</FONT></P>
<P><FONT SIZE=-1> </FONT></P>
<P><FONT SIZE=-1>' 问题</FONT> 13 所需之宣告</P>
<P><FONT SIZE=-1>Declare Function CreateSolidBrush Lib "gdi32"
(ByVal crColor As Long) As Long</FONT></P>
<P><FONT SIZE=-1>Declare Function SelectObject Lib "gdi32" (ByVal
hdc As Long, ByVal hObject As Long) As Long</FONT></P>
<P><FONT SIZE=-1>Declare Function FloodFill Lib "gdi32" (ByVal
hdc As Long, ByVal X As Long, ByVal Y As Long, ByVal crColor As Long) As
Long</FONT></P>
<P><FONT SIZE=-1> </FONT></P>
<P><FONT SIZE=-1>' 问题</FONT> 14 所需之宣告</P>
<P><FONT SIZE=-1>Declare Function GetDiskFreeSpace Lib "kernel32"
Alias "GetDiskFreeSpaceA" (ByVal lpRootPathName As String, lpSectorsPerCluster
As Long, lpBytesPerSector As Long, lpNumberOfFreeClusters As Long, lpTtoalNumberOfClusters
As Long) As Long</FONT></P>
<P><FONT SIZE=-1> </FONT></P>
<P><FONT SIZE=-1>' 问题</FONT> 15 所需之宣告</P>
<P><FONT SIZE=-1>Public Const NIM_ADD = 0</FONT></P>
<P><FONT SIZE=-1>Public Const NIM_MODIFY = 1</FONT></P>
<P><FONT SIZE=-1>Public Const NIM_DELETE = 2</FONT></P>
<P><FONT SIZE=-1>Public Const NIF_MESSAGE = 1</FONT></P>
<P><FONT SIZE=-1>Public Const NIF_ICON = 2</FONT></P>
<P><FONT SIZE=-1>Public Const NIF_TIP = 4</FONT></P>
<P><FONT SIZE=-1>Type NOTIFYICONDATA</FONT></P>
<P><FONT SIZE=-1>cbSize As Long</FONT></P>
<P><FONT SIZE=-1>hWnd As Long</FONT></P>
<P><FONT SIZE=-1>uID As Long</FONT></P>
<P><FONT SIZE=-1>uFlags As Long</FONT></P>
<P><FONT SIZE=-1>uCallbackMessage As Long</FONT></P>
<P><FONT SIZE=-1>hIcon As Long</FONT></P>
<P><FONT SIZE=-1>szTip As String * 64</FONT></P>
<P><FONT SIZE=-1>End Type</FONT></P>
<P><FONT SIZE=-1> </FONT></P>
<P><FONT SIZE=-1>Public Const WM_LBUTTONDOWN = &H201</FONT></P>
<P><FONT SIZE=-1>Public Const WM_LBUTTONDBLCLK = &H203</FONT></P>
<P><FONT SIZE=-1>Public Const WM_USER = &H400</FONT></P>
<P><FONT SIZE=-1>Public prevWndProcForIcon As Long</FONT></P>
<P><FONT SIZE=-1> </FONT></P>
<P><FONT SIZE=-1>Declare Function Shell_NotifyIconA Lib "SHELL32"
(ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Integer</FONT></P>
<P><FONT SIZE=-1> </FONT></P>
<P><FONT SIZE=-1> </FONT></P>
<P><FONT SIZE=-1>' 问题</FONT> 4 所需之视窗程序</P>
<P><FONT SIZE=-1>Function WndProc(ByVal hWnd As Long, ByVal Msg As Long,
ByVal wParam As Long, ByVal lParam As Long) As Long</FONT></P>
<P><FONT SIZE=-1>If Msg = WM_RBUTTONDOWN Then</FONT></P>
<P><FONT SIZE=-1>' 吃掉这个讯息</FONT></P>
<P><FONT SIZE=-1>Else</FONT></P>
<P><FONT SIZE=-1>WndProc = CallWindowProc(prevWndProc, hWnd, Msg, wParam,
lParam)</FONT></P>
<P><FONT SIZE=-1>End If</FONT></P>
<P><FONT SIZE=-1>End Function</FONT></P>
<P><FONT SIZE=-1> </FONT></P>
<P><FONT SIZE=-1>' 问题</FONT> 15 所需之视窗程序</P>
<P><FONT SIZE=-1>Function WndProcForIcon(ByVal hWnd As Long, ByVal Msg
As Long, ByVal wParam As Long, ByVal lParam As Long) As Long</FONT></P>
<P><FONT SIZE=-1>If Msg = WM_USER Then</FONT></P>
<P><FONT SIZE=-1>If lParam = WM_LBUTTONDOWN Then</FONT></P>
<P><FONT SIZE=-1>MsgBox "按下滑鼠</FONT>", vbInformation + vbSystemModal</P>
<P><FONT SIZE=-1>ElseIf lParam = WM_LBUTTONDBLCLK Then</FONT></P>
<P><FONT SIZE=-1>MsgBox "双按滑鼠</FONT>", vbInformation + vbSystemModal</P>
<P><FONT SIZE=-1>End If</FONT></P>
<P><FONT SIZE=-1>End If</FONT></P>
<P><FONT SIZE=-1>WndProcForIcon = CallWindowProc(prevWndProcForIcon, hWnd,
Msg, wParam, lParam)</FONT></P>
<P><FONT SIZE=-1>End Function</FONT></P>
</BODY>
</HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -