Jump to content

GUICtrlSetGraphic() problem


annelinn
 Share

Recommended Posts

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")
Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

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