求一个API函数的用法

pheonixdie 2006-10-28 10:38:18
TrackMouseEvent
...全文
198 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhujiujun 2006-11-02
  • 打赏
  • 举报
回复
没有用过贴个msdn出来

TrackMouseEvent
The TrackMouseEvent function posts messages when the mouse pointer leaves a window or hovers over a window for a specified amount of time.

BOOL TrackMouseEvent(
LPTRACKMOUSEEVENT lpEventTrack // pointer to a TRACKMOUSEEVENT
// structure
);

Parameters
lpEventTrack
Pointer to a TRACKMOUSEEVENT structure.
Return Values
If the function succeeds, the return value is nonzero .

If the function fails, return value is zero. To get extended error information, callGetLastError.

The messages that the function can post are the following:

Message Meaning
WM_MOUSEHOVER The mouse hovered over the client area of the window for the period of time specified in a prior call to TrackMouseEvent. Hover tracking stops when this message is generated. The application must call TrackMouseEvent again if it requires further tracking of mouse hover behavior.
WM_MOUSELEAVE The mouse left the client area of the window specified in a prior call to TrackMouseEvent. All tracking requested by TrackMouseEvent is canceled when this message is generated. The application must call TrackMouseEvent when the mouse re-enters its window if it requires further tracking of mouse hover behavior.


Remarks
The mouse pointer is considered to be hovering when it stays within a specified rectangle for a specified period of time. Call SystemParametersInfo and use the values SPI_GETMOUSEHOVERWIDTH, SPI_GETMOUSEHOVERHEIGHT, and SPI_GETMOUSEHOVERTIME to retrieve the size of the rectangle and the time.

QuickInfo
Alzzl 2006-10-29
  • 打赏
  • 举报
回复
foxapi 上面找来的例子:

'Example Name:TrackMouseEvent
'In a form (Form1)
Private Sub Form_Click()
Dim ET As TRACKMOUSEEVENTTYPE
'initialize structure
ET.cbSize = Len(ET)
ET.hwndTrack = Me.hWnd
ET.dwFlags = TME_LEAVE
'start the tracking
TrackMouseEvent ET
'show a message to the user
Me.Print "Move the mouse cursor outside the form" + vbCrLf + "to generate a WM_MOUSELEAVE event"
End Sub
Private Sub Form_Load()
'KPD-Team 2001
'URL: KPDTeam@Allapi.net
'E-Mail: KPDTeam@Allapi.net
'show a warning message
MsgBox "WARNING: This sample uses subclassing." + vbCrLf + "To end this program, always use the X button of the form." + vbCrLf + "Do not use VB's Stop button and do not use the 'End' keyword in your VB code." + vbCrLf + vbCrLf + "For more information about subclassing, check out" + vbCrLf + "our subclassing tutorial at http://www.allapi.net/", vbExclamation
'set the graphics mode to persistent
Me.AutoRedraw = True
Me.Print "Click the form to begin"
'start subclassing this form
HookForm Me
End Sub
Private Sub Form_Unload(Cancel As Integer)
'stop subclassing this form
UnHookForm Me
End Sub
'In a module
Public Const TME_CANCEL = &H80000000
Public Const TME_HOVER = &H1&
Public Const TME_LEAVE = &H2&
Public Const TME_NONCLIENT = &H10&
Public Const TME_QUERY = &H40000000
Public Const WM_MOUSELEAVE = &H2A3&
Public Type TRACKMOUSEEVENTTYPE
cbSize As Long
dwFlags As Long
hwndTrack As Long
dwHoverTime As Long
End Type

Public Declare Function TrackMouseEvent Lib "user32" (lpEventTrack As TRACKMOUSEEVENTTYPE) As Long
Public Declare Function SetCursorPos Lib "user32.dll" (ByVal x As Long, ByVal y As Long) As Long
'Subclassing is explained in our subclassing tutorial at http://www.allapi.net/
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) 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
Public Const GWL_WNDPROC = (-4)
Public PrevProc As Long
Public Sub HookForm(F As Form)
PrevProc = SetWindowLong(F.hWnd, GWL_WNDPROC, AddressOf WindowProc)
End Sub
Public Sub UnHookForm(F As Form)
SetWindowLong F.hWnd, GWL_WNDPROC, PrevProc
End Sub
Public Function WindowProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If uMsg = WM_MOUSELEAVE Then
'if we receive a WM_MOUSELEAVE message, show it
Form1.Print "The mouse left the form!"
End If
WindowProc = CallWindowProc(PrevProc, hWnd, uMsg, wParam, lParam)
End Function

1,486

社区成员

发帖
与我相关
我的任务
社区描述
VB API
社区管理员
  • API
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧