Sign in to follow this  
Followers 0
eri

Multi GUi..

2 posts in this topic

I want Call and Hide Another Gui From Menu..

Please Correct This Script..

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

#Region ### START Koda GUI section ### Form=
$XP = GUICreate("XP", 283, 297, 273, 203)
$Button1 = GUICtrlCreateButton("Instal", 16, 216, 89, 25, $WS_GROUP)
$Button2 = GUICtrlCreateButton("Apply", 128, 216, 97, 25, $WS_GROUP)
    $Button3 = GUICtrlCreateButton("Option", 200, 264, 73, 25, $WS_GROUP)
    $OptionsDummy = GUICtrlCreateDummy()
    $OptionsContext = GUICtrlCreateContextMenu($OptionsDummy)
    $MXp = GUICtrlCreateMenuItem("XP", $OptionsContext)
    $MVista = GUICtrlCreateMenuItem("Vista", $OptionsContext)
    GUICtrlCreateMenuItem("", $OptionsContext)
    $OptionsExit = GUICtrlCreateMenuItem("Exit", $OptionsContext)
GUISetState (@SW_HIDE, $XP)

$Vista = GUICreate("Vista", 283, 297, 273, 203)
$Button4 = GUICtrlCreateButton("Instal", 16, 216, 89, 25, $WS_GROUP)
$Button5 = GUICtrlCreateButton("select File", 128, 216, 97, 25, $WS_GROUP)
    $Button6 = GUICtrlCreateButton("Option", 200, 264, 73, 25, $WS_GROUP)
    $OptionsDummy = GUICtrlCreateDummy()
    $OptionsContext = GUICtrlCreateContextMenu($OptionsDummy)
    $MXpa = GUICtrlCreateMenuItem("XP", $OptionsContext)
    $MVistaa = GUICtrlCreateMenuItem("Vista", $OptionsContext)
    GUICtrlCreateMenuItem("", $OptionsContext)
    $OptionsExite = GUICtrlCreateMenuItem("Exit", $OptionsContext)
GUISetState (@SW_SHOW, $Vista)

#EndRegion ### END Koda GUI section ###

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE Or $msg = $OptionsExit Or $msg = $OptionsExite
            Exit
        Case $msg = $MXp
            GUISetState(@SW_HIDE, $Vista)
            GUISetState(@SW_SHOW, $XP)

        Case $msg = $MVista
            GUISetState(@SW_HIDE, $XP)
            GUISetState(@SW_SHOW, $Vista)

        Case $msg = $MXpa
            GUISetState(@SW_HIDE, $Vista)
            GUISetState(@SW_SHOW, $XP)

        Case $msg = $MVistaa
            GUISetState(@SW_HIDE, $XP)
            GUISetState(@SW_SHOW, $Vista)

    EndSelect

    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $Button3
            showMenu($XP , $nmsg, $OptionsContext)
        Case $Button6
            showMenu($Vista , $nmsg, $OptionsContext)
    EndSwitch
WEnd

Func ShowMenu($hWnd, $CtrlID, $nContextID)
    Local $arPos, $x, $y
    Local $hMenu = GUICtrlGetHandle($nContextID)

    $arPos = ControlGetPos($hWnd, "", $CtrlID)

    $x = $arPos[0]
    $y = $arPos[1] + $arPos[3]

    ClientToScreen($hWnd, $x, $y)
    TrackPopupMenu($hWnd, $hMenu, $x, $y)
EndFunc   ;==>ShowMenu


; Convert the client (GUI) coordinates to screen (desktop) coordinates
Func ClientToScreen($hWnd, ByRef $x, ByRef $y)
    Local $stPoint = DllStructCreate("int;int")

    DllStructSetData($stPoint, 1, $x)
    DllStructSetData($stPoint, 2, $y)

    DllCall("user32.dll", "int", "ClientToScreen", "hwnd", $hWnd, "ptr", DllStructGetPtr($stPoint))

    $x = DllStructGetData($stPoint, 1)
    $y = DllStructGetData($stPoint, 2)
    ; release Struct not really needed as it is a local
    $stPoint = 0
EndFunc   ;==>ClientToScreen


; Show at the given coordinates (x, y) the popup menu (hMenu) which belongs to a given GUI window (hWnd)
Func TrackPopupMenu($hWnd, $hMenu, $x, $y)
    DllCall("user32.dll", "int", "TrackPopupMenuEx", "hwnd", $hMenu, "int", 0, "int", $x, "int", $y, "hwnd", $hWnd, "ptr", 0)
EndFunc   ;==>TrackPopupMenu

Thank`s :(

Share this post


Link to post
Share on other sites



eri,

Create a function for the $Vista GUI to be displayed in and call it when needed. To catch events for the child window instead of the main $XP GUI, I do it like so:

Func _Vista()
    $Vista = GUICreate("Vista", 283, 297, 273, 203)
    $Button4 = GUICtrlCreateButton("Instal", 16, 216, 89, 25, $WS_GROUP)
    $Button5 = GUICtrlCreateButton("select File", 128, 216, 97, 25, $WS_GROUP)
    $Button6 = GUICtrlCreateButton("Option", 200, 264, 73, 25, $WS_GROUP)
    $OptionsDummy = GUICtrlCreateDummy()
    $OptionsContext = GUICtrlCreateContextMenu($OptionsDummy)
    $MXpa = GUICtrlCreateMenuItem("XP", $OptionsContext)
    $MVistaa = GUICtrlCreateMenuItem("Vista", $OptionsContext)
    GUICtrlCreateMenuItem("", $OptionsContext)
    $OptionsExite = GUICtrlCreateMenuItem("Exit", $OptionsContext)
    GUISetState (@SW_SHOW, $Vista)

    While WinExists($Vista)
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $Button3
                showMenu($XP , $nmsg, $OptionsContext)
            Case $Button6
                showMenu($Vista , $nmsg, $OptionsContext)
        EndSwitch
    WEnd
EndFunc

To show the $XP GUI when the $Vista on closes, call GUIDelete() instead of Exit (important).

It's not right, but it shows what I'm talking about, you probably just need to change the code for Vista to XP or whichever way you want it.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$XP = GUICreate("XP", 283, 297, 273, 203)
$Button1 = GUICtrlCreateButton("Instal", 16, 216, 89, 25, $WS_GROUP)
$Button2 = GUICtrlCreateButton("Apply", 128, 216, 97, 25, $WS_GROUP)
$Button3 = GUICtrlCreateButton("Option", 200, 264, 73, 25, $WS_GROUP)
$OptionsDummy = GUICtrlCreateDummy()
$OptionsContext = GUICtrlCreateContextMenu($OptionsDummy)
$MXp = GUICtrlCreateMenuItem("XP", $OptionsContext)
$MVista = GUICtrlCreateMenuItem("Vista", $OptionsContext)
GUICtrlCreateMenuItem("", $OptionsContext)
$OptionsExit = GUICtrlCreateMenuItem("Exit", $OptionsContext)
GUISetState (@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE, $OptionsExit, $OptionsExit
            Exit
        Case $MXp
            _Vista()
            GUISetState(@SW_SHOW, $XP)

        Case $MVista
            GUISetState(@SW_HIDE, $XP)
            _Vista()

    EndSwitch
WEnd

Func _Vista()
    $Vista = GUICreate("Vista", 283, 297, 273, 203)
    $Button4 = GUICtrlCreateButton("Instal", 16, 216, 89, 25, $WS_GROUP)
    $Button5 = GUICtrlCreateButton("select File", 128, 216, 97, 25, $WS_GROUP)
    $Button6 = GUICtrlCreateButton("Option", 200, 264, 73, 25, $WS_GROUP)
    $OptionsDummy = GUICtrlCreateDummy()
    $OptionsContext = GUICtrlCreateContextMenu($OptionsDummy)
    $MXpa = GUICtrlCreateMenuItem("XP", $OptionsContext)
    $MVistaa = GUICtrlCreateMenuItem("Vista", $OptionsContext)
    GUICtrlCreateMenuItem("", $OptionsContext)
    $OptionsExite = GUICtrlCreateMenuItem("Exit", $OptionsContext)
    GUISetState (@SW_SHOW, $Vista)

    While WinExists($Vista)
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                GUISetState(@SW_SHOW, $XP)
                GUIDelete($Vista)
            Case $Button3
                showMenu($XP , $nmsg, $OptionsContext)
            Case $Button6
                showMenu($Vista , $nmsg, $OptionsContext)
                    Case $MXpa
            _Vista()
            GUISetState(@SW_SHOW, $XP)

        Case $MVistaa
            GUISetState(@SW_HIDE, $XP)
            _Vista()
        EndSwitch
    WEnd
EndFunc

Func ShowMenu($hWnd, $CtrlID, $nContextID)
    Local $arPos, $x, $y
    Local $hMenu = GUICtrlGetHandle($nContextID)

    $arPos = ControlGetPos($hWnd, "", $CtrlID)

    $x = $arPos[0]
    $y = $arPos[1] + $arPos[3]

    ClientToScreen($hWnd, $x, $y)
    TrackPopupMenu($hWnd, $hMenu, $x, $y)
EndFunc   ;==>ShowMenu


; Convert the client (GUI) coordinates to screen (desktop) coordinates
Func ClientToScreen($hWnd, ByRef $x, ByRef $y)
    Local $stPoint = DllStructCreate("int;int")

    DllStructSetData($stPoint, 1, $x)
    DllStructSetData($stPoint, 2, $y)

    DllCall("user32.dll", "int", "ClientToScreen", "hwnd", $hWnd, "ptr", DllStructGetPtr($stPoint))

    $x = DllStructGetData($stPoint, 1)
    $y = DllStructGetData($stPoint, 2)
    ; release Struct not really needed as it is a local
    $stPoint = 0
EndFunc   ;==>ClientToScreen


; Show at the given coordinates (x, y) the popup menu (hMenu) which belongs to a given GUI window (hWnd)
Func TrackPopupMenu($hWnd, $hMenu, $x, $y)
    DllCall("user32.dll", "int", "TrackPopupMenuEx", "hwnd", $hMenu, "int", 0, "int", $x, "int", $y, "hwnd", $hWnd, "ptr", 0)
EndFunc   ;==>TrackPopupMenu

James

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0