Jump to content
Sign in to follow this  
ahmet

help needed for multiple GUI

Recommended Posts

Melba23

ahmet,

Looks to me as if you were destroying the graphic each time you tried to draw a new line. I can get multiple lines with this code:

#cs ----------------------------------------------------------------------------

    AutoIt Version: 3.3.4.0
    Author:         myName

    Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here

#include <GuiConstantsEx.au3>
#include <GDIPlus.au3>

$main = GUICreate("Drawing", 400, 400)

$file_menu = GUICtrlCreateMenu("File")
$exit_sub = GUICtrlCreateMenuItem("Exit", $file_menu)

$draw_menu = GUICtrlCreateMenu("Draw")
$line = GUICtrlCreateMenuItem("Line", $draw_menu)

$arc = GUICtrlCreateMenuItem("Arc", $draw_menu)
$circle = GUICtrlCreateMenuItem("Circle", $draw_menu)
$spline = GUICtrlCreateMenuItem("Spline", $draw_menu)
$rectangle = GUICtrlCreateMenuItem("Rectangle", $draw_menu)

GUISetState()

_GDIPlus_Startup()
$graphic = _GDIPlus_GraphicsCreateFromHWND($main)

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE Or $msg = $exit_sub
            ExitLoop
        Case $msg = $line
            GUISetState(@SW_DISABLE)
            GUICreate("Coordinates", 200, 150)
            GUISetState()
            GUICtrlCreateGroup("Start Point", 10, 10, 80, 80)
            $x1 = GUICtrlCreateInput("x", 15, 30, 30, 20)
            $y1 = GUICtrlCreateInput("y", 50, 30, 30, 20)
            GUICtrlCreateGroup("End Point", 100, 10, 80, 80)
            $x2 = GUICtrlCreateInput("x", 105, 30, 30, 20)
            $y2 = GUICtrlCreateInput("y", 140, 30, 30, 20)
            $ok_button = GUICtrlCreateButton("OK", 60, 120, 40, 20)
            $cancel_button = GUICtrlCreateButton("Cancel", 110, 120, 40, 20)
            While 1
                $msg = GUIGetMsg()
                Select
                    Case $msg = $GUI_EVENT_CLOSE
                        ExitLoop
                    Case $msg = $ok_button
                        $p1 = GUICtrlRead($x1)
                        $p2 = GUICtrlRead($x2)
                        $t1 = GUICtrlRead($y1)
                        $t2 = GUICtrlRead($y2)
                        GUIDelete()
                        GUISetState(@SW_ENABLE, $main)
                        WinActivate($main)

                        _GDIPlus_GraphicsDrawLine($graphic, $p1, $t1, $p2, $t2)

                        ExitLoop

                EndSelect
            WEnd
    EndSelect
WEnd

_GDIPlus_GraphicsDispose($graphic)
_GDIPlus_Shutdown()

I hope it helps. :mellow:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
ahmet

Last line always deletes after I draw a new one

Share this post


Link to post
Share on other sites
Melba23

ahmet,

First, a belated welcome to the AutoIt forum. :mellow:

I am not an expert with GDI, but this now refreshes the lines - although you do have to close all other windows first:

#cs ----------------------------------------------------------------------------

    AutoIt Version: 3.3.4.0
    Author:         myName

    Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>

$main = GUICreate("Drawing", 400, 400)

$file_menu = GUICtrlCreateMenu("File")
$exit_sub = GUICtrlCreateMenuItem("Exit", $file_menu)

$draw_menu = GUICtrlCreateMenu("Draw")
$line = GUICtrlCreateMenuItem("Line", $draw_menu)

$arc = GUICtrlCreateMenuItem("Arc", $draw_menu)
$circle = GUICtrlCreateMenuItem("Circle", $draw_menu)
$spline = GUICtrlCreateMenuItem("Spline", $draw_menu)
$rectangle = GUICtrlCreateMenuItem("Rectangle", $draw_menu)

GUISetState()

_GDIPlus_Startup()
$graphic = _GDIPlus_GraphicsCreateFromHWND($main)
$bitmap = _GDIPlus_BitmapCreateFromGraphics(401, 401, $graphic)
$backbuffer = _GDIPlus_ImageGetGraphicsContext($bitmap)

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE Or $msg = $exit_sub
            ExitLoop
        Case $msg = $line
            GUISetState(@SW_DISABLE)
            GUICreate("Coordinates", 200, 150)
            GUISetState()
            GUICtrlCreateGroup("Start Point", 10, 10, 80, 80)
            $x1 = GUICtrlCreateInput("x", 15, 30, 30, 20)
            $y1 = GUICtrlCreateInput("y", 50, 30, 30, 20)
            GUICtrlCreateGroup("End Point", 100, 10, 80, 80)
            $x2 = GUICtrlCreateInput("x", 105, 30, 30, 20)
            $y2 = GUICtrlCreateInput("y", 140, 30, 30, 20)
            $ok_button = GUICtrlCreateButton("OK", 60, 120, 40, 20)
            $cancel_button = GUICtrlCreateButton("Cancel", 110, 120, 40, 20)
            While 1
                $msg = GUIGetMsg()
                Select
                    Case $msg = $GUI_EVENT_CLOSE
                        ExitLoop
                    Case $msg = $ok_button
                        $p1 = GUICtrlRead($x1)
                        $p2 = GUICtrlRead($x2)
                        $t1 = GUICtrlRead($y1)
                        $t2 = GUICtrlRead($y2)
                        GUIDelete()
                        GUISetState(@SW_ENABLE, $main)
                        WinActivate($main)

                        _GDIPlus_GraphicsDrawLine($backbuffer, $p1, $t1, $p2, $t2)
                        _GDIPlus_GraphicsDrawImageRect($graphic, $bitmap, 0, 0, 401, 401)
                        ExitLoop

                EndSelect
            WEnd
    EndSelect
WEnd

_GDIPlus_GraphicsDispose($backbuffer)
_GDIPlus_BitmapDispose($bitmap)
_GDIPlus_GraphicsDispose($graphic)
_GDIPlus_Shutdown()

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
Melba23

ahmet,

Glad I could help. :mellow:

Might I suggest that you make your titles a bit more descriptive of the problem in future? If you had added "GDI" to the title, you would have attracted the GDI gurus and got more expert help (perhaps!).

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
Melba23

ahmet,

And what have you done to solve the problem before posting here? We would prefer that you make some effort to debug something as simple as this by yourself before asking for help. :mellow:

If you have the full version of SciTE4AutoIt3 then run Tidy (by pressing Ctrl-T or via the <Tools> menu) and it will indicate where the problem is. If you do not have the full SciTE package, I recommend you download it from here.

If you do not have Tidy available, then here is a clue: :(

Where is the

WEnd to match the While 1 on line 89?

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.