api一日一练 第17天 (点评版)赠送 Delphi版+汇编版本
Delphi版本program Sdk17;
uses
Windows, Messages;
var
hForm: HWND;
stOldPoint: TPoint;
stRect1: TRect;
begin
hForm := FindWindow(nil, '小七论坛WWW.XQMSYK.COM');
if (hForm <> 0) then
begin
GetCursorPos(stOldPoint); //获取当前光标位置
GetWindowRect(hForm, stRect1);//获取当前窗口坐标
SetCursorPos(209 + stRect1.Left, 130 + stRect1.Top);//把鼠标移动到按钮的位置
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);//点下
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0); //抬起
SetCursorPos(stOldPoint.X, stOldPoint.Y); //恢复光标的位置
end else
begin
MessageBox(0, '没有发现窗口', 'xqmsyk.com', 0);
end;
end.
汇编版本
.686
.model flat, stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
.data
g_szCaption db 'xqmsyk.com', 0
g_szErrorText db '没有发现窗口哦', 0
g_szWindowText db '小七论坛WWW.XQMSYK.COM', 0
.code
WinMain proc
LOCAL @hForm: HWND
LOCAL @stOldPoint: POINT
LOCAL @stRect1: RECT
invoke FindWindow, NULL, offset g_szWindowText
.if eax
mov @hForm, eax
invoke GetCursorPos, addr @stOldPoint ; 获取当前光标位置
invoke GetWindowRect, @hForm, addr @stRect1 ; 获取当前窗口坐标
; 把鼠标移动到按钮的位置
mov eax, @stRect1.top
add eax, 130
mov ecx, @stRect1.left
add ecx, 209
invoke SetCursorPos, ecx, eax
invoke mouse_event, MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0 ; 点下
invoke mouse_event, MOUSEEVENTF_LEFTUP, 0, 0, 0, 0 ; 抬起
invoke SetCursorPos, @stOldPoint.x, @stOldPoint.y ; 恢复光标的位置
.else
invoke MessageBox, 0, offset g_szErrorText, offset g_szCaption, 0
.endif
ret
WinMain endp
start:
invoke WinMain
ret
end start
页:
[1]