小七技术论坛,计算机安全和杀毒软件,编程交流于软件安全技术交流,给新手一个绿色安全的论坛

标题: api一日一练 第17天 (点评版)赠送 Delphi版+汇编版本 [打印本页]

作者: 七液    时间: 2013-2-8 15:25
标题: api一日一练 第17天 (点评版)赠送 Delphi版+汇编版本
Delphi版本

  1. program Sdk17;

  2. uses
  3.   Windows, Messages;

  4. var
  5.   hForm: HWND;
  6.   stOldPoint: TPoint;
  7.   stRect1: TRect;
  8. begin
  9.   hForm := FindWindow(nil, '小七论坛[url]WWW.XQMSYK.COM[/url]');
  10.   if (hForm <> 0) then
  11.   begin
  12.     GetCursorPos(stOldPoint);       //  获取当前光标位置
  13.     GetWindowRect(hForm, stRect1);  //  获取当前窗口坐标

  14.     SetCursorPos(209 + stRect1.Left, 130 + stRect1.Top);  //  把鼠标移动到按钮的位置
  15.     mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);  //  点下
  16.     mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);    //  抬起

  17.     SetCursorPos(stOldPoint.X, stOldPoint.Y);       //  恢复光标的位置
  18.   end else
  19.   begin
  20.     MessageBox(0, '没有发现窗口', 'xqmsyk.com', 0);
  21.   end;
  22. end.
复制代码
汇编版本

  1. .686
  2. .model flat, stdcall
  3. option casemap:none

  4. include \masm32\include\windows.inc
  5. include \masm32\include\kernel32.inc
  6. include \masm32\include\user32.inc

  7. includelib \masm32\lib\kernel32.lib
  8. includelib \masm32\lib\user32.lib

  9. .data
  10.         g_szCaption                db        'xqmsyk.com', 0
  11.         g_szErrorText        db        '没有发现窗口哦', 0
  12.        
  13.         g_szWindowText        db        '小七论坛[url]WWW.XQMSYK.COM[/url]', 0

  14. .code

  15. WinMain proc
  16.         LOCAL        @hForm: HWND
  17.         LOCAL        @stOldPoint: POINT
  18.         LOCAL        @stRect1: RECT
  19.        
  20.         invoke        FindWindow, NULL, offset g_szWindowText
  21.         .if                eax
  22.                         mov                @hForm, eax
  23.                        
  24.                         invoke        GetCursorPos, addr @stOldPoint                        ;        获取当前光标位置
  25.                         invoke        GetWindowRect, @hForm, addr @stRect1        ;        获取当前窗口坐标
  26.                        
  27.                         ;        把鼠标移动到按钮的位置
  28.                         mov                eax, @stRect1.top
  29.                         add                eax, 130
  30.                         mov                ecx, @stRect1.left
  31.                         add                ecx, 209
  32.                         invoke        SetCursorPos, ecx, eax
  33.                        
  34.                         invoke        mouse_event, MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0        ;        点下
  35.                         invoke        mouse_event, MOUSEEVENTF_LEFTUP, 0, 0, 0, 0                ;        抬起
  36.                        
  37.                         invoke        SetCursorPos, @stOldPoint.x, @stOldPoint.y        ;        恢复光标的位置
  38.         .else
  39.                         invoke        MessageBox, 0, offset g_szErrorText, offset g_szCaption, 0
  40.         .endif
  41.         ret

  42. WinMain endp

  43. start:
  44.         invoke        WinMain
  45.         ret
  46. end start
复制代码





欢迎光临 小七技术论坛,计算机安全和杀毒软件,编程交流于软件安全技术交流,给新手一个绿色安全的论坛 (https://xqmsyk.com/) Powered by Discuz! X3.3