- 积分
- 94
- 最后登录
- 2016-10-26
- 阅读权限
- 20
- 积分
- 94
- 帖子
- 163
- 精华
- 4
TA的每日心情 | 衰 2016-10-26 03:39 |
|---|
签到天数: 90 天 连续签到: 1 天 [LV.6]常住居民II 菜鸟入门

- UID
- 5415
- 小七币
- 292
- 贡献
- 6
- 在线时间
- 95 小时
- 注册时间
- 2012-3-7
|
废话:
变量声明最好都在函数开头,不要在中间随便插入一句声明.
有的时候查找某个变量的时候非常麻烦,而且编译速度很慢.
(这个是可以证明的,Delphi编译快和语法严谨有很大关系)
而且有的时候类型或者内存申请的都是开头申请结尾释放,
如果在代码中间插入一句有的时候真的很难注意就内存泄露了.
Delphi版本
- program Sdk18;
- uses
- Windows, Messages;
- var
- hForm: HWND;
- stOldPoint: TPoint;
- stRect1: TRect;
- begin
- hForm := FindWindow(nil, '小七论坛[url]WWW.XQMSYK.COM[/url]');
- if (hForm <> 0) then
- begin
- ShowWindow(hForm, SW_SHOW); // 让它正常显示
- // 让窗口出现在所有窗口的前面,坐标是左上角
- SetWindowPos(hForm, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE);
- 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 '小七论坛[url]WWW.XQMSYK.COM[/url]', 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 ShowWindow, @hForm, SW_SHOW ; 让它正常显示
- ; 让窗口出现在所有窗口的前面,坐标是左上角
- invoke SetWindowPos, @hForm, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE
-
- 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
复制代码 |
|