Jump to content

system hang


PhilipG
 Share

Recommended Posts

I've encountered something I don't really understand my self.

i have a function to create a new gui

Func edit()
$winopen= GUICreate("Redigera text", 145, 173, -1, -1, BitOR ($WS_POPUP, $WS_BORDER), -1) 
 GUISetState(@sw_show, $winopen)
    $myedit = GUICtrlCreateEdit("Text", 5, 5, 135, 135)
$save = GUICtrlCreateButton("Spara", 5, 145)
$abort = GUICtrlCreateButton("Avbryt", 50, 145)
   
    
    While 1
 $msg2 = GUIGetMsg()
         
If $msg2 = $GUI_EVENT_CLOSE Or $msg2 = $abort Then 
            GUIdelete($winopen)
            ;GUISwitch ($main)
            $msg2 = 0
            ExitLoop
        EndIf
        
    wend
EndFunc

before I added the while 1 loop the gui where written as it should but now it stops right after it has created the gui window. the controls in the window are never written!

Link to comment
Share on other sites

yes this function is called from within an other function.

all the other functions look like this:

Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    Switch $iwParam
    Case $idOpen
    case $idRed
        edit()
    Case $idSet
            settings()
            
    EndSwitch
EndFunc   ;==>WM_COMMAND

Func WM_CONTEXTMENU($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hMenu

    $hMenu = _GUICtrlMenu_CreatePopup ()
    _GUICtrlMenu_InsertMenuItem ($hMenu, 0, "Ny...", $idOpen)
    _GUICtrlMenu_InsertMenuItem ($hMenu, 1, "Redigera Text", $idRed)
    _GUICtrlMenu_InsertMenuItem ($hMenu, 2, "", 0)
    _GUICtrlMenu_InsertMenuItem ($hMenu, 3, "Inställningar", $idSet)
    _GUICtrlMenu_TrackPopupMenu ($hMenu, $iwParam)
    _GUICtrlMenu_DestroyMenu ($hMenu)
    Return True
EndFunc

Func settings()

$font = _ChooseFont()
GUICtrlSetFont ($load , $font[3], $font[4], $font[1], $font[2])
$data = "0=" & $font[0] & @lf &"1=" & $font[1] & @lf &"2=" & $font[2] & @lf &"3=" & $font[3] & @lf &"4=" & $font[4] & @lf &"5=" & $font[5] & @lf &"6=" & $font[6] & @lf &"7=" & $font[7] & @lf
;IniWriteSection (@ScriptDir & "\notes\" & @year & @mon & @mday & @HOUR & @min & @sec & @msec & ".note", "FONT", $data, 0)
IniWriteSection ($notename, "FONT", $data, 0)
ConsoleWriteError(@error)
EndFunc

Func edit()
$winopen= GUICreate("Redigera text", 145, 173, -1, -1, BitOR ($WS_POPUP, $WS_BORDER), -1) 
 GUISetState(@sw_show, $winopen)
    $myedit = GUICtrlCreateEdit("Text", 5, 5, 135, 135)
$save = GUICtrlCreateButton("Spara", 5, 145)
$abort = GUICtrlCreateButton("Avbryt", 50, 145)
   
    
    While WinExists($winopen)
 $msg2 = GUIGetMsg()
         
If $msg2 = $GUI_EVENT_CLOSE Then 
            GUIdelete($winopen)
            ;GUISwitch ($main)
            $msg2 = 0
            ExitLoop
        EndIf
        
    wend
EndFunc

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
GUIRegisterMsg($WM_CONTEXTMENU, "WM_CONTEXTMENU")

EDIT: Spelling

Edited by PhilipG
Link to comment
Share on other sites

#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <Misc.au3>
#include <GuiMenu.au3>
$notename = @ScriptDir & "\notes\20100126172830166.note"
Global Enum $idOpen = 1000, $idSet, $idInfo, $idRed
$abort = "nope"
$winopen = "nope"
Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    Switch $iwParam
    Case $idOpen
    case $idRed
        edit()
    Case $idSet
            settings()
            
    EndSwitch
EndFunc   ;==>WM_COMMAND

Func WM_CONTEXTMENU($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hMenu

    $hMenu = _GUICtrlMenu_CreatePopup ()
    _GUICtrlMenu_InsertMenuItem ($hMenu, 0, "Ny...", $idOpen)
    _GUICtrlMenu_InsertMenuItem ($hMenu, 1, "Redigera Text", $idRed)
    _GUICtrlMenu_InsertMenuItem ($hMenu, 2, "", 0)
    _GUICtrlMenu_InsertMenuItem ($hMenu, 3, "Inställningar", $idSet)
    _GUICtrlMenu_TrackPopupMenu ($hMenu, $iwParam)
    _GUICtrlMenu_DestroyMenu ($hMenu)
    Return True
EndFunc

Func settings()

$font = _ChooseFont()
GUICtrlSetFont ($load , $font[3], $font[4], $font[1], $font[2])
$data = "0=" & $font[0] & @lf &"1=" & $font[1] & @lf &"2=" & $font[2] & @lf &"3=" & $font[3] & @lf &"4=" & $font[4] & @lf &"5=" & $font[5] & @lf &"6=" & $font[6] & @lf &"7=" & $font[7] & @lf
;IniWriteSection (@ScriptDir & "\notes\" & @year & @mon & @mday & @HOUR & @min & @sec & @msec & ".note", "FONT", $data, 0)
IniWriteSection ($notename, "FONT", $data, 0)
ConsoleWriteError(@error)
EndFunc

Func edit()
$winopen= GUICreate("Redigera text", 145, 173, -1, -1, BitOR ($WS_POPUP, $WS_BORDER), -1) 
 GUISetState(@sw_show, $winopen)
    $myedit = GUICtrlCreateEdit("Text", 5, 5, 135, 135)
$save = GUICtrlCreateButton("Spara", 5, 145)
$abort = GUICtrlCreateButton("Avbryt", 50, 145)
   
    
    While WinExists($winopen)
 $msg2 = GUIGetMsg()
         
If $msg2 = $GUI_EVENT_CLOSE Then 
            GUIdelete($winopen)
            ;GUISwitch ($main)
            $msg2 = 0
            ExitLoop
        EndIf
        
    wend
EndFunc

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
;GUIRegisterMsg($WM_CONTEXTMENU, "WM_CONTEXTMENU")

$width=150
$height=150
;$font = _ChooseFont()
$picPath = @ScriptDir &"\Graphic\postit.gif"
$gui = GUICreate("", $width, $height, -1, -1, $WS_POPUP, $WS_EX_TOOLWINDOW)
$ctrl = GUICtrlCreatePic($picPath, 0, 0, $width, $height)
GuiCtrlSetState(-1,$GUI_DISABLE)
$more = GUICTRLCreateIcon ( @ScriptDir &"\Graphic\more.ico", -1, 6, 3, 10, 10, $SS_NOTIFY)
$close = GUICTRLCreateIcon ( @ScriptDir &"\Graphic\close.ico", -1, 133, 5, 12, 12, $SS_NOTIFY)

$drag = GUICtrlCreateLabel("",20,0,110,20,-1, $GUI_WS_EX_PARENTDRAG)
GUICtrlSetBkColor($drag, $GUI_BKCOLOR_TRANSPARENT)
$load = GUICtrlCreateLabel("Detta är starten" & @CRLF & @CRLF & "Fortsättning följer", 10, 20, 130, 130)
GUICtrlSetBkColor($load, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetColor ( $load, 0x774000)
;GUICtrlSetFont ($load , $font[3], $font[4], $font[1], $font[2])
GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg(1)
    
    Switch $msg[2]
        Case GUICtrlGetHandle($close)
            exitloop
        
        Case GUICtrlGetHandle($more)
            WM_CONTEXTMENU($gui, 0, $gui, 0)

    EndSwitch

WEnd

    GUIDelete()

Link to comment
Share on other sites

running win xp 32bit service pack 3. The first window displays as it should. The whole gui background is a pic looking like a post it.

When you access the context menu and triggers edit() a new gui opens as it schould but the controls for that GUI doesn't load at all and the program halts.

Link to comment
Share on other sites

running win xp 32bit service pack 3. The first window displays as it should. The whole gui background is a pic looking like a post it.

When you access the context menu and triggers edit() a new gui opens as it schould but the controls for that GUI doesn't load at all and the program halts.

I don't get any of this behaviour sorry Posted Image
Link to comment
Share on other sites

so do I

The following version works, at least as you say you expect. I've simply reorganized he code somehow and added scope declarations (I'm a bit picky, I know) but what should make the difference is that I've added Sleep(50) in your tight loops.

#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <Misc.au3>
#include <GuiMenu.au3>
;~ AutoItSetOption("TrayIconDebug", 1)

Global Enum $idOpen = 1000, $idSet, $idInfo, $idRed

Global $notename = @ScriptDir & "\notes\20100126172830166.note"
Global $abort = "nope"
Global $winopen = "nope"


GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
;GUIRegisterMsg($WM_CONTEXTMENU, "WM_CONTEXTMENU")

Global $width = 150
Global $height = 150
;$font = _ChooseFont()
Global $picPath = @ScriptDir & "\Graphic\postit.gif"
Global $gui = GUICreate("", $width, $height, -1, -1, $WS_POPUP, $WS_EX_TOOLWINDOW)
Global $ctrl = GUICtrlCreatePic($picPath, 0, 0, $width, $height)
GUICtrlSetState(-1, $GUI_DISABLE)
Global $more = GUICtrlCreateIcon(@ScriptDir & "\Graphic\more.ico", -1, 6, 3, 10, 10, $SS_NOTIFY)
Global $close = GUICtrlCreateIcon(@ScriptDir & "\Graphic\close.ico", -1, 133, 5, 12, 12, $SS_NOTIFY)

Global $drag = GUICtrlCreateLabel("", 20, 0, 110, 20, -1, $GUI_WS_EX_PARENTDRAG)
GUICtrlSetBkColor($drag, $GUI_BKCOLOR_TRANSPARENT)
Global $load = GUICtrlCreateLabel("Detta är starten" & @CRLF & @CRLF & "Fortsättning följer", 10, 20, 130, 130)
GUICtrlSetBkColor($load, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetColor($load, 0x774000)
;GUICtrlSetFont ($load , $font[3], $font[4], $font[1], $font[2])
GUISetState(@SW_SHOW)

Global $msg

While 1
    $msg = GUIGetMsg(1)

    Switch $msg[2]
        Case GUICtrlGetHandle($close)
            ExitLoop

        Case GUICtrlGetHandle($more)
            WM_CONTEXTMENU($gui, 0, $gui, 0)

    EndSwitch
    Sleep(50)
WEnd

GUIDelete()


Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    Switch $iwParam
        Case $idOpen
        Case $idRed
            edit()
        Case $idSet
            settings()
    EndSwitch
EndFunc ;==>WM_COMMAND

Func WM_CONTEXTMENU($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hMenu = _GUICtrlMenu_CreatePopup()
    _GUICtrlMenu_InsertMenuItem($hMenu, 0, "Ny...", $idOpen)
    _GUICtrlMenu_InsertMenuItem($hMenu, 1, "Redigera Text", $idRed)
    _GUICtrlMenu_InsertMenuItem($hMenu, 2, "", 0)
    _GUICtrlMenu_InsertMenuItem($hMenu, 3, "Inställningar", $idSet)
    _GUICtrlMenu_TrackPopupMenu($hMenu, $iwParam)
    _GUICtrlMenu_DestroyMenu($hMenu)
    Return True
EndFunc ;==>WM_CONTEXTMENU

Func settings()
    Local $font = _ChooseFont()
    GUICtrlSetFont($load, $font[3], $font[4], $font[1], $font[2])
    Local $data = "0=" & $font[0] & @LF & "1=" & $font[1] & @LF & "2=" & $font[2] & @LF & "3=" & $font[3] & @LF & "4=" & $font[4] & @LF & "5=" & $font[5] & @LF & "6=" & $font[6] & @LF & "7=" & $font[7] & @LF
    ;IniWriteSection (@ScriptDir & "\notes\" & @year & @mon & @mday & @HOUR & @min & @sec & @msec & ".note", "FONT", $data, 0)
    IniWriteSection($notename, "FONT", $data, 0)
    ConsoleWriteError(@error)
EndFunc ;==>settings

Func edit()
    Local $winopen = GUICreate("Redigera text", 145, 173, -1, -1, BitOR($WS_POPUP, $WS_BORDER), -1)
    GUISetState(@SW_SHOW, $winopen)
    Local $myedit = GUICtrlCreateEdit("Text", 5, 5, 135, 135)
    Local $save = GUICtrlCreateButton("Spara", 5, 145)
    $abort = GUICtrlCreateButton("Avbryt", 50, 145)

    Local $msg2
    While WinExists($winopen)
        $msg2 = GUIGetMsg()

        If $msg2 = $GUI_EVENT_CLOSE Then
            GUIDelete($winopen)
            ;GUISwitch ($main)
            $msg2 = 0
            ExitLoop
        EndIf
        Sleep(50)
    WEnd
EndFunc ;==>edit

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

<br />thats strange. Any suggiestions at all what to do?<br />

<br /><br /><br />

Those loops were doing way more than they needed to, which prevented other things from happening (like message handling and control drawing).

There's no need to continually re-read the control handles, since they don't change.

I added small sleeps to help keep the CPU idle and moved the functions to the bottom of the script.

I also made the edit gui activate the main gui when it closes, since the main one doesn't appear on the taskbar, can't be alt-tabbed to, and is easily obscured by other windows.

Try this out and see how it goes.

#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <Misc.au3>
#include <GuiMenu.au3>

$notename = @ScriptDir & "\notes\20100126172830166.note"
Global Enum $idOpen = 1000, $idSet, $idInfo, $idRed
$abort = "nope"
$winopen = "nope"

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
;GUIRegisterMsg($WM_CONTEXTMENU, "WM_CONTEXTMENU")

$width = 150
$height = 150
;$font = _ChooseFont()
$picPath = @ScriptDir & "\Graphic\postit.gif"
$gui = GUICreate("", $width, $height, -1, -1, $WS_POPUP, $WS_EX_TOOLWINDOW)
$ctrl = GUICtrlCreatePic($picPath, 0, 0, $width, $height)
GUICtrlSetState(-1, $GUI_DISABLE)
$more = GUICtrlCreateIcon(@ScriptDir & "\Graphic\more.ico", -1, 6, 3, 10, 10, $SS_NOTIFY)
$close = GUICtrlCreateIcon(@ScriptDir & "\Graphic\close.ico", -1, 133, 5, 12, 12, $SS_NOTIFY)

$drag = GUICtrlCreateLabel("", 20, 0, 110, 20, -1, $GUI_WS_EX_PARENTDRAG)
GUICtrlSetBkColor($drag, $GUI_BKCOLOR_TRANSPARENT)
$load = GUICtrlCreateLabel("Detta är starten" & @CRLF & @CRLF & "Fortsättning följer", 10, 20, 130, 130)
GUICtrlSetBkColor($load, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetColor($load, 0x774000)
;GUICtrlSetFont ($load , $font[3], $font[4], $font[1], $font[2])
GUISetState(@SW_SHOW)

Local $hClose = ControlGetHandle($gui, "", $close)
Local $hMore = ControlGetHandle($gui, "", $more)

While True
    $msg = GUIGetMsg(1)

    Switch $msg[2]
        Case $hClose
            GUIDelete($gui)
            ExitLoop
        Case $hMore
            WM_CONTEXTMENU($gui, 0, $gui, 0)
    EndSwitch
    Sleep(10)
WEnd

Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    Switch $iwParam
        Case $idOpen
        Case $idRed
            edit()
        Case $idSet
            settings()
    EndSwitch
EndFunc ;==>WM_COMMAND

Func WM_CONTEXTMENU($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hMenu

    $hMenu = _GUICtrlMenu_CreatePopup()
    _GUICtrlMenu_InsertMenuItem($hMenu, 0, "Ny...", $idOpen)
    _GUICtrlMenu_InsertMenuItem($hMenu, 1, "Redigera Text", $idRed)
    _GUICtrlMenu_InsertMenuItem($hMenu, 2, "", 0)
    _GUICtrlMenu_InsertMenuItem($hMenu, 3, "Inställningar", $idSet)
    _GUICtrlMenu_TrackPopupMenu($hMenu, $iwParam)
    _GUICtrlMenu_DestroyMenu($hMenu)
    Return True
EndFunc ;==>WM_CONTEXTMENU

Func settings()

    $font = _ChooseFont()
    GUICtrlSetFont($load, $font[3], $font[4], $font[1], $font[2])
    $data = "0=" & $font[0] & @LF & "1=" & $font[1] & @LF & "2=" & $font[2] & @LF & "3=" & $font[3] & @LF & "4=" & $font[4] & @LF & "5=" & $font[5] & @LF & "6=" & $font[6] & @LF & "7=" & $font[7] & @LF
    ;IniWriteSection (@ScriptDir & "\notes\" & @year & @mon & @mday & @HOUR & @min & @sec & @msec & ".note", "FONT", $data, 0)
    IniWriteSection($notename, "FONT", $data, 0)
    ConsoleWriteError(@error)
EndFunc ;==>settings

Func edit()
    $winopen = GUICreate("Redigera text", 145, 173, -1, -1, BitOR($WS_POPUP, $WS_BORDER), -1)

    $myedit = GUICtrlCreateEdit("Text", 5, 5, 135, 135)
    $save = GUICtrlCreateButton("Spara", 5, 145)
    $abort = GUICtrlCreateButton("Avbryt", 50, 145)

    $hSave = ControlGetHandle($winopen, "", $save)
    $hAbort = ControlGetHandle($winopen, "", $abort)

    GUISetState(@SW_SHOW, $winopen)

    While True
        $msg2 = GUIGetMsg(1)
        If $msg2[1] = $winopen Then
            Select
                Case $msg2[2] = $hSave
                    MsgBox(0, "Test", "Save")
                Case $msg2[2] = $hAbort
                    ContinueCase
                Case $msg2[0] = $GUI_EVENT_CLOSE
                    GUIDelete($winopen)
                    WinActivate($gui)
                    ExitLoop
            EndSelect
        EndIf
        Sleep(10)
    WEnd
EndFunc ;==>edit

[font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font]

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