Sign in to follow this  
Followers 0
annelinn

GUICtrlSetGraphic() problem

9 posts in this topic

I'm trying to use GUICtrlSetGraphic() to draw simple shapes (squares and lines) within a specified area of a window.

The script below creates a window, and creates a blue graphic control inside the window. Then it tries to draw a rectangle inside the blue area.

The script is as close as possible to the example script given in the help file for GUICtrlSetGraphic(). Naturally, the example script works perfectly, and mine doesn't. What might I be doing wrong?

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>

; Create a GUI main window
$Mwin_handle = GUICreate("Test", 1000, 600, 0, 0)
GUISetState(@SW_SHOW)

; Create a graphic control within the window
$Swin_handle = GUICtrlCreateGraphic(800, 400, 100, 100)
GUICtrlSetBkColor(-1, 0x0000ff)     ; Blue background
GUICtrlSetColor(-1, 0x000000)       ; Black border

; Try to draw a black square inside the blue area
GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x000000)
GUICtrlSetGraphic(-1, $GUI_GR_RECT, 50, 50, 20, 20)

; Prompt the user before terminating script
MsgBox(1, "test", "waiting")

Share this post


Link to post
Share on other sites



annelinn,

Your code works prefectly for me. ;)

Perhaps your monitor makes it difficult to see the black rectangle on the blue background. Have you tried to change the blue to a lighter shade (0xC4C4FF for example)? :)

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

#3 ·  Posted (edited)

Perhaps your monitor makes it difficult to see the black rectangle on the blue background. Have you tried to change the blue to a lighter shade (0xC4C4FF for example)? ;)

Yes, I've tried various combinations of colours (including black on white, and vice-versa). I've also tried using different windows themes.

Perhaps it's a Windows Vista problem.

Edited by annelinn

Share this post


Link to post
Share on other sites

annelinn,

Perhaps it's a Windows Vista problem

No - I am running Vista. ;)

What exactly does not work when you run your code? Does the larger area display correctly?

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

The main window, and the blue area within it, are displayed properly. The little black boxes I'm trying to draw inside the blue area don't appear at all.

Here's a screenshot.

post-48660-12827526222033_thumb.jpg

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Hmm, I get the same result as you, annelinn, I also am running Vista, Home Premium.

Edited by somdcomputerguy

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

It's a repaint issue. Add this after your drawing is finished

_WinAPI_InvalidateRect($Mwin_handle)

Alternatively, don't show your GUI (GuiSetState) until your drawing is finished.

Share this post


Link to post
Share on other sites

wrathdu,

It's a repaint issue

Which explains why it worked for me. The message box actually covered the graphics area on my display and I had to move it to see the small box - hence automatic repainting.

Thanks. ;)

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

#9 ·  Posted (edited)

Yes, that's the solution. Thank you, all, for your generous help.

The fixed script is below for future reference.

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#Include <WinAPI.au3>

; Create a GUI main window
$Mwin_handle = GUICreate("Test", 1000, 600, 0, 0)
GUISetState(@SW_SHOW)

; Create a graphic control within the window
$Swin_handle = GUICtrlCreateGraphic(800, 400, 100, 100)
GUICtrlSetBkColor(-1, 0x0000ff)     ; Blue background
GUICtrlSetColor(-1, 0x000000)       ; Black border

; Try to draw a black square inside the blue area
GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x000000)
GUICtrlSetGraphic(-1, $GUI_GR_RECT, 50, 50, 20, 20)

_WinAPI_InvalidateRect($Mwin_handle)

; Prompt the user before terminating script
MsgBox(1, "test", "waiting")
Edited by annelinn

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