请问如何模拟鼠标点击消息,使tabstrip的click事件发生
如何模拟鼠标点击消息,使tabstrip的click事件发生
[解决办法]
仿照
http://topic.csdn.net/u/20090325/07/ab133e9f-de30-4ae0-a3d0-4c0238a651ff.html
[解决办法]
- VB code
Private Sub Class_Initialize() '-- Default snap width m_lSnapWidth = 10 '-- Initialize array (handled windows info) ReDim m_uWndInfo(0) As WND_INFO m_lWndCount = 0End SubPrivate Sub Class_Terminate() '-- Stop subclassing If (m_lWndCount) Then Call Subclass_StopAll End IfEnd Sub'========================================================================================' Subclass handler: MUST be the first Public routine in this file.' That includes public properties also.'========================================================================================Public Sub zSubclass_Proc(ByVal bBefore As Boolean, ByRef bHandled As Boolean, ByRef lReturn As Long, ByRef lng_hWnd As Long, ByRef uMsg As Long, ByRef wParam As Long, ByRef lParam As Long)''Parameters:' bBefore - Indicates whether the the message is being processed before or after the default handler - only really needed if a message is set to callback both before & after.' bHandled - Set this variable to True in a 'before' callback to prevent the message being subsequently processed by the default handler... and if set, an 'after' callback' lReturn - Set this variable as per your intentions and requirements, see the MSDN documentation for each individual message value.' lng_hWnd - The window handle' uMsg - The message number' wParam - Message related data' lParam - Message related data''Notes:' If you really know what you're doing, it's possible to change the values of the' hWnd, uMsg, wParam and lParam parameters in a 'before' callback so that different' values get passed to the default handler.. and optionaly, the 'after' callback Dim rcWnd As RECT2 Dim lc As Long Select Case uMsg '-- Size/Move starting Case WM_ENTERSIZEMOVE '-- Get Desktop area (as first rectangle) Call SystemParametersInfo(SPI_GETWORKAREA, 0, m_rcWnd(0), 0) '-- Get rectangles of all handled windows For lc = 1 To m_lWndCount '-- Window maximized ? If (IsZoomed(m_uWndInfo(lc).hWnd)) Then '-- Take work are rectangle Call CopyMemory(m_rcWnd(lc), m_rcWnd(0), LB_RECT) Else '-- Get window rectangle Call GetWindowRect(m_uWndInfo(lc).hWnd, m_rcWnd(lc)) End If '-- Is it our current window ? If (m_uWndInfo(lc).hWnd = lng_hWnd) Then '-- Get anchor-offset Call GetCursorPos(m_ptAnchor) Call GetCursorPos(m_ptLast) m_ptOffset.x1 = m_rcWnd(lc).x1 - m_ptLast.x1 m_ptOffset.y1 = m_rcWnd(lc).y1 - m_ptLast.y1 End If Next lc '-- Sizing Case WM_SIZING Call CopyMemory(rcWnd, ByVal lParam, LB_RECT) Call pvSizeRect(lng_hWnd, rcWnd, wParam) Call CopyMemory(ByVal lParam, rcWnd, LB_RECT) bHandled = True lReturn = 1 '-- Moving Case WM_MOVING Call CopyMemory(rcWnd, ByVal lParam, LB_RECT) Call pvMoveRect(lng_hWnd, rcWnd) Call CopyMemory(ByVal lParam, rcWnd, LB_RECT) bHandled = True lReturn = 1 '-- Size/Move finishing Case WM_EXITSIZEMOVE Call pvCheckGlueing '-- Special case: *menu* call Case WM_SYSCOMMAND If (wParam = SC_MINIMIZE Or wParam = SC_RESTORE) Then Call pvCheckGlueing End If '-- Special case: *control* call Case WM_COMMAND Call pvCheckGlueing End SelectEnd Sub
[解决办法]
还是用TabStrip1.Tabs(1).Selected = True这样的代码来实现比较好,模拟鼠标移上去点击一下会把人下一跳的 ^_^
[解决办法]
使用PostMessage试试.
- VB code
Private Function SendClick(hwnd As Long, mX As Long, mY As Long) '发送点击消息 Dim I As Long I = PostMessage(hwnd, WM_LBUTTONDOWN, 0, (mX And &HFFFF) + (mY And &HFFFF) * &H10000) I = PostMessage(hwnd, WM_LBUTTONUP, 0, (mX And &HFFFF) + (mY And &HFFFF) * &H10000) End Function
[解决办法]
在老马17楼的代码上修正一下,传入hWnd为控件句柄、坐标为相对坐标。
[解决办法]
这么多代码,值得推荐一下。