Jump to content

How to create a child windows


Valnurat
 Share

Recommended Posts

I have a mainform with a ListviewControl. The ListView contains data from my SQL Server. My idea is that when you find what you are looking for, in the listview, I pick it by pressing the enter button and then show the content on a child window with some control.

So my questions are:

How do you pick the content in the listview with either enter button or the mouse?

How do you create a child windows with control?

Global $idListview, $idOKay


_FormCreate()
_Main()


Func _FormCreate()
    ; Create GUI
    GUICreate("Computer Asset", 1027, 400)
    $idListview = GUICtrlCreateListView("", 2, 2, 1024, 268,Default, BitOR($LVS_SHOWSELALWAYS, $LVS_EX_GRIDLINES,$LVS_EX_FULLROWSELECT))

    ; Add columns
    _GUICtrlListView_AddColumn($idListview, "Computername", 100,2)
    _GUICtrlListView_AddColumn($idListview, "Tkt No.", 100,2)
    _GUICtrlListView_AddColumn($idListview, "Req No.", 100,2)
    _GUICtrlListView_AddColumn($idListview, "Order Date", 100,2)
    _GUICtrlListView_AddColumn($idListview, "Costcenter", 100,2)
    _GUICtrlListView_AddColumn($idListview, "Username", 100,2)
    _GUICtrlListView_AddColumn($idListview, "Model", 100,2)
    _GUICtrlListView_AddColumn($idListview, "Current Location", 100,2)
    _GUICtrlListView_AddColumn($idListview, "Option", 100,2)
    _GUICtrlListView_AddColumn($idListview, "Shipdate", 100,2)
    $idOKay = GUICtrlCreateButton("OK", 310, 290, 85, 25)

    GUISetState(@SW_SHOW)
EndFunc

Func _Main()
    Local $sConnectionString = 'DRIVER={' & $sDriver & '};SERVER=' & $sServer & ';DATABASE=' & $sDatabase & ';UID=' & $sUser & ';PWD=' & $sPassword & ';'
    Local $oConnection = _ADO_Connection_Create()
    _ADO_Connection_OpenConString($oConnection, $sConnectionString)
    If @error Then Return SetError(@error, @extended, $ADO_RET_FAILURE)
    Local $sTableName = 'StaffMemberUser.ComputerAsset'
    Local $sQUERY = "Select Computername, TktNo, ReqNo, OrderDate, CostCenter, Username, Model, CurrentLocation, Note, Shipdate from " & $sTableName
    Local $oRecordset = _ADO_Execute($oConnection, $sQUERY)
    Local $aRecordsetArray = _ADO_Recordset_ToArray($oRecordset, False)
    Local $aRecordset_inner = _ADO_RecordsetArray_GetContent($aRecordsetArray)
    _GUICtrlListView_SetItemCount($idListview, UBound($aRecordset_inner) - 1)
    _GUICtrlListView_AddArray($idListview, $aRecordset_inner)
    ; CleanUp
    $oRecordset = Null
    _ADO_Connection_Close($oConnection)
    $oConnection = Null
    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $idOKay
                MsgBox($MB_SYSTEMMODAL, "listview item", GUICtrlRead($idListview), 2)
            Case $idListview
                MsgBox($MB_SYSTEMMODAL, "listview", "clicked=" & GUICtrlGetState($idListview), 2)
        EndSwitch
    WEnd
    GUIDelete()
EndFunc

 

Yours sincerely

Kenneth.

Link to comment
Share on other sites

You code a second GuiCreate and set the parent paramenter to the handle of the parent GUI.
Check example 2 in the help file for GUICreate.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

The wiki has a tutorial how to manage multiple GUIs.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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

 $hGUI = GUICreate("Test", 500, 500)

 GUISetState()

 ; Create child GUIs to hold tabs
 $hTab_Win0 = GUICreate("", 400, 200, 50, 20, $WS_POPUP, $WS_EX_MDICHILD, $hGUI)
 $hTab_0 = GUICtrlCreateTab(10, 10, 380, 180)
     $hTab_00 = GUICtrlCreateTabitem("00")
         GUICtrlCreateButton("00", 160, 90, 80, 30)
     $hTab_01 = GUICtrlCreateTabitem("01")
         GUICtrlCreateButton("01", 160, 90, 80, 30)

 GUICtrlCreateTabitem ("")
 GUISetState()

 $hTab_Win1 = GUICreate("", 400, 200, 50, 250, $WS_POPUP, $WS_EX_MDICHILD, $hGUI)
 $hTab_1 = GUICtrlCreateTab(10, 10, 380, 180)
     $hTab_10 = GUICtrlCreateTabitem("10")
         GUICtrlCreateButton("10", 160, 90, 80, 30)
     $hTab_11 = GUICtrlCreateTabitem("11")
         GUICtrlCreateButton("11", 160, 90, 80, 30)
 GUICtrlCreateTabitem ("")
 GUISetState()

 While 1
     Switch GUIGetMsg()
         Case $GUI_EVENT_CLOSE
             Exit
     EndSwitch
 WEnd

here is a very basic example, learn and modify according  to your need.

to hide you can use something like that

 if  $whatever then
                   GUISetState(@SW_HIDE, $hTab_Win0)
                   GUISetState(@SW_HIDE, $hTab_Win1)
                   
               Else
                   GUISetState(@SW_SHOW, $hTab_Win0)
                   GUISetState(@SW_SHOW, $hTab_Win1)
                 
                EndIf
 

Edited by antonioj84
Link to comment
Share on other sites

I have now created a childform, but why is my mainform not disabled?

When my childform is active I can press the [x] on my mainform and then my application is closed.

 

Global $idListview, $idOKay, $hMainForm, $idNewEntry, $idEditEntry, $aMsg, $hNewEntry, $idNewOKay, $idNewCancel


_MainFormCreate()
_Main()


Func _MainFormCreate()
    ; Create GUI
    $hMainForm = GUICreate("Computer Asset", 1027, 400)
    $idListview = GUICtrlCreateListView("", 2, 2, 1024, 268,Default, BitOR($LVS_SHOWSELALWAYS, $LVS_EX_GRIDLINES,$LVS_EX_FULLROWSELECT))

    ; Add columns
    _GUICtrlListView_AddColumn($idListview, "Computername", 100,2)
    _GUICtrlListView_AddColumn($idListview, "Tkt No.", 100,2)
    _GUICtrlListView_AddColumn($idListview, "Req No.", 100,2)
    _GUICtrlListView_AddColumn($idListview, "Order Date", 100,2)
    _GUICtrlListView_AddColumn($idListview, "Costcenter", 100,2)
    _GUICtrlListView_AddColumn($idListview, "Username", 100,2)
    _GUICtrlListView_AddColumn($idListview, "Model", 100,2)
    _GUICtrlListView_AddColumn($idListview, "Current Location", 100,2)
    _GUICtrlListView_AddColumn($idListview, "Option", 100,2)
    _GUICtrlListView_AddColumn($idListview, "Shipdate", 100,2)
    $idNewEntry = GUICtrlCreateButton("New", 310, 290, 85, 25)
    $idEditEntry = GUICtrlCreateButton("New", 310, 290, 85, 25)
    GUISetState(@SW_SHOW, $hMainForm)
EndFunc

Func _Main()
    While 1
        $aMsg = GUIGetMsg(1)
        Switch $aMsg[1]
            Case $hMainForm
                Switch $aMsg[0]
                    Case $GUI_EVENT_CLOSE
                        ExitLoop
                    Case $idNewEntry
                        GUICtrlSetState($hMainForm, $GUI_DISABLE)
                        _NewFormCreate()
                    Case $idListview
                        MsgBox($MB_SYSTEMMODAL, "listview", "clicked=" & GUICtrlGetState($idListview), 2)
                EndSwitch
            Case $hNewEntry
                Switch $aMsg[0]
                    Case $GUI_EVENT_CLOSE
                        GUIDelete($hNewEntry)
                EndSwitch
        EndSwitch
    WEnd
    GUIDelete()
EndFunc

Func _NewFormCreate()
    $hNewEntry = GUICreate("Create New", 500, 500, 350, 350,-1,-1,$hMainForm)
    $idNewOKay = GUICtrlCreateButton("Ok", 110, 290, 85, 25)
    $idNewCancel = GUICtrlCreateButton("Cancel", 310, 290, 85, 25)
    GUISetState(@SW_SHOW, $hNewEntry)
EndFunc

 

Yours sincerely

Kenneth.

Link to comment
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
 Share

×
×
  • Create New...