找回密码
 加入
搜索
查看: 9205|回复: 17

[系统综合] 【已解决】2个au3代码,能否用其中一个来修改另一个的代码?

 火.. [复制链接]
发表于 2013-4-16 23:06:41 | 显示全部楼层 |阅读模式
本帖最后由 fenhanxue 于 2013-4-18 14:07 编辑

就是有2个au3代码,想通过其中一个au3,来控制另一个au3的代码,应该怎么实现拉?
高人提供下思路或方案哈~谢谢谢谢拉

问题描述如下(感觉还是用图片才能说明问题):

也就是想通过程序1中的input的内容,来调整程序2中的这行代码:$Label1 = GUICtrlCreateLabel("", 40, 56, 140, 41)


程序1的代码如下:
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$Form1 = GUICreate("程序1", 226, 165)
$Button1 = GUICtrlCreateButton("Button1", 56, 80, 97, 49)
$Input1 = GUICtrlCreateInput("", 56, 32, 97, 21)
GUISetState(@SW_SHOW)
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                 Case $Button1
                        
                        ;;;;;;;;;;;;;这段代码该怎么写;;;;;;;;;;;;;;

EndSwitch
WEnd
程序2代码:
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
$Form1 = GUICreate("程序2", 226, 165, 192, 124)

;;;;;;;;;;;;;;;;;;;;下面这行代码随程序1的输入而改变
$Label1 = GUICtrlCreateLabel("测试", 40, 56, 140, 41)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

GUISetState(@SW_SHOW)
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
        EndSwitch
WEnd

本帖子中包含更多资源

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

×
发表于 2013-4-17 10:22:35 | 显示全部楼层
也許可以試著使用全局變量~
发表于 2013-4-17 10:59:47 | 显示全部楼层
本帖最后由 netegg 于 2013-4-17 11:01 编辑

可以,但是要传递数据,或者把第一个文件当成一个函数库,第二个文件include下
发表于 2013-4-17 11:35:18 | 显示全部楼层
用配置文件
发表于 2013-4-17 12:19:52 | 显示全部楼层
这样笼统的说,没有实际意义,直接 StringReplace() 你需要修改的地方就行了。

需要替换依据,比如要替换“2中的这行代码:$Label1 = GUICtrlCreateLabel("", 40, 56, 140, 41)”其中的函数名后面的引号内字符。
发表于 2013-4-17 14:22:13 | 显示全部楼层
用配置文件就很简单了
 楼主| 发表于 2013-4-17 19:42:31 | 显示全部楼层
回复 5# afan


    亲我想的也是这个 StringReplace()  

   但是我是2个au3文件,也就是可以用第一个au3  StringReplace()  第二个au3代码?
发表于 2013-4-17 20:04:56 | 显示全部楼层
回复 7# fenhanxue


    你就不会先 $str = FileRead('2.au3') 吗?亲
发表于 2013-4-17 23:30:34 | 显示全部楼层
本帖最后由 mbdnmt 于 2013-4-17 23:32 编辑

可以给加分吧?

1.au3
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$Form1 = GUICreate("程序1", 226, 165)
$Button1 = GUICtrlCreateButton("Button1", 56, 80, 97, 49)
$Input1 = GUICtrlCreateInput("", 56, 32, 97, 21)
GUISetState(@SW_SHOW)
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        $str = GUICtrlRead($Input1)
                        $iFhd = FileOpen("2.au3", 0)
                        ; 检查以只读打开的文件
                        If $iFhd = -1 Then
                                MsgBox(0, "错误", "无法打开文件.")
                                Exit
                        EndIf
                        ; 读取文本
                        $chars = FileRead($iFhd)
                        ;ConsoleWrite($chars)
                        FileClose($iFhd)
                        ; 替换
                        $strNew = StringRegExpReplace($chars, '\$Label1 = GUICtrlCreateLabel.*"\,', '\$Label1 \= GUICtrlCreateLabel\("' & $str & '"\,')
                        ;ConsoleWrite($strNew)
                        ; 重写2.au3
                        $iFhd = FileOpen("2.au3", 2)
                        FileWrite($iFhd, $strNew)
                        FileFlush($iFhd)
                        FileClose($iFhd)
        EndSwitch
WEnd
2.au3
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
$Form1 = GUICreate("程序2", 226, 165, 192, 124)

;;;;;;;;;;;;;;;;;;;;下面这行代码随程序1的输入而改变
$Label1 = GUICtrlCreateLabel("测试", 40, 56, 140, 41)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

GUISetState(@SW_SHOW)
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
        EndSwitch
WEnd

评分

参与人数 1金钱 +20 收起 理由
fenhanxue + 20 一定要加的哇

查看全部评分

发表于 2013-4-17 23:32:19 | 显示全部楼层
回复 10# mbdnmt

记得1.au3和2.au3放同一个路径下,楼主可以给加分了吧?
发表于 2013-4-17 23:38:33 | 显示全部楼层
用传递参数或INI应该能实现
发表于 2013-4-18 04:48:35 | 显示全部楼层
程序2代码不变,
程序1

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <winapi.au3>
#include <sendmessage.au3>

$Form1 = GUICreate("程序1", 226, 165)
$Button1 = GUICtrlCreateButton("Button1", 56, 80, 97, 49)
$Input1 = GUICtrlCreateInput("", 56, 32, 97, 21)
Local $hStatic = 0
Local $tBuffer = DllStructCreate('wchar[2048]')
GUISetState(@SW_SHOW)
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        If(_WinAPI_IsWindow($hStatic)=0) Then
                                $hStatic = _WinAPI_GetWindow(WinGetHandle('程序2'),5)
                        EndIf
                        DllStructSetData($tBuffer,1,GUICtrlRead($Input1))
                        _SendMessage($hStatic,$WM_SETTEXT,0,DllStructGetPtr($tBuffer),0,'wparam','ptr')
        EndSwitch
WEnd

评分

参与人数 1金钱 +20 收起 理由
fenhanxue + 20 好感激哇

查看全部评分

 楼主| 发表于 2013-4-18 14:06:24 | 显示全部楼层
回复 5# afan


    懂了。。。谢啦
发表于 2013-4-18 23:23:15 | 显示全部楼层
回复 14# fenhanxue

我提供的是运行前修改的方法,13楼提供的是程序2运行中的修改方法
 楼主| 发表于 2013-4-18 23:35:38 | 显示全部楼层
回复 15# mbdnmt


   恩恩哈~谢谢拉
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-6-1 12:02 , Processed in 0.088724 second(s), 29 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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