找回密码
 加入
搜索
查看: 3593|回复: 0

[GUI管理] 使用SetParent api设置子窗口的几点疑问

[复制链接]
发表于 2010-11-9 17:42:06 | 显示全部楼层 |阅读模式
最近在学习excel vba的学习,总感觉很多地方没有au3方便
但是,对单元格的内容引用还是使用vba方便,因此想将vba和au3相结合。
我想了个办法,就是将vba的窗体和au3的窗体用SetParent结合在一起
不过存在几个问题,实在是想不出解决的办法,所以发上来一起讨论一下
为了便于运行,我用两个au3代码来模拟我遇到的问题
代码1,模拟excel vba的窗体
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("模拟程序", 380, 281, 192, 124)
$Button1 = GUICtrlCreateButton("Button1", 16, 64, 75, 25)
$Button2 = GUICtrlCreateButton("Button2", 96, 64, 75, 25)
$Button3 = GUICtrlCreateButton("Button3", 176, 64, 75, 25)
$Button4 = GUICtrlCreateButton("Button4", 256, 64, 75, 25)
$Button5 = GUICtrlCreateButton("Button1", 11, 133, 75, 25)
$Button6 = GUICtrlCreateButton("Button2", 91, 133, 75, 25)
$Button7 = GUICtrlCreateButton("Button3", 171, 133, 75, 25)
$Button8 = GUICtrlCreateButton("Button4", 251, 133, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit

        EndSwitch
WEnd




代码2,模拟au3的窗体
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <WinAPI.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("au3程序", 380, 281, 192, 124)
$Button1 = GUICtrlCreateButton("Button1", 16, 64, 75, 25)
$Button2 = GUICtrlCreateButton("Button2", 96, 64, 75, 25)
$Button3 = GUICtrlCreateButton("Button3", 176, 64, 75, 25)
$Button4 = GUICtrlCreateButton("Button4", 256, 64, 75, 25)
$Button5 = GUICtrlCreateButton("Button1", 11, 133, 75, 25)
$Button6 = GUICtrlCreateButton("Button2", 91, 133, 75, 25)
$Button7 = GUICtrlCreateButton("Button3", 171, 133, 75, 25)
$Button8 = GUICtrlCreateButton("Button4", 251, 133, 75, 25)
GUISetState(@SW_SHOW)
$f=WinGetHandle("au3程序","")
$c=WinGetHandle("模拟程序","")
$new=_WinAPI_SetParent($c, $f)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit

        EndSwitch
WEnd


先运行代码1的程序,再运行代码2的程序

在这里为了便于有关问题的模拟,原本代码1的窗体是无边框无标题栏的,这里我们先设置都存在
运行后,可以发现“模拟程序”已经在“au3程序”中了
但是,很多地方都重叠,拖动后也不会重绘

在我遇到的问题中,vba窗体成为au3程序的子窗体后,最小化au3窗体后再恢复,vba的窗体就不见了,只有用鼠标点击原先的vba窗体后才会再次出现

还有一个问题就是,将“au3程序”这个窗体关闭后,模拟程序的托盘图标还是存在的

第三个问题就是,使用_WinAPI_SetParent后,$new就是新的句柄,这个句柄和$f还有$c这两个句柄有什么关系
$f还有$c这两个句柄还可以使用吗?如果可以使用,那么$new这个句柄有什么作用?
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-20 22:23 , Processed in 0.073248 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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