首先,如上所说,你这种方法对有些游戏无效。其次,再看看你这段代码中本身的错误。
hwnd = FindWindow(vbNullString, "123") '这里面的"123"是指什么?他应当是窗口的名字,也就是任务栏里的名字。除非你的游戏叫123,不然就会msgbox"游戏未加载".
SendMessage Me.hwnd, WM_CHAR, vbKeyF1, ByVal 0& '这句话是往自己的窗体发消息!与你的向目标游戏窗口发消息不同。
你到底能不能找到游戏窗口?
用这个吧 多送个鼠标移动点击的
先打开任务管理器最小化 再按Command1
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) 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 Const MOUSEEVENTF_LEFTDOWN = &H2
Private Const MOUSEEVENTF_LEFTUP = &H4
Private Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Sub Command1_Click()
Dim a As Long
a = FindWindow(vbNullString, "Windows 任务管理器")
If a = 0 Then MsgBox "游戏未运行": Exit Sub
ShowWindow a, 0
ShowWindow a, 1
'Call SetCursorPos(512, 384) '移动
'mouse_event MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP, 0, 0, 0, 0 '点击
End Sub
w15828584183 说的对
而且最好用POSTMESSAGE
再不行就用钩子试试
有的游戏用direct可能不会处理窗口消息。