| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 5585 人关注过本帖
标题:关于PostMessage函数发鼠标消息的位置像素的设置问题!
只看楼主 加入收藏
不说也罢
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:贵宾
威 望:39
帖 子:1481
专家分:4989
注 册:2007-10-7
收藏
得分:0 
以下是引用shi781203在2016-6-4 00:13:12的发言:


你的要求,我已经做了,请问能再多给指点吗?


不及时结贴,的确令人不爽。请楼主以后及时结贴。
今天闲来无事,也来凑凑热闹

程序代码:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long

Private Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
End Type


Private Sub Command1_Click()
    '根据楼主需求,模拟点击计算器按键9
    Dim hwnd As Long
    Dim BtHeight As Long
    BtHeight = GetSystemMetrics(4)
    hwnd = FindWindow(vbNullString, "计算器")
    If hwnd = 0 Then
        MsgBox "计算器没有运行!"
        Exit Sub
    End If
    Dim p1 As RECT
    GetWindowRect hwnd, p1'用了这个API,计算器窗口怎么移动,都可以实现点击它
    SetCursorPos p1.Left + 110, p1.Top + BtHeight + 180 '鼠标移动到计算器9的按键上
    mouse_event &H2 Or &H4, 0, 0, 0, 0'模拟按下了9
End Sub


===================================================
讨厌C#的行尾的小尾巴;和一对大括号{ }
===================================================
2016-06-04 14:57
shi781203
Rank: 2
来 自:广东省
等 级:论坛游民
帖 子:112
专家分:50
注 册:2011-3-18
收藏
得分:0 
以下是引用不说也罢在2016-6-4 14:57:08的发言:



不及时结贴,的确令人不爽。请楼主以后及时结贴。
今天闲来无事,也来凑凑热闹


Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long

Private Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
End Type


Private Sub Command1_Click()
    '根据楼主需求,模拟点击计算器按键9
    Dim hwnd As Long
    Dim BtHeight As Long
    BtHeight = GetSystemMetrics(4)
    hwnd = FindWindow(vbNullString, "计算器")
    If hwnd = 0 Then
        MsgBox "计算器没有运行!"
        Exit Sub
    End If
    Dim p1 As RECT
    GetWindowRect hwnd, p1'用了这个API,计算器窗口怎么移动,都可以实现点击它
    SetCursorPos p1.Left + 110, p1.Top + BtHeight + 180 '鼠标移动到计算器9的按键上
    mouse_event &H2 Or &H4, 0, 0, 0, 0'模拟按下了9
End Sub

请问能不能用以下代码取替?
***************************************
Public Const WM_MOUSEMOVE = &H200
Type RECT
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
End Type

Type POINTAPI
    x As Long
    y As Long
End Type

Type WINDOWPLACEMENT
    Length As Long
    flags As Long
    showCmd As Long
    ptMinPosition As POINTAPI
    ptMaxPosition As POINTAPI
    rcNormalPosition As RECT
End Type
*********************************************(上述为GetWindowPlacement这个API函数要用到模块)
(以下代码实现模拟鼠标在指定窗体移动到中央,请问以下语句错误在哪里?)
……
GetWindowPlacement WinID, Wt
PostMessage WinID, WM_MOUSEMOVE, 0, Wt.rcNormalPosition.Right / 2 + Wt.rcNormalPosition.Bottom / 2
……

飞点燃费盐--历史上至有型的计算机病毒(能感染你是我的荣幸,也是你的光荣!)
2016-06-05 16:37
快速回复:关于PostMessage函数发鼠标消息的位置像素的设置问题!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.020030 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved