Jump to content

Help with child window.


Recommended Posts

I'm having a problem with my child window. Everytime the child window is made the program crashes. I don't mean a crash like a error box popped up and said "Error, line 82......", i mean crash like completely died and i had to kill the process. it only crashes when the child window appears. The function that calls the child window is at the bottom of the script. Everything else in the script works fine by the way, the child window is my only problem.

here's the whole script so you guys can test it.

Global Enum $idping = 1000, $iddel, $idurl, $idadd, $idedit
$gui = GUICreate("Ping rganizer", 450, 317)
;===========Make the listview===========
;======================================
$listview = _GUICtrlListView_Create($gui, "", 60, 55, 330, 200)
    _GUICtrlListView_SetExtendedListViewStyle($listview, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
_GUICtrlListView_InsertColumn($listview, 0, "Name", 110)
_GUICtrlListView_InsertColumn($listview, 1, "Realm URL", 160)
_GUICtrlListView_InsertColumn($listview, 2, "Status", 50)
$names = IniReadSectionNames( "realms.ini" )
For $names1 = 1 To $names[0]
    $ip = IniRead( "realms.ini", $names[$names1], "ip", "No DNS")
    $number = _GUICtrlListView_GetItemCount($listview)
;Make list items
    _GUICtrlListView_AddItem($listview, $names[$names1], 0)
    _GUICtrlListView_AddSubItem($listview, $number, $ip, 1)
;End list items
Next
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
;======================================
;============Listview End=============

;loop gui
While 1
    EzSkinOver()
    $msg = GUIGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        Exit
    EndSelect
WEnd        

;Right-click menu for listview
Func ListView_RClick()
    Local $ahit
    $ahit = _GUICtrlListView_SubItemHitTest($listview)
    If ($ahit[0] <> -1) Then
       ; Create a standard popup menu
       ; -------------------- To Do --------------------
        $menu = _GUICtrlMenu_CreatePopup()
        _GUICtrlMenu_AddMenuItem($menu, "Ping", $idping)
        _GUICtrlMenu_AddMenuItem($menu, "")
        _GUICtrlMenu_AddMenuItem($menu, "Add", $idadd)
        _GUICtrlMenu_AddMenuItem($menu, "Edit", $idedit)
        _GUICtrlMenu_AddMenuItem($menu, "Delete", $iddel)
        _GUICtrlMenu_AddMenuItem($menu, "")
        _GUICtrlMenu_AddMenuItem($menu, "Visit Server Website", $idurl)
       ; ========================================================================
       ; Shows how to capture the context menu selections
       ; ========================================================================
        Switch _GUICtrlMenu_TrackPopupMenu($menu, $listview, -1, -1, 1, 1, 2, 1)
            Case $idping
                $imagelist = _GUIImageList_Create( 18, 18)
                $SubItem = 1; The first SubItem
                $subitemip = _GUICtrlListView_GetItemText($listView,_GUICtrlListView_GetSelectedIndices($listview),$SubItem)
                TCPStartup()
                $nametoip = TCPNameToIP($subitemip)
                $ping = TCPConnect($nametoip, 80)
                if $ping = -1 Then
                    _GUICtrlListView_SetItemText($listview, $ahit[0], "Down", 2)
                    TCPShutdown()
                ElseIf @error = 1 Then
                    _GUICtrlListView_SetItemText($listview, $ahit[0], "Down", 2)
                    TCPShutdown()
                ElseIf @error = 2 Then
                    _GUICtrlListView_SetItemText($listview, $ahit[0], "Down", 2)
                    TCPShutdown()
                Else
                    _GUICtrlListView_SetItemText($listview, $ahit[0], "Up", 2)
                    TCPShutdown()
                EndIf
            Case $idadd
                addserver()
            Case $idedit
                editserver()
            Case $iddel
                $subitem2 = 0
                $selected = _GUICtrlListView_GetItemText($listview,_GUICtrlListView_GetSelectedIndices($listview), $subitem2)
                $delcheck = MsgBox( 4, "Are you Sure?", "Are you sure you want to delete " & $selected)
                If $delcheck = 6 Then
                IniDelete( "realms.ini", $selected)
                _GUICtrlListView_DeleteItemsSelected($listview)
                ElseIf $delcheck = 7 Then
                EndIf
            Case $idurl
                $url = IniRead( "realms.ini", _GUICtrlListView_GetItemText($listview, $ahit[0]), "url", "10")
                If $url = 10 Then
                    MsgBox(16, "Error", "Error! No Website given.")
                Else
                _IECreate($url)
                EndIf
        EndSwitch
        _GUICtrlMenu_DestroyMenu($menu)
    EndIf
EndFunc  ;==>ListView_RClick

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo
    $hWndListView = $listview
    If Not IsHWnd($listview) Then $hWndListView = GUICtrlGetHandle($listview)

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
   ;$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $NM_RCLICK; Sent by a list-view control when the user clicks an item with the left mouse button
                    ListView_RClick()
                    Return 0
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc  ;==>WM_NOTIFY


;Add Server Function========
Func addserver()
Local $msgadd
$addgui = GUICreate("Add Server", 134, 207, -1, -1, -1, BitOR($WS_EX_TOOLWINDOW,$WS_EX_MDICHILD), $gui)
GUISetBkColor(0x8B4513, $addgui)
GUICtrlCreateLabel("Server Name", 16, 8, 66, 17)
$servername = GUICtrlCreateInput("", 16, 32, 97, 21)
GUICtrlCreateLabel("Realm Url", 16, 64, 50, 17)
$realmurl = GUICtrlCreateInput("", 16, 88, 97, 21)
GUICtrlCreateLabel("Server Website", 16, 120, 77, 17)
$serverurl = GUICtrlCreateInput("http://", 16, 144, 97, 21)
$addserver = EzSkinButton("Add Server", 24, 176, 73, 25)
GUICtrlSetColor(-1, 0xffd700)
GUICtrlSetFont(-1, 8, 400, 0, "Times New Roman")
GUISetState(@SW_SHOW)
;#cs    If i elnimate the follow while loop it works fine
While 1
    $msgadd = GUIGetMsg()
    If $msgadd = $addserver Then
        IniWriteSection( "realms.ini", GUICtrlRead($servername), "ip=" & GUICtrlRead($realmurl))
        IniWrite("realms.ini", GUICtrlRead($servername), "url", GUICtrlRead($serverurl))
        GUIDelete($addgui)
    EndIf
    If $msgadd = $GUI_EVENT_CLOSE Then
        GUIDelete($addgui)
    EndIf
WEnd
;#ce   If you can give me a work around, then thank you very much
EndFunc
        
Func editserver()
$editgui = GUICreate("Edit Server", 134, 207, -1, -1, -1, $WS_EX_TOOLWINDOW)
GUISetBkColor(0x8B4513, $editgui)
GUICtrlCreateLabel("Server Name", 16, 8, 66, 17)
$editname = GUICtrlCreateInput("", 16, 32, 97, 21)
GUICtrlCreateLabel("Realm Url", 16, 64, 50, 17)
$editrealm = GUICtrlCreateInput("", 16, 88, 97, 21)
GUICtrlCreateLabel("Server Website", 16, 120, 77, 17)
$editurl = GUICtrlCreateInput("http://", 16, 144, 97, 21)
$editserver = EzSkinButton("Add Server", 24, 176, 73, 25)
GUICtrlSetColor(-1, 0xffd700)
GUICtrlSetFont(-1, 8, 400, 0, "Times New Roman")
GUISetState(@SW_SHOW)
EndFunc

All i need is to wait for the user to input stuff into the fields and press the button.

here's the realms.ini file so you can test the script:

[Name1]
ip=http://google.co.uk
url=http://google.com
[Name1]
ip=http://google.co.uk
url=http://google.co.uk

Thanks to anyone that helps. Been trying to overcome this problem the whole day, been searching the site like crazy so i figured it was time to ask for help. :)

"The quieter you are, the more you are able to hear..."

My AppsUSB Finder

Link to comment
Share on other sites

You haven't posted quite all the script so I can't run it, but my guess is that the problem is to do with your WM_NOTIFY function.

You should try to get out of that as soon as possible but when it calls ListView_RClick() it will be waiting for a long time.

Try doing this instead

change your loop like this

;loop gui
Global $doLVRClickthing = False;<--------add this
While 1
    EzSkinOver()
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
    EndSelect

    If $doLVRClickthing Then;<------add these lines
        ListView_RClick()
        $doLVRClickthing = False
    EndIf

WEnd

and change your WM_NOTIFY like this

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo
    $hWndListView = $listview
    If Not IsHWnd($listview) Then $hWndListView = GUICtrlGetHandle($listview)

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
;$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $NM_RCLICK; Sent by a list-view control when the user clicks an item with the left mouse button
                    $doLVRClickthing = True;ListView_RClick()<--------------changed here
                    Return 0
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc  ;==>WM_NOTIFY

As I say, I don't know if that is the problem, it's just my best guess.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

firstly, thank you very much, it now works. secondly that is my whole script minus the #includes (srry shoulda added those for ya) and like 2 func's that don't affect the overall script. either way, it works now and thank you very much. :)

"The quieter you are, the more you are able to hear..."

My AppsUSB Finder

Link to comment
Share on other sites

A different approach with EzSkin

#include <EzSkin.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiMenu.au3>
#include <GuiImageList.au3>
#include <IE.au3>


Global Enum $idping = 1000, $iddel, $idurl, $idadd, $idedit
$gui = EzSkinGUICreate("Ping Organizer", 450, 317)
$guiIcon = EzSkinIcon($gui, 2)
;===========Make the listview===========
;======================================
$listview = _GUICtrlListView_Create($gui, "", 60, 55, 330, 200)
_GUICtrlListView_SetExtendedListViewStyle($listview, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
_GUICtrlListView_InsertColumn($listview, 0, "Name", 110)
_GUICtrlListView_InsertColumn($listview, 1, "Realm URL", 160)
_GUICtrlListView_InsertColumn($listview, 2, "Status", 50)
$names = IniReadSectionNames("realms.ini")
For $names1 = 1 To $names[0]
    $ip = IniRead("realms.ini", $names[$names1], "ip", "No DNS")
    $number = _GUICtrlListView_GetItemCount($listview)
    ;Make list items
    _GUICtrlListView_AddItem($listview, $names[$names1], 0)
    _GUICtrlListView_AddSubItem($listview, $number, $ip, 1)
    ;End list items
Next
GUISetState(@SW_SHOW)

; Add GUI
$addgui = EzSkinGUICreate("Add Server", 234, 307);, -1, -1, -1, BitOR($WS_EX_TOOLWINDOW,$WS_EX_MDICHILD), $gui)
GUISetBkColor(0x8B4513, $addgui)
$addIcon = EzSkinIcon($addgui, 1)
GUICtrlCreateLabel("Server Name", 66, 58, 66, 17)
$servername = GUICtrlCreateInput("", 66, 82, 97, 21)
GUICtrlCreateLabel("Realm Url", 66, 114, 50, 17)
$realmurl = GUICtrlCreateInput("", 66, 138, 97, 21)
GUICtrlCreateLabel("Server Website", 66, 170, 77, 17)
$serverurl = GUICtrlCreateInput("http://", 66, 194, 97, 21)
$addserver = EzSkinButton("Add Server", 74, 226, 73, 25)

;$addserver = GUICtrlCreateButton("Add Server", 24, 176, 73, 25)
;GUICtrlSetColor(-1, 0xffd700)
;GUICtrlSetFont(-1, 8, 400, 0, "Times New Roman")
GUISetState(@SW_HIDE)

; Edit GUI
$editgui = EzSkinGUICreate("Edit Server", 234, 307);, -1, -1, -1, $WS_EX_TOOLWINDOW)
GUISetBkColor(0x8B4513, $editgui)
$editIcon = EzSkinIcon($editgui, 1)
GUICtrlCreateLabel("Server Name", 66, 58, 66, 17)
$editname = GUICtrlCreateInput("", 66, 82, 97, 21)
GUICtrlCreateLabel("Realm Url", 66, 114, 50, 17)
$editrealm = GUICtrlCreateInput("", 66, 138, 97, 21)
GUICtrlCreateLabel("Server Website", 66, 170, 77, 17)
$editurl = GUICtrlCreateInput("http://", 66, 194, 97, 21)
$editserver = EzSkinButton("Add Server", 74, 226, 73, 25)
GUICtrlSetColor($editserver + 1, 0xffd700)
GUICtrlSetFont($editserver + 1, 8, 400, 0, "Times New Roman")

;$editserver = GUICtrlCreateButton("Add Server", 24, 176, 73, 25)
;GUICtrlSetColor(-1, 0xffd700)
;GUICtrlSetFont(-1, 8, 400, 0, "Times New Roman")
GUISetState(@SW_HIDE)

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
;======================================
;============Listview End=============

;loop gui
While 1
    EzSkinOver()
    $msg = GUIGetMsg()
    Select
        Case $msg = $guiIcon[1]
            Exit
        Case $msg = $guiIcon[2]
            GUISetState(@SW_MINIMIZE, $gui)
        Case $msg = $addIcon[1] Or $msg = $editIcon[1]
            GUISetState(@SW_HIDE, $addgui)
            GUISetState(@SW_HIDE, $editgui)
            GUISetState(@SW_SHOW, $gui)
            
        Case $msg = $addserver
            IniWriteSection("realms.ini", GUICtrlRead($servername), "ip=" & GUICtrlRead($realmurl))
            IniWrite("realms.ini", GUICtrlRead($servername), "url", GUICtrlRead($serverurl))
            GUISetState(@SW_HIDE, $addgui)
            GUISetState(@SW_SHOW, $gui)
            
        Case $msg = $editserver
            ; do what you will
            GUISetState(@SW_HIDE, $editgui)
            GUISetState(@SW_SHOW, $gui)
    EndSelect
WEnd

;Right-click menu for listview
Func ListView_RClick()
    Local $ahit
    $ahit = _GUICtrlListView_SubItemHitTest($listview)
    If ($ahit[0] <> -1) Then
        ; Create a standard popup menu
        ; -------------------- To Do --------------------
        $menu = _GUICtrlMenu_CreatePopup()
        _GUICtrlMenu_AddMenuItem($menu, "Ping", $idping)
        _GUICtrlMenu_AddMenuItem($menu, "")
        _GUICtrlMenu_AddMenuItem($menu, "Add", $idadd)
        _GUICtrlMenu_AddMenuItem($menu, "Edit", $idedit)
        _GUICtrlMenu_AddMenuItem($menu, "Delete", $iddel)
        _GUICtrlMenu_AddMenuItem($menu, "")
        _GUICtrlMenu_AddMenuItem($menu, "Visit Server Website", $idurl)
        ; ========================================================================
        ; Shows how to capture the context menu selections
        ; ========================================================================
        Switch _GUICtrlMenu_TrackPopupMenu($menu, $listview, -1, -1, 1, 1, 2, 1)
            Case $idping
                $imagelist = _GUIImageList_Create(18, 18)
                $SubItem = 1; The first SubItem
                $subitemip = _GUICtrlListView_GetItemText($listview, _GUICtrlListView_GetSelectedIndices($listview), $SubItem)
                TCPStartup()
                $nametoip = TCPNameToIP($subitemip)
                $ping = TCPConnect($nametoip, 80)
                If $ping = -1 Then
                    _GUICtrlListView_SetItemText($listview, $ahit[0], "Down", 2)
                    TCPShutdown()
                ElseIf @error = 1 Then
                    _GUICtrlListView_SetItemText($listview, $ahit[0], "Down", 2)
                    TCPShutdown()
                ElseIf @error = 2 Then
                    _GUICtrlListView_SetItemText($listview, $ahit[0], "Down", 2)
                    TCPShutdown()
                Else
                    _GUICtrlListView_SetItemText($listview, $ahit[0], "Up", 2)
                    TCPShutdown()
                EndIf
            Case $idadd
                _GUICtrlMenu_DestroyMenu($menu)
                GUISetState(@SW_HIDE, $gui)
                GUISetState(@SW_SHOW, $addgui)
                
            Case $idedit
                _GUICtrlMenu_DestroyMenu($menu)
                GUISetState(@SW_HIDE, $gui)
                GUISetState(@SW_SHOW, $editgui)
            Case $iddel
                $subitem2 = 0
                $selected = _GUICtrlListView_GetItemText($listview, _GUICtrlListView_GetSelectedIndices($listview), $subitem2)
                $delcheck = MsgBox(4, "Are you Sure?", "Are you sure you want to delete " & $selected)
                If $delcheck = 6 Then
                    IniDelete("realms.ini", $selected)
                    _GUICtrlListView_DeleteItemsSelected($listview)
                ElseIf $delcheck = 7 Then
                EndIf
            Case $idurl
                $url = IniRead("realms.ini", _GUICtrlListView_GetItemText($listview, $ahit[0]), "url", "10")
                If $url = 10 Then
                    MsgBox(16, "Error", "Error! No Website given.")
                Else
                    _IECreate($url)
                EndIf
        EndSwitch
        _GUICtrlMenu_DestroyMenu($menu)
    EndIf
EndFunc   ;==>ListView_RClick

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo
    $hWndListView = $listview
    If Not IsHWnd($listview) Then $hWndListView = GUICtrlGetHandle($listview)

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    ;$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $NM_RCLICK; Sent by a list-view control when the user clicks an item with the left mouse button
                    ListView_RClick()
                    Return 0
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

8)

NEWHeader1.png

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...