Sign in to follow this  
Followers 0
Rawox

Creating lines and rectangles?

5 posts in this topic

Hey,

Is there a way to create lines and rectangles in a GUI. I want to create them but I don't understand the GUICtrlCreateGraphic function.

So, could someone explain that one a little bit better to me or are there other ways to do this?

Rawox.

Share this post


Link to post
Share on other sites



Rawox,

Hello yet again.....

Here is a commented example of how to use GUICtrlCreateGraphic and how to draw rectangles and lines:

#include <GUIConstantsEx.au3>

; Create GUI
$hGUI = GUICreate("Test", 500, 500)

; Create GREEN graphic
$hGraph_1 = GUICtrlCreateGraphic(10, 10, 250, 250)
GUICtrlSetBkColor(-1, 0x00FF00)
; Create BLACK bordered YELLOW rectangle within graphic
GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0, 0xffff00)
GUICtrlSetGraphic($hGraph_1, $GUI_GR_RECT, 20, 20, 210, 210)

; Create RED graphic
$hGraph_2 = GUICtrlCreateGraphic(205, 250, 250, 250)
GUICtrlSetBkColor(-1, 0xFF0000)
; Set line start point
GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 10, 10)
; Set line colour to GREEN
GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x00ff00)
; Draw line to this point
GUICtrlSetGraphic(-1, $GUI_GR_LINE, 240, 240)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

WEnd

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

Thanks for your reply Melba.

This will become handy :)

Share this post


Link to post
Share on other sites

Is there a way to do this and have a transparent gui I just want to paint the graphic to the screen. Everything else to be transparent.

Roger

Rawox,

Hello yet again.....

Here is a commented example of how to use GUICtrlCreateGraphic and how to draw rectangles and lines:

#include <GUIConstantsEx.au3>

; Create GUI
$hGUI = GUICreate("Test", 500, 500)

; Create GREEN graphic
$hGraph_1 = GUICtrlCreateGraphic(10, 10, 250, 250)
GUICtrlSetBkColor(-1, 0x00FF00)
; Create BLACK bordered YELLOW rectangle within graphic
GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0, 0xffff00)
GUICtrlSetGraphic($hGraph_1, $GUI_GR_RECT, 20, 20, 210, 210)

; Create RED graphic
$hGraph_2 = GUICtrlCreateGraphic(205, 250, 250, 250)
GUICtrlSetBkColor(-1, 0xFF0000)
; Set line start point
GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 10, 10)
; Set line colour to GREEN
GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x00ff00)
; Draw line to this point
GUICtrlSetGraphic(-1, $GUI_GR_LINE, 240, 240)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

WEnd

M23

Share this post


Link to post
Share on other sites

RogFleming,

Not asking for much, then.... >_<

Actually, it is not that difficult. This code comes courtesy of ProgAndy (just in case you thought I was clever enough to have done it by myself!)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WINAPI.au3>
#include <sendmessage.au3>

HotKeySet("ESC", "_Exit")

$hGUI = GUICreate("Test", 500, 500, -1, -1, $WS_POPUP, $WS_EX_LAYERED)
GUISetBkColor(0xABCDEF)

; Create GREEN graphic
$hGraph_1 = GUICtrlCreateGraphic(10, 10, 250, 250)
GUICtrlSetBkColor(-1, 0x00FF00)
; Create BLACK bordered YELLOW rectangle within graphic
GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0, 0xffff00)
GUICtrlSetGraphic($hGraph_1, $GUI_GR_RECT, 20, 20, 210, 210)

; Create RED graphic
$hGraph_2 = GUICtrlCreateGraphic(205, 250, 250, 250)
GUICtrlSetBkColor(-1, 0xFF0000)
; Set line start point
GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 10, 10)
; Set line colour to GREEN
GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x00ff00)
; Draw line to this point
GUICtrlSetGraphic(-1, $GUI_GR_LINE, 240, 240)

_WinAPI_SetLayeredWindowAttributes($hGUI, 0xABCDEF, 250)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_EVENT_PRIMARYDOWN
            _SendMessage($hGUI, $WM_SYSCOMMAND, 0xF012, 0)
    EndSwitch

WEnd

Func _Exit()
    Exit
EndFunc

Func _WinAPI_SetLayeredWindowAttributes($hwnd, $i_transcolor, $Transparency = 255, $dwFlages = 0x03, $isColorRef = False)
; #############################################
; You are NOT ALLOWED to remove the following lines
; Function Name: _WinAPI_SetLayeredWindowAttributes
; Author(s): Prog@ndy
; #############################################
    If $dwFlages = Default Or $dwFlages = "" Or $dwFlages < 0 Then $dwFlages = 0x03

    If Not $isColorRef Then
        $i_transcolor = Hex(String($i_transcolor), 6)
        $i_transcolor = Execute('0x00' & StringMid($i_transcolor, 5, 2) & StringMid($i_transcolor, 3, 2) & StringMid($i_transcolor, 1, 2))
    EndIf
    Local $Ret = DllCall("user32.dll", "int", "SetLayeredWindowAttributes", "hwnd", $hwnd, "long", $i_transcolor, "byte", $Transparency, "long", $dwFlages)
    Select
        Case @error
            Return SetError(@error, 0, 0)
        Case $Ret[0] = 0
            Return SetError(4, _WinAPI_GetLastError(), 0)
        Case Else
            Return 1
    EndSelect
EndFunc  ;==>_WinAPI_SetLayeredWindowAttributes

Just click on the graphics to move the GUI - and use ESC to exit.

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  
Followers 0