Jump to content

Child window crashes


Dana
 Share

Recommended Posts

I must be missing something really obvious. I'm trying to create a window with a child window, but when I do, neither the main window nor the child get displayed. I've stripped out all the nonessential code from this example:

$version = "0.1"
Opt("TrayIconDebug", 1)
#include <GUIConstantsEx.au3>
#include <ListviewConstants.au3>
#include <GuiListView.au3>
#include <EditConstants.au3>
#include <File.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Include <WinAPI.au3>


$w = 1024
$h = 700
Opt("GUIOnEventMode", 1) ; Change to OnEvent mode
$mainwindow = GUICreate("Logbook v" & $version & "main window", $w, $h,-1,-1, $WS_OVERLAPPEDWINDOW)
$datawindow = GUICreate("Logbook v" & $version, $w-100, $h-100,-1,-1, $WS_CHILD,-1, $mainwindow)
GUICtrlCreateLabel("Test label", 30, 10)
$printbutton = GUICtrlCreateButton("Print", 30, $h - 40, 60)
$closebutton = GUICtrlCreateButton("Close", $w - 30 - 60, $h - 40, 60)

GUISetOnEvent($GUI_EVENT_CLOSE, "CloseClicked")
GUICtrlSetOnEvent($closebutton, "CloseClicked")
GUICtrlSetOnEvent($printbutton, "PrintClicked")
GUISetState(@SW_SHOW)

While 1
        ;do stuff here
    Sleep(250) ; keep the GUI from eating up all the CPU cycles
WEnd


Func CloseClicked()
    GUIDelete()
    ;FileClose($file)
    ;If ($dataline == 0) Then FileDelete($logfile) ; don't save empty file
    Exit
EndFunc   ;==>CloseClicked


Func PrintClicked()
    Exit
EndFunc   ;==>PrintClicked

    

Opt("GUIOnEventMode", 0) ; Disable OnEvent mode

If I comment out the line (18) where I'm trying to create the child window, there are no problems and the script loops on the sleep line until I close the window, as expected. With the line in, nothing at all gets displayed on the screen and the script loops on the sleep line. However, if I click on the autoit icon in the taskbar and attempt to exit the script, my computer locks up and I have to power it down; I can't even get to task manager at that point. If I don't try to exit it from the icon, task manager can kill it.

What am I missing?

-Dana

Edited by Dana
Link to comment
Share on other sites

Hi

Missing a GUISetState(@SW_SHOW) after creating the main window.

Also in on event with multi gui you might be better off using the handle variable for the events, can save any confusion on window/control the event belongs to..

eg:

GUISetState(@SW_SHOW, $mainwindow) and GUISetState(@SW_SHOW, $datawindow)

GUISetOnEvent($GUI_EVENT_CLOSE, "CloseClicked", $mainwindow)

etc..

Cheers

Edited by smashly
Link to comment
Share on other sites

  • Moderators

Dana,

You need to GUISetState the main window before trying to cretae the child: ;)

$version = "0.1"
Opt("TrayIconDebug", 1)
#include <GUIConstantsEx.au3>
#include <ListviewConstants.au3>
#include <GuiListView.au3>
#include <EditConstants.au3>
#include <File.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Include <WinAPI.au3>


$w = 1024
$h = 700
Opt("GUIOnEventMode", 1) ; Change to OnEvent mode

$mainwindow = GUICreate("Logbook v" & $version & "main window", $w, $h,-1,-1, $WS_OVERLAPPEDWINDOW)

GUICtrlCreateLabel("Test label", 30, 10)
$printbutton = GUICtrlCreateButton("Print", 30, $h - 40, 60)
$closebutton = GUICtrlCreateButton("Close", $w - 30 - 60, $h - 40, 60)

GUISetOnEvent($GUI_EVENT_CLOSE, "CloseClicked")
GUICtrlSetOnEvent($closebutton, "CloseClicked")
GUICtrlSetOnEvent($printbutton, "PrintClicked")
GUISetState(@SW_SHOW)

$datawindow = GUICreate("Logbook v" & $version, $w-100, $h-100,-1,-1, $WS_CHILD,-1, $mainwindow)
GUISetBkColor(0xFFFF00, $datawindow)
GUISetState(@SW_SHOW)

While 1
        ;do stuff here
    Sleep(250) ; keep the GUI from eating up all the CPU cycles
WEnd


Func CloseClicked()
    GUIDelete()
    ;FileClose($file)
    ;If ($dataline == 0) Then FileDelete($logfile) ; don't save empty file
    Exit
EndFunc   ;==>CloseClicked


Func PrintClicked()
    Exit
EndFunc   ;==>PrintClicked

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Thanks, M23, that did the trick. I thought I had tried that but apparently not, though I never tried changing the color to see what was happening, too.

The only part I don't understand now is why the position of the child window is unpredictable when I use the default -1 for the locations... I thought it should be centerned? Not a biggie, as I can get it to where I want by explicitly locating it.

-Dana

Link to comment
Share on other sites

  • Moderators

Dana,

Sorry, never thought of that!

As far as I know a child window needs to be located relative to the parent - otherwise why are you creating it?. I have never tried to locate at the -1, -1 position. I will have play (perhaps ;) ) and see what is going on.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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...