找回密码
 加入
搜索
查看: 5877|回复: 14

[GUI管理] 已有的程序窗口上,新增一个控件,怎么来响应这个控件呢?

  [复制链接]
发表于 2010-7-19 20:22:56 | 显示全部楼层 |阅读模式
如果已经有一个窗体了:



我现在想在已有的应用程序窗口上,新增一个控件,比如这样:
#Include <GuiButton.au3>

$win_title = "test"
$win_txt = "按钮"
$hwnd2 = WinGetHandle($win_title,$win_txt)
If WinExists($win_title,$win_txt) Then
        $btn = _GUICtrlButton_Create($hwnd2, "按钮2", 100, 100, 81, 27)
EndIf

GUISetState()
While 1
              $msg = GUIGetMsg()
               If $msg = $GUI_EVENT_CLOSE Then Exit
WEnd

现在怎么来响应“按钮2”呢?

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2010-7-19 21:46:55 | 显示全部楼层
回复 1# keroine


    可以用事件模式
发表于 2010-7-19 21:47:56 | 显示全部楼层
事先建好两个按钮,同时隐藏一个,If  条件出现后,即显示这个隐藏的按钮
 楼主| 发表于 2010-7-19 21:55:28 | 显示全部楼层
事先建好两个按钮,同时隐藏一个,If  条件出现后,即显示这个隐藏的按钮
131738 发表于 2010-7-19 21:47


   
    不好意思,应该是我没有说太清楚。我是要在一个另外的应用程序窗口上增加一个按钮之类的控件,就想知道怎么来响应这个控件。
 楼主| 发表于 2010-7-19 21:56:41 | 显示全部楼层
回复 2# guland


    多谢,我试试看能不能搞定
发表于 2010-7-20 18:33:17 | 显示全部楼层
另外的应用程序窗口,除非是你创建的,否则第三方程序是不可能的。。。。。
发表于 2010-7-20 21:54:43 | 显示全部楼层
回复 6# 131738


    第三方程序上也有可能的~或许也不是有可能,而是肯定可以。- -|||
发表于 2010-7-20 22:02:22 | 显示全部楼层
消息劫持...(hook)
发表于 2010-7-20 23:56:10 | 显示全部楼层
回复 7# pusofalse

好像没见过这样的例子,超版可否写一个让我等见识见识,开开眼界。。。。
发表于 2010-7-20 23:58:33 | 显示全部楼层
回复 8# thesnow

帅哥也来这里释疑解惑了。。。。
发表于 2010-7-21 02:46:44 | 显示全部楼层
回复  131738


    第三方程序上也有可能的~或许也不是有可能,而是肯定可以。- -|||
pusofalse 发表于 2010-7-20 21:54


难道是说的拆开后再重新打包。。。。那当然没问题。。。
发表于 2010-7-21 04:53:55 | 显示全部楼层
回复 11# 131738


    NO~有多种方法都可以实现在第三方程序上创建控件并截取其消息。
SetWindowLong就可以很好地完成此功能,_GUICtrlButton_Create($hWnd, ..., ...)($hWnd属于第三方进程)在远程界面上创建一个按钮之后,虽然按钮是显示在了$hWnd上面,但所属的进程仍旧是自己的程序。但这样做有一个缺点,自己的程序必须要常驻内存,因为 在循环截取消息的不是第三方$hWnd,而是自己的程序。
还有如thesnow兄所说的消息劫持。

以下这个不必常驻进程,将代码写入到第三方进程中后自己的程序退出就OK了,剩下的截取消息等工作将由目标进程自己完成。

测试代码:
a.au3
GUICreate("Receive msg cross process", 400, 300)
GUISetState()

While GUIGetMsg() <> -3
WEnd
b.au3
#include <Thread.au3>

$pCreateWindowExW = _RTGetProcAddress("User32.dll", "CreateWindowExW")
$pSendMessageW = _RTGetProcAddress("User32.dll", "SendMessageW")
$pGetStockObject = _RTGetProcAddress("Gdi32.dll", "GetStockObject")
$pGetModuleHandleW = _RTGetProcAddress("Kernel32.dll", "GetModuleHandleW")
$pMessageBoxW = _RTGetProcAddress("User32.dll", "MessageBoxW")
$pGetMessageW = _RTGetProcAddress("User32.dll", "GetMessageW")
$pDispatchMessageW = _RTGetProcAddress("User32.dll", "DispatchMessageW")

$hWnd = WinGetHandle("Receive msg cross process")
If (@error) Then Exit

$iPid = WinGetProcess($hWnd)
$hProcess = _RTOpenProcess($iPid)

$pCallAddr = _RTVirtualAllocEx($hProcess, 1028)
$bCode = "0x" & _
        "6A00" & _
        "B8" & _RTLongPtrToBytes($pGetModuleHandleW) & _
        "FFD0" & _
        "6A00" & _
        "50" & _
        "68" & _RTUlongToBytes(1024) & _
        "68" & _RTLongPtrToBytes($hWnd) & _
        "68" & _RTUlongToBytes(20) & _
        "68" & _RTUlongToBytes(150) & _
        "68" & _RTUlongToBytes(40) & _
        "68" & _RTUlongToBytes(40) & _
        "68" & _RTUlongToBytes(0x50014000) & _
        "68" & _RTLongPtrToBytes($pCallAddr + 181) & _
        "68" & _RTLongPtrToBytes($pCallAddr + 167) & _
        "6A00" & _
        "B8" & _RTLongPtrToBytes($pCreateWindowExW) & _
        "FFD0" & _
        "A3" & _RTLongPtrToBytes($pCallAddr + 1024) & _
        "6A11" & _
        "B8" & _RTLongPtrToBytes($pGetStockObject) & _
        "FFD0" & _
        "6A01" & _
        "50" & _
        "6A30" & _
        "FF35" & _RTLongPtrToBytes($pCallAddr + 1024) & _
        "B8" & _RTLongPtrToBytes($pSendMessageW) & _
        "FFD0" & _
        "6A00" & _
        "6A00" & _
        "FF35" & _RTLongPtrToBytes($pCallAddr + 1024) & _
        "68" & _RTLongPtrToBytes($pCallAddr + 512) & _
        "B8" & _RTLongPtrToBytes($pGetMessageW) & _
        "FFD0" & _
        "68" & _RTLongPtrToBytes($pCallAddr + 512) & _
        "B8" & _RTLongPtrToBytes($pDispatchMessageW) & _
        "FFD0" & _
        "813D" & _RTLongPtrToBytes($pCallAddr + 516) & _RTUlongToBytes(0x202) & _
        "75" & Hex(-46, 2) & _
        "6A30" & _
        "6A00" & _
        "68" & _RTLongPtrToBytes($pCallAddr + 191) & _
        "68" & _RTLongPtrToBytes($hWnd) & _
        "B8" & _RTLongPtrToBytes($pMessageBoxW) & _
        "FFD0" & _
        "EB" & Hex(-69, 2) & _
        _RTStringToBytesW("Button") & _
        _RTStringToBytesW("Test") & _
        _RTStringToBytesW("Bingo, catch you~!")

_RTWriteProcessMemory($hProcess, $pCallAddr, $bCode, BinaryLen($bCode), "binary")
_RTCloseHandle(_RTCreateRemoteThread($hProcess, $pCallAddr))
先运行a再运行b。需要用到的外部库文件:纯AU3拦截进程创建,并阻止或允许其运行

评分

参与人数 1贡献 +5 收起 理由
txm888 + 5

查看全部评分

发表于 2010-7-21 05:13:35 | 显示全部楼层
学习一下。
发表于 2010-7-21 16:51:58 | 显示全部楼层
回复 12# pusofalse

谢谢!!!领教了。。。
源码收下,等找到 Thread.au3 库文件后,仔细研究。。。
 楼主| 发表于 2010-7-24 19:20:35 | 显示全部楼层
回复 12# pusofalse


   太感谢了,学习中。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-6-2 04:13 , Processed in 0.085815 second(s), 26 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表