找回密码
 加入
搜索
查看: 5816|回复: 9

[AU3基础] 如何使 父子窗口的A子窗口永远在其他子窗口的最底层?[已解决]

  [复制链接]
发表于 2015-3-16 14:51:42 | 显示全部楼层 |阅读模式
本帖最后由 kk_lee69 于 2015-3-17 23:08 编辑

如程序所 示 父窗口下 有 A B C 三个子窗口 如何使 A子窗口永远在
其他子窗口之下,即使被点击了 仍然在其他子窗口下



#include <GuiConstants.au3>
#include <WindowsConstants.au3>
#include <winapi.au3>


Opt("GUIOnEventMode", 1)

;Global Const $SC_CLOSE = 0xF060
Local $ChildForm[1] = [0], $ChildBtn[1] = [0]
 
$WinMain = GUICreate("Main", 1000,750,-1,-1,  $WS_MAXIMIZEBOX + $WS_MINIMIZEBOX + $WS_SIZEBOX)


GUISetOnEvent($GUI_EVENT_CLOSE,"GUI_COMMAND")

GUISetState(@SW_SHOW, $WinMain)




$WinMainSub=GUICreate("A視窗", 300,300, 200, 200, BitOR($WS_CHILD, $WS_CAPTION),-1, $WinMain)
_WinAPI_SetParent($WinMainSub, $WinMain)
GUISetState(@SW_SHOW, $WinMainSub)


$WinMainSub2=GUICreate("B視窗", 300,300,300, 300,BitOR($WS_CHILD, $WS_CAPTION),-1, $WinMain)
_WinAPI_SetParent($WinMainSub2,$WinMain)
GUISetState(@SW_SHOW, $WinMainSub2)

$WinMainSub3=GUICreate("C視窗", 300,300,400,  400,BitOR($WS_CHILD, $WS_CAPTION),-1, $WinMain)
_WinAPI_SetParent($WinMainSub2,$WinMain)
GUISetState(@SW_SHOW, $WinMainSub3)

GUISetOnEvent($GUI_EVENT_CLOSE,"GUI_COMMAND")


While 1
        Sleep(20)
WEnd
 
 


Func GUI_COMMAND()
    Switch @GUI_CtrlId
                
         Case $GUI_EVENT_CLOSE
            Switch @GUI_WINHANDLE
                Case $WinMain
                    Exit
                                        
                                        
                Case Else
                    GUIDelete(@GUI_WINHANDLE)
            EndSwitch


                
                        
    EndSwitch
EndFunc


有參考過
http://www.autoitx.com/forum.php ... D7%B2%E3&page=2
這篇 文章  裡面的方法 不適用在 父子窗口
发表于 2015-3-17 14:31:38 | 显示全部楼层
#include <GuiConstants.au3>
#include <WindowsConstants.au3>
#include <winapi.au3>

Opt("GUIOnEventMode", 1)

;Global Const $SC_CLOSE = 0xF060
Local $ChildForm[1] = [0], $ChildBtn[1] = [0]

$WinMain = GUICreate("Main", 1000, 750, -1, -1, $WS_MAXIMIZEBOX + $WS_MINIMIZEBOX + $WS_SIZEBOX)


GUISetOnEvent($GUI_EVENT_CLOSE, "GUI_COMMAND")

GUISetState(@SW_SHOW, $WinMain)




$WinMainSub = GUICreate("A視窗", 300, 300, 200, 200, BitOR($WS_CHILD, $WS_CAPTION), -1, $WinMain)
_WinAPI_SetParent($WinMainSub, $WinMain)
GUISetState(@SW_SHOW, $WinMainSub)


$WinMainSub2 = GUICreate("B視窗", 300, 300, 300, 300, BitOR($WS_CHILD, $WS_CAPTION), -1, $WinMain)
_WinAPI_SetParent($WinMainSub2, $WinMain)
GUISetState(@SW_SHOW, $WinMainSub2)

$WinMainSub3 = GUICreate("C視窗", 300, 300, 400, 400, BitOR($WS_CHILD, $WS_CAPTION), -1, $WinMain)
_WinAPI_SetParent($WinMainSub2, $WinMain)
$aStyle = GUIGetStyle($WinMainSub3)
GUISetStyle(-1,BitOR(0x08000000,$aStyle[1]),$WinMainSub3)
GUISetState(@SW_SHOW, $WinMainSub3)


;WS_EX_NOACTIVATE
GUISetOnEvent($GUI_EVENT_CLOSE, "GUI_COMMAND")


While 1
        Sleep(20)
WEnd




Func GUI_COMMAND()
        Switch @GUI_CtrlId

                Case $GUI_EVENT_CLOSE
                        Switch @GUI_WinHandle
                                Case $WinMain
                                        Exit


                                Case Else
                                        GUIDelete(@GUI_WinHandle)
                        EndSwitch




        EndSwitch
EndFunc   ;==>GUI_COMMAND
上面这个代码实现了C窗口永远在A,B窗口之后
https://msdn.microsoft.com/en-us/library/windows/desktop/ff700543(v=vs.85).aspx#WS_EX_NOACTIVATE
 楼主| 发表于 2015-3-17 15:04:25 | 显示全部楼层
回复 2# ceoguang
實際測試有點不一樣... 請看附圖

本帖子中包含更多资源

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

×
发表于 2015-3-17 15:53:21 | 显示全部楼层
本帖最后由 ceoguang 于 2015-3-17 15:58 编辑

回复 3# kk_lee69
#include <GuiConstants.au3>
#include <WindowsConstants.au3>
#include <winapi.au3>

Opt("GUIOnEventMode", 1)

;Global Const $SC_CLOSE = 0xF060
Local $ChildForm[1] = [0], $ChildBtn[1] = [0]

$WinMain = GUICreate("Main", 1000, 750, -1, -1, $WS_MAXIMIZEBOX + $WS_MINIMIZEBOX + $WS_SIZEBOX)


GUISetOnEvent($GUI_EVENT_CLOSE, "GUI_COMMAND")

GUISetState(@SW_SHOW, $WinMain)




$WinMainSub = GUICreate("A視窗", 300, 300, 200, 200, BitOR($WS_CHILD, $WS_CAPTION), -1, $WinMain)
_WinAPI_SetParent($WinMainSub, $WinMain)
GUISetState(@SW_SHOW, $WinMainSub)


$WinMainSub2 = GUICreate("B視窗", 300, 300, 300, 300, BitOR($WS_CHILD, $WS_CAPTION), -1, $WinMain)
_WinAPI_SetParent($WinMainSub2, $WinMain)
GUISetState(@SW_SHOW, $WinMainSub2)

$WinMainSub3 = GUICreate("C視窗", 300, 300, 400, 400, BitOR($WS_CHILD, $WS_CAPTION), -1, $WinMain)
_WinAPI_SetParent($WinMainSub2, $WinMain)
;$aStyle = GUIGetStyle($WinMainSub3)
;GUISetStyle(-1,BitOR(0x08000000,$aStyle[1]),$WinMainSub3)
GUIRegisterMsg(0x22, "WM_CHILDACTIVATE")
GUISetState(@SW_SHOW, $WinMainSub3)

GUISetOnEvent($GUI_EVENT_CLOSE, "GUI_COMMAND")


While 1
        Sleep(20)
WEnd


Func WM_CHILDACTIVATE($hWnd, $Msg, $wParam, $lParam)
        If $WinMainSub3 = $hWnd Then
                #cs
                #define SWP_NOMOVE 0x2
                #define SWP_NOACTIVATE 0x10
                #define SWP_NOSIZE 0x1
                #ce
                _WinAPI_SetWindowPos($hWnd, $WinMainSub2,0,0,0,0, BitOR(0x1,0x10,0x2))
                Return 1
        EndIf
        Return $GUI_RUNDEFMSG 
EndFunc

Func GUI_COMMAND()
        Switch @GUI_CtrlId

                Case $GUI_EVENT_CLOSE
                        Switch @GUI_WinHandle
                                Case $WinMain
                                        Exit


                                Case Else
                                        GUIDelete(@GUI_WinHandle)
                        EndSwitch




        EndSwitch
EndFunc   ;==>GUI_COMMAND
抱歉没具体测试
发表于 2015-3-17 16:01:37 | 显示全部楼层
上面的代码可保证C永远在B的下层
发表于 2015-3-17 17:31:27 | 显示全部楼层
本帖最后由 131738 于 2015-3-17 17:37 编辑
回复  kk_lee69 抱歉没具体测试
ceoguang 发表于 2015-3-17 15:53


学了一手, 想到了 _WinAPI_SetWindowPos() 函数, 掰了半天没效果,
原来是要定义一个 WM_CHILDACTIVATE 子窗点击消息处理函数.
个人认为第 2 参数设置为 $HWND_BOTTOM 更容易理解吧..........
发表于 2015-3-17 19:03:32 | 显示全部楼层
回复 6# 131738
是的
_WinAPI_SetWindowPos($hWnd, 1,0,0,0,0, BitOR(0x1,0x10,0x2))
 楼主| 发表于 2015-3-17 23:07:39 | 显示全部楼层
回复 7# ceoguang
    了解了~~ 感謝幫忙 !!

對於 _WinAPI_SetWindowPos 這個用法 也更清楚點了 感謝!!
发表于 2015-3-19 11:26:46 | 显示全部楼层
发表于 2015-4-13 14:41:45 | 显示全部楼层
很不错的问题刚好解决我的烦恼
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-12-27 17:46 , Processed in 0.074278 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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