找回密码
 加入
搜索
查看: 6701|回复: 8

[GUI管理] 【已解决】B窗口中用事件模式监控A窗口中的label控件值变化并同步更新-不用轮询模式

  [复制链接]
发表于 2014-10-13 22:24:58 | 显示全部楼层 |阅读模式
本帖最后由 touch_xu 于 2014-10-15 17:37 编辑

我想做的事就是,在B窗口中用事件模式监控A窗口中的label控件值变化并同步更新.



A窗口代码如下, 就是用OK产生随机数:
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#region ### START Koda GUI section ### Form=
$Form1 = GUICreate("A", 179, 126, 192, 124)
$Label1 = GUICtrlCreateLabel(Random(30, 50, 1), 0, 24, 180, 16, $SS_CENTER)
$Button1 = GUICtrlCreateButton("OK", 32, 80, 115, 25)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        GUICtrlSetData($Label1, Random(30, 50, 1))

        EndSwitch
WEnd
B窗口代码,就是监控A窗口的随机数变化, 并同步更新, 不用轮询模式:
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#region ### START Koda GUI section ### Form=
$Form2 = GUICreate("B", 179, 126, 192, 124)
$Label2 = GUICtrlCreateLabel("0", 0, 24, 180, 16, $SS_CENTER)
GUICtrlSetOnEvent(-1, "_GuiEvent")
GUISetOnEvent($GUI_EVENT_CLOSE, "_GuiEvent")
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###

Opt('GUIResizeMode', 802)
Opt("GUIOnEventMode", 1)


$CtrlHandle = ControlGetHandle("A", "", "Static1")
GUICtrlSetOnEvent(-1, "_GuiEvent")

While 1
        Sleep(90)
WEnd

Func _GuiEvent()
        Switch @GUI_CtrlId
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $CtrlHandle
                        GUICtrlSetData($Label2, ControlGetText($CtrlHandle, "", "Static1"))
        EndSwitch
EndFunc   ;==>_GuiEvent
大家帮我看下能不能实现,错在什么地方,谢谢!

本帖子中包含更多资源

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

×
发表于 2014-10-14 13:55:34 | 显示全部楼层
多线程解决,实时监控
 楼主| 发表于 2014-10-14 20:49:01 | 显示全部楼层
多线程解决,实时监控
ap112 发表于 2014-10-14 13:55



    事件结构无法完成吗? 可不可以帮忙修改下,谢谢!
发表于 2014-10-14 21:45:36 | 显示全部楼层
回复 3# touch_xu

这个跟事件啥的有什么关系?定时检测数据,有更新时自己跟着更新就是了.
Local $o_data = ControlGetText('A', '', $CtrlHandle)
AdlibRegister('_f_data', 300)
Func _f_data()
        If $o_data <> ControlGetText($CtrlHandle, "", "Static1") Then
                $o_data = ControlGetText($CtrlHandle, "", "Static1")
                GUICtrlSetData($Label2, $o_data)
        EndIf
EndFunc
 楼主| 发表于 2014-10-14 21:51:01 | 显示全部楼层
回复  touch_xu

这个跟事件啥的有什么关系?定时检测数据,有更新时自己跟着更新就是了.
user3000 发表于 2014-10-14 21:45



    这就是轮询啊, 我知道这样可以实现, 这样效率不是不高吗, 所以才来寻求更好的方法了!
    仍然十分感谢!
发表于 2014-10-14 21:58:23 | 显示全部楼层
请问一下 是按了OK键才变数字吗? 如果是的话那么从OK控件下手不就简单了~
 楼主| 发表于 2014-10-14 22:20:47 | 显示全部楼层
请问一下 是按了OK键才变数字吗? 如果是的话那么从OK控件下手不就简单了~
austere 发表于 2014-10-14 21:58



    不是的,这是我模拟的,实际上我所监控的程序是自己后台变化的, 和OK键无关,谢谢!
发表于 2014-10-15 10:15:29 | 显示全部楼层
回复 3# touch_xu
$Form1 = GUICreate("多线程", 250, 150, 300, 300)
$Label1 = GUICtrlCreateLabel("", 8, 8, 146, 17)
$Button1 = GUICtrlCreateButton("换个数据", 168, 8, 79, 25, 0)
$Form2 = GUICreate("多线程", 250,150, 570,300)
$Label2 = GUICtrlCreateLabel("", 8, 8, 146, 17)
GUISetState(@SW_SHOW,$Form1)
GUISetState(@SW_SHOW,$Form2)
$Timer = DllCallbackRegister("Timer", "int", "hwnd;uint;uint;dword")
$TimerDLL = DllCall("user32.dll", "uint", "SetTimer", "hwnd", 0, "uint", 0, "int", 1000, "ptr", DllCallbackGetPtr($Timer))
While 1
        Switch GUIGetMsg()
                Case - 3
                        Exit
                Case $Button1
                        GUICtrlSetData($Label1,Random(1,100))
        EndSwitch
WEnd
Func Timer($hWnd, $uiMsg, $idEvent, $dwTime)
        If  $idEvent = $TimerDLL[0] Then GUICtrlSetData($Label2,GUICtrlRead($Label1))
EndFunc
 楼主| 发表于 2014-10-15 17:36:18 | 显示全部楼层
回复  touch_xu
ap112 发表于 2014-10-15 10:15



    十分感谢,也可以满足我的要求,按照您的代码我分成两个窗口,就OK了,谢谢!
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-4-29 21:36 , Processed in 0.076994 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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