Jump to content

Main window after progress bar closing problem


Recommended Posts

I am having a problem where after the progressbar completes the GUI1() window will open but when I click the X IN THE TOP LEFT OR CLICK CLOSE it does not close. Any incite or help would be greatly appreciated. Thanks.

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

Opt("MustDeclareVars", 1)
Opt("GUIOnEventMode", 1)
Global $h = 100, $w = $h

Global $hGUI = GUICreate("Loading", $w, $h, -1, -1, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST))
Global $bg_color = 0xFFFFFF
GUISetBkColor($bg_color)
_WinAPI_SetLayeredWindowAttributes($hGUI, $bg_color, 0xFF)
GUISetState()

Circle_Progress_Init($hGUI, $w, $h, $bg_color)

GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST")

Global $fx, $progress
Global $angle = 0
Global $size = 50
Global $current = 0
Do
    $progress = $current / $size
    $angle = $progress * 360
    Circle_Progress($angle, $progress * 100)
    $current += 1
    Sleep(50)
Until $angle > 359

Sleep(500)

Circle_Progress(360, "DONE", "%s")

_Exit()

Func GUI1()

    Local $msg

    GUICreate("HP WIZARD DUELS - DECK GENERATOR R1.V1", -1, -1, -1, -1, BitOR($WS_MAXIMIZEBOX, $WS_MINIMIZEBOX))

    GUISetState(@SW_SHOW)

    While 1

        $msg = GUIGetMsg()

        If $msg = $GUI_EVENT_CLOSE Then ExitLoop

    WEnd

    GUIDelete()

EndFunc

Func Circle_Progress_Init($hWnd, $Weight, $Height, $bg_color = 0xFFFFFF)
    _GDIPlus_Startup()
    Global $font = "Times New Roman"
    Global $fsize = Floor($h / 10)
    Global $pen_size = Floor($Height / 6)
    Global $hPen = _GDIPlus_PenCreate(0, $pen_size)
    Global $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hWnd)
    Global $hBitmap = _GDIPlus_BitmapCreateFromGraphics($Weight, $Height, $hGraphics)
    Global $hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsClear($hBackbuffer, "0xFF" & $bg_color)
    _GDIPlus_GraphicsSetSmoothingMode($hBackbuffer, 2)
EndFunc

Func Circle_Progress($angle, $text, $sFormat  = "%.2f", $fg_pencolor = 0xFF0000FF, $bg_pencolor = 0xFFD0FFD0, $clear_color = 0xFFFFFFFF)
    Local $ps2 = $pen_size / 2
    _GDIPlus_GraphicsClear($hBackbuffer, $clear_color)
    _GDIPlus_PenSetColor($hPen, $bg_pencolor)
    _GDIPlus_GraphicsDrawEllipse($hBackbuffer, $ps2, $ps2, $w - $pen_size, $h - $pen_size, $hPen)
    _GDIPlus_PenSetColor($hPen, $fg_pencolor)
    _GDIPlus_GraphicsDrawArc($hBackbuffer, $ps2, $ps2, $w - $pen_size, $h - $pen_size, -90, $angle, $hPen)
    $fx = StringLen(StringFormat($sFormat, $text)) * $fsize / 2.5
    _GDIPlus_GraphicsDrawString($hBackbuffer, StringFormat($sFormat, $text), $w / 2 - $fx, $h / 2 - $fsize * 0.75, $font, $fsize)
    _GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 0, 0, $w, $h)
EndFunc

Func Circle_Progress_Close()
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_GraphicsDispose($hBackbuffer)
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_Shutdown()
EndFunc

Func WM_NCHITTEST($hWnd, $iMsg, $iwParam, $ilParam)
    If ($hWnd = $hGui) And ($iMsg = $WM_NCHITTEST) Then Return $HTCAPTION
EndFunc ;==>WM_NCHITTEST

Func _Exit()
    Circle_Progress_Close()
    GUIDelete($hGUI)

    GUI1()

    Exit

EndFunc
Link to comment
Share on other sites

You're mixing Opt("GUIOnEventMode", 1) with GUIGetMsg(), which does not work and your _exit() function calls a function that creates a GUI and never returns, meaning it will never reach Exit.

This should be more like it:

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

Opt("MustDeclareVars", 1)
Opt("GUIOnEventMode", 1)

Global $h = 100
Global $w = $h, $pen_size, $font, $fsize, $hPen, $hGraphics, $hBitmap, $hBackbuffer, $hGUI

_CircleDisplay()
_GUI1()

While 1
    Sleep(100)
WEnd

Func _GUI1()
    GUICreate("HP WIZARD DUELS - DECK GENERATOR R1.V1", -1, -1, -1, -1, BitOR($WS_MAXIMIZEBOX, $WS_MINIMIZEBOX))
    GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
    GUISetState(@SW_SHOW)
EndFunc ;==>_GUI1

Func _CircleDisplay()
    $hGUI = GUICreate("Loading", $w, $h, -1, -1, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST))
    GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST")
    Local $bg_color = 0xFFFFFF
    Local $fx, $progress
    Local $angle = 0
    Local $size = 50
    Local $current = 0
    GUISetBkColor($bg_color)
    _WinAPI_SetLayeredWindowAttributes($hGUI, $bg_color, 0xFF)
    GUISetState()
    Circle_Progress_Init($hGUI, $w, $h, $bg_color)
    Do
        $progress = $current / $size
        $angle = $progress * 360
        Circle_Progress($angle, $progress * 100)
        $current += 1
        Sleep(50)
    Until $angle > 359
    Sleep(500)
    Circle_Progress(360, "DONE", "%s")
    Circle_Progress_Close()
    GUIDelete()
EndFunc

Func Circle_Progress_Init($hWnd, $Weight, $Height, $bg_color = 0xFFFFFF)
    _GDIPlus_Startup()
    $font = "Times New Roman"
    $fsize = Floor($h / 10)
    $pen_size = Floor($Height / 6)
    $hPen = _GDIPlus_PenCreate(0, $pen_size)
    $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hWnd)
    $hBitmap = _GDIPlus_BitmapCreateFromGraphics($Weight, $Height, $hGraphics)
    $hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsClear($hBackbuffer, "0xFF" & $bg_color)
    _GDIPlus_GraphicsSetSmoothingMode($hBackbuffer, 2)
EndFunc

Func Circle_Progress($angle, $text, $sFormat = "%.2f", $fg_pencolor = 0xFF0000FF, $bg_pencolor = 0xFFD0FFD0, $clear_color = 0xFFFFFFFF)
    Local $ps2 = $pen_size / 2
    _GDIPlus_GraphicsClear($hBackbuffer, $clear_color)
    _GDIPlus_PenSetColor($hPen, $bg_pencolor)
    _GDIPlus_GraphicsDrawEllipse($hBackbuffer, $ps2, $ps2, $w - $pen_size, $h - $pen_size, $hPen)
    _GDIPlus_PenSetColor($hPen, $fg_pencolor)
    _GDIPlus_GraphicsDrawArc($hBackbuffer, $ps2, $ps2, $w - $pen_size, $h - $pen_size, -90, $angle, $hPen)
    Local $fx = StringLen(StringFormat($sFormat, $text)) * $fsize / 2.5
    _GDIPlus_GraphicsDrawString($hBackbuffer, StringFormat($sFormat, $text), $w / 2 - $fx, $h / 2 - $fsize * 0.75, $font, $fsize)
    _GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 0, 0, $w, $h)
EndFunc

Func Circle_Progress_Close()
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_GraphicsDispose($hBackbuffer)
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_Shutdown()
EndFunc

Func WM_NCHITTEST($hWnd, $iMsg, $iwParam, $ilParam)
    If ($hWnd = $hGUI) And ($iMsg = $WM_NCHITTEST) Then Return $HTCAPTION
EndFunc

Func _Exit()
    Exit
EndFunc
Edited by Tvern
Link to comment
Share on other sites

You're mixing Opt("GUIOnEventMode", 1) with GUIGetMsg(), which does not work and your _exit() function calls a function that creates a GUI and never returns, meaning it will never reach Exit.

This should be more like it:

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

Opt("MustDeclareVars", 1)
Opt("GUIOnEventMode", 1)

Global $h = 100
Global $w = $h, $pen_size, $font, $fsize, $hPen, $hGraphics, $hBitmap, $hBackbuffer, $hGUI

_CircleDisplay()
_GUI1()

While 1
    Sleep(100)
WEnd

Func _GUI1()
    GUICreate("HP WIZARD DUELS - DECK GENERATOR R1.V1", -1, -1, -1, -1, BitOR($WS_MAXIMIZEBOX, $WS_MINIMIZEBOX))
    GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
    GUISetState(@SW_SHOW)
EndFunc ;==>_GUI1

Func _CircleDisplay()
    $hGUI = GUICreate("Loading", $w, $h, -1, -1, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST))
    GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST")
    Local $bg_color = 0xFFFFFF
    Local $fx, $progress
    Local $angle = 0
    Local $size = 50
    Local $current = 0
    GUISetBkColor($bg_color)
    _WinAPI_SetLayeredWindowAttributes($hGUI, $bg_color, 0xFF)
    GUISetState()
    Circle_Progress_Init($hGUI, $w, $h, $bg_color)
    Do
        $progress = $current / $size
        $angle = $progress * 360
        Circle_Progress($angle, $progress * 100)
        $current += 1
        Sleep(50)
    Until $angle > 359
    Sleep(500)
    Circle_Progress(360, "DONE", "%s")
    Circle_Progress_Close()
    GUIDelete()
EndFunc

Func Circle_Progress_Init($hWnd, $Weight, $Height, $bg_color = 0xFFFFFF)
    _GDIPlus_Startup()
    $font = "Times New Roman"
    $fsize = Floor($h / 10)
    $pen_size = Floor($Height / 6)
    $hPen = _GDIPlus_PenCreate(0, $pen_size)
    $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hWnd)
    $hBitmap = _GDIPlus_BitmapCreateFromGraphics($Weight, $Height, $hGraphics)
    $hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsClear($hBackbuffer, "0xFF" & $bg_color)
    _GDIPlus_GraphicsSetSmoothingMode($hBackbuffer, 2)
EndFunc

Func Circle_Progress($angle, $text, $sFormat = "%.2f", $fg_pencolor = 0xFF0000FF, $bg_pencolor = 0xFFD0FFD0, $clear_color = 0xFFFFFFFF)
    Local $ps2 = $pen_size / 2
    _GDIPlus_GraphicsClear($hBackbuffer, $clear_color)
    _GDIPlus_PenSetColor($hPen, $bg_pencolor)
    _GDIPlus_GraphicsDrawEllipse($hBackbuffer, $ps2, $ps2, $w - $pen_size, $h - $pen_size, $hPen)
    _GDIPlus_PenSetColor($hPen, $fg_pencolor)
    _GDIPlus_GraphicsDrawArc($hBackbuffer, $ps2, $ps2, $w - $pen_size, $h - $pen_size, -90, $angle, $hPen)
    Local $fx = StringLen(StringFormat($sFormat, $text)) * $fsize / 2.5
    _GDIPlus_GraphicsDrawString($hBackbuffer, StringFormat($sFormat, $text), $w / 2 - $fx, $h / 2 - $fsize * 0.75, $font, $fsize)
    _GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 0, 0, $w, $h)
EndFunc

Func Circle_Progress_Close()
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_GraphicsDispose($hBackbuffer)
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_Shutdown()
EndFunc

Func WM_NCHITTEST($hWnd, $iMsg, $iwParam, $ilParam)
    If ($hWnd = $hGUI) And ($iMsg = $WM_NCHITTEST) Then Return $HTCAPTION
EndFunc

Func _Exit()
    Exit
EndFunc

Tvern thanks a million. Worked perfectly. You are genius. I really appreciate the help. And thank you for pointing out where the mistake was. I see the mix up now.

Regards,

Catalyst

Link to comment
Share on other sites

You're mixing Opt("GUIOnEventMode", 1) with GUIGetMsg(), which does not work and your _exit() function calls a function that creates a GUI and never returns, meaning it will never reach Exit.

This should be more like it:

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

Opt("MustDeclareVars", 1)
Opt("GUIOnEventMode", 1)

Global $h = 100
Global $w = $h, $pen_size, $font, $fsize, $hPen, $hGraphics, $hBitmap, $hBackbuffer, $hGUI

_CircleDisplay()
_GUI1()

While 1
    Sleep(100)
WEnd

Func _GUI1()
    GUICreate("HP WIZARD DUELS - DECK GENERATOR R1.V1", -1, -1, -1, -1, BitOR($WS_MAXIMIZEBOX, $WS_MINIMIZEBOX))
    GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
    GUISetState(@SW_SHOW)
EndFunc ;==>_GUI1

Func _CircleDisplay()
    $hGUI = GUICreate("Loading", $w, $h, -1, -1, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST))
    GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST")
    Local $bg_color = 0xFFFFFF
    Local $fx, $progress
    Local $angle = 0
    Local $size = 50
    Local $current = 0
    GUISetBkColor($bg_color)
    _WinAPI_SetLayeredWindowAttributes($hGUI, $bg_color, 0xFF)
    GUISetState()
    Circle_Progress_Init($hGUI, $w, $h, $bg_color)
    Do
        $progress = $current / $size
        $angle = $progress * 360
        Circle_Progress($angle, $progress * 100)
        $current += 1
        Sleep(50)
    Until $angle > 359
    Sleep(500)
    Circle_Progress(360, "DONE", "%s")
    Circle_Progress_Close()
    GUIDelete()
EndFunc

Func Circle_Progress_Init($hWnd, $Weight, $Height, $bg_color = 0xFFFFFF)
    _GDIPlus_Startup()
    $font = "Times New Roman"
    $fsize = Floor($h / 10)
    $pen_size = Floor($Height / 6)
    $hPen = _GDIPlus_PenCreate(0, $pen_size)
    $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hWnd)
    $hBitmap = _GDIPlus_BitmapCreateFromGraphics($Weight, $Height, $hGraphics)
    $hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsClear($hBackbuffer, "0xFF" & $bg_color)
    _GDIPlus_GraphicsSetSmoothingMode($hBackbuffer, 2)
EndFunc

Func Circle_Progress($angle, $text, $sFormat = "%.2f", $fg_pencolor = 0xFF0000FF, $bg_pencolor = 0xFFD0FFD0, $clear_color = 0xFFFFFFFF)
    Local $ps2 = $pen_size / 2
    _GDIPlus_GraphicsClear($hBackbuffer, $clear_color)
    _GDIPlus_PenSetColor($hPen, $bg_pencolor)
    _GDIPlus_GraphicsDrawEllipse($hBackbuffer, $ps2, $ps2, $w - $pen_size, $h - $pen_size, $hPen)
    _GDIPlus_PenSetColor($hPen, $fg_pencolor)
    _GDIPlus_GraphicsDrawArc($hBackbuffer, $ps2, $ps2, $w - $pen_size, $h - $pen_size, -90, $angle, $hPen)
    Local $fx = StringLen(StringFormat($sFormat, $text)) * $fsize / 2.5
    _GDIPlus_GraphicsDrawString($hBackbuffer, StringFormat($sFormat, $text), $w / 2 - $fx, $h / 2 - $fsize * 0.75, $font, $fsize)
    _GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 0, 0, $w, $h)
EndFunc

Func Circle_Progress_Close()
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_GraphicsDispose($hBackbuffer)
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_Shutdown()
EndFunc

Func WM_NCHITTEST($hWnd, $iMsg, $iwParam, $ilParam)
    If ($hWnd = $hGUI) And ($iMsg = $WM_NCHITTEST) Then Return $HTCAPTION
EndFunc

Func _Exit()
    Exit
EndFunc

Hey tvern,

I was trying to think about what the best way to go about putting an image in the circle that is the loading progress bar. Do you have any suggestions? Any incite or help would be greatly appreciated. The imae would most likely be a a jpeg.

Catalyst

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