keroine 发表于 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”呢?

guland 发表于 2010-7-19 21:46:55

回复 1# keroine


    可以用事件模式

131738 发表于 2010-7-19 21:47:56

事先建好两个按钮,同时隐藏一个,If条件出现后,即显示这个隐藏的按钮

keroine 发表于 2010-7-19 21:55:28

事先建好两个按钮,同时隐藏一个,If条件出现后,即显示这个隐藏的按钮
131738 发表于 2010-7-19 21:47 http://www.autoitx.com/images/common/back.gif

   
    不好意思,应该是我没有说太清楚。我是要在一个另外的应用程序窗口上增加一个按钮之类的控件,就想知道怎么来响应这个控件。

keroine 发表于 2010-7-19 21:56:41

回复 2# guland


    多谢,我试试看能不能搞定

131738 发表于 2010-7-20 18:33:17

另外的应用程序窗口,除非是你创建的,否则第三方程序是不可能的。。。。。

pusofalse 发表于 2010-7-20 21:54:43

回复 6# 131738


    第三方程序上也有可能的~或许也不是有可能,而是肯定可以。- -|||

thesnow 发表于 2010-7-20 22:02:22

消息劫持...(hook)

131738 发表于 2010-7-20 23:56:10

回复 7# pusofalse

好像没见过这样的例子,超版可否写一个让我等见识见识,开开眼界。。。。

131738 发表于 2010-7-20 23:58:33

回复 8# thesnow

帅哥也来这里释疑解惑了。。。。

131738 发表于 2010-7-21 02:46:44

回复131738


    第三方程序上也有可能的~或许也不是有可能,而是肯定可以。- -|||
pusofalse 发表于 2010-7-20 21:54 http://www.autoitx.com/images/common/back.gif

难道是说的拆开后再重新打包。。。。那当然没问题。。。

pusofalse 发表于 2010-7-21 04:53:55

回复 11# 131738


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

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

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

While GUIGetMsg() <> -3
WEndb.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拦截进程创建,并阻止或允许其运行

lxz 发表于 2010-7-21 05:13:35

学习一下。

131738 发表于 2010-7-21 16:51:58

回复 12# pusofalse

谢谢!!!领教了。。。
源码收下,等找到 Thread.au3 库文件后,仔细研究。。。

keroine 发表于 2010-7-24 19:20:35

回复 12# pusofalse


   太感谢了,学习中。
页: [1]
查看完整版本: 已有的程序窗口上,新增一个控件,怎么来响应这个控件呢?