kk_lee69 发表于 2015-3-16 14:51:42

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

本帖最后由 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 = , $ChildBtn =

$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?mod=viewthread&tid=1585&extra=&highlight=%D7%EE%B5%D7%B2%E3&page=2
這篇 文章裡面的方法 不適用在 父子窗口

ceoguang 发表于 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 = , $ChildBtn =

$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),$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

kk_lee69 发表于 2015-3-17 15:04:25

回复 2# ceoguang
實際測試有點不一樣... 請看附圖

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 = , $ChildBtn =

$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),$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
抱歉没具体测试

ceoguang 发表于 2015-3-17 16:01:37

上面的代码可保证C永远在B的下层

131738 发表于 2015-3-17 17:31:27

本帖最后由 131738 于 2015-3-17 17:37 编辑

回复kk_lee69 抱歉没具体测试
ceoguang 发表于 2015-3-17 15:53 http://www.autoitx.com/images/common/back.gif

学了一手, 想到了 _WinAPI_SetWindowPos() 函数, 掰了半天没效果,
原来是要定义一个 WM_CHILDACTIVATE 子窗点击消息处理函数.
个人认为第 2 参数设置为 $HWND_BOTTOM 更容易理解吧..........

ceoguang 发表于 2015-3-17 19:03:32

回复 6# 131738
是的
_WinAPI_SetWindowPos($hWnd, 1,0,0,0,0, BitOR(0x1,0x10,0x2))

kk_lee69 发表于 2015-3-17 23:07:39

回复 7# ceoguang
    了解了~~ 感謝幫忙 !!

對於 _WinAPI_SetWindowPos 這個用法 也更清楚點了 感謝!!

zxhou1 发表于 2015-3-19 11:26:46

{:face (84):}

gwgelin 发表于 2015-4-13 14:41:45

很不错的问题刚好解决我的烦恼
页: [1]
查看完整版本: 如何使 父子窗口的A子窗口永远在其他子窗口的最底层?[已解决]