Spiff59 Posted August 7, 2009 Posted August 7, 2009 (edited) I have a complex GUI, in which a large portion of it needs to be drawn in a different manner depending on the value of some input data. In the interest of saving a lot of code... Rather than naming each control, then making a "Clear_Controls()" function containing a hundred "GUICtrlDelete" statements, is there a way to group different types of controls (labels, buttons, checkboxes, graphics) and delete them in a single statement? Or a command to delete every control within certain screen coordinates? Thanks. Edited August 7, 2009 by Spiff59
dantay9 Posted August 7, 2009 Posted August 7, 2009 Kind of. What you can do is make all the labels in an array. $Label[0], $Label[1], etc. Then, to delete all the labels, you just use a loop. For $i = 1 To 100 GuiCtrlDelete($Label[$i]) Next
Spiff59 Posted August 7, 2009 Author Posted August 7, 2009 Kind of. What you can do is make all the labels in an array. $Label[0], $Label[1], etc. Then, to delete all the labels, you just use a loop. For $i = 1 To 100 GuiCtrlDelete($Label[$i]) Next I hadn't gotten a quick reply, so already started coding that. A mix of one and two dimension control arrays and some nested loops kept the code down to about 20 lines. The odd thing now is, when I call the routine to delete the labels/checkboxes/graphics, it caused an unrelated listview elsewhere in the GUI to flicker like crazy.
dantay9 Posted August 7, 2009 Posted August 7, 2009 Post the script and we can see what's wrong. Sometimes, nothing is wrong with the script, you just have to do it a different way.
Spiff59 Posted August 7, 2009 Author Posted August 7, 2009 (edited) Post the script and we can see what's wrong. Sometimes, nothing is wrong with the script, you just have to do it a different way. Well, here's an example of the listview flickering. I just added a loop to the helpfile example to turn a graphic box on and off while there was a listview on the screen. You can execute the GUICtrlCreateGraphic all day long with no problems. It's the GUICtrlDelete of a graphic control that is messing with the listview. expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Opt('MustDeclareVars', 1) Example() Func Example() Local $listview, $button, $item1, $item2, $item3, $input1, $msg, $G1 GUICreate("listview items", 420, 250, 100, 200, -1, $WS_EX_ACCEPTFILES) GUISetBkColor(0x00E0FFFF) ; will change background color $listview = GUICtrlCreateListView("col1 |col2|col3 ", 10, 10, 200, 150);,$LVS_SORTDESCENDING) $button = GUICtrlCreateButton("Value?", 75, 170, 70, 20) $item1 = GUICtrlCreateListViewItem("item2|col22|col23", $listview) $item2 = GUICtrlCreateListViewItem("item1|col12|col13", $listview) $item3 = GUICtrlCreateListViewItem("item3|col32|col33", $listview) $input1 = GUICtrlCreateInput("", 20, 200, 150) GUICtrlSetState(-1, $GUI_DROPACCEPTED) ; to allow drag and dropping GUISetState() GUICtrlSetData($item2, "ITEM1") GUICtrlSetData($item3, "||COL33") GUICtrlDelete($item1) ; added code For $x = 1 to 40 $G1 = GUICtrlCreateGraphic(300, 100, 60, 60) GUICtrlSetColor(-1, 0x808080) Sleep(100) Guictrldelete($g1) Sleep(100) Next ; end of added code Do $msg = GUIGetMsg() Select Case $msg = $button MsgBox(0, "listview item", GUICtrlRead(GUICtrlRead($listview)), 2) Case $msg = $listview MsgBox(0, "listview", "clicked=" & GUICtrlGetState($listview), 2) EndSelect Until $msg = $GUI_EVENT_CLOSE EndFunc ;==>Example Edit: Technically, I see the button control, as well as the input control, flashing in this example. So, I guess the GUICtrlDelete on a graphic type control is causing multiple types of controls, in addition to the listview, to be repainted. Edited August 7, 2009 by Spiff59
dantay9 Posted August 7, 2009 Posted August 7, 2009 I am not sure what is going on. I tried locking the bits, stripping everything, removing the color changes, _GuiCtrlListView_BeginUpdate. Nothing worked. I can't tell you what is wrong.
martin Posted August 7, 2009 Posted August 7, 2009 The GuiCtrlCreateGraphic generates 1 WM_PAINT message and the GuiCtrlDelete generates another one. If you do it with creating a label, colouring it and deleting you will get an extra WM_PAINT for the colouring that doesn't occur with the graphic, but would if you updated the graphic ($GUI_GR_REFRESH). All that repainting is what is causing the flickering. expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Opt('MustDeclareVars', 1) Global $ip=0,$nop=0 Example() Func Example() Local $listview, $button, $item1, $item2, $item3, $input1, $msg, $G1 GUICreate("listview items", 420, 250, 100, 200, -1, $WS_EX_ACCEPTFILES) GUISetBkColor(0x00E0FFFF) ; will change background color guiregistermsg($WM_PAINT,"Paint") $listview = GUICtrlCreateListView("col1 |col2|col3 ", 10, 10, 200, 150);,$LVS_SORTDESCENDING) $button = GUICtrlCreateButton("Value?", 75, 170, 70, 20) $item1 = GUICtrlCreateListViewItem("item2|col22|col23", $listview) $item2 = GUICtrlCreateListViewItem("item1|col12|col13", $listview) $item3 = GUICtrlCreateListViewItem("item3|col32|col33", $listview) $input1 = GUICtrlCreateInput("", 20, 200, 150) GUICtrlSetState(-1, $GUI_DROPACCEPTED) ; to allow drag and dropping GUISetState() GUICtrlSetData($item2, "ITEM1") GUICtrlSetData($item3, "||COL33") GUICtrlDelete($item1) ; added code $nop=1 For $x = 1 to 40 $G1 = GUICtrlCreateGraphic(300, 100, 60, 60) ;GUICtrlSetColor($G1, 0x808080) Sleep(100) Guictrldelete($g1) Sleep(100) Next $nop=0 ; end of added code Do $msg = GUIGetMsg() Select Case $msg = $button MsgBox(0, "listview item", GUICtrlRead(GUICtrlRead($listview)), 2) Case $msg = $listview MsgBox(0, "listview", "clicked=" & GUICtrlGetState($listview), 2) EndSelect Until $msg = $GUI_EVENT_CLOSE EndFunc ;==>Example Func paint($hW, $iM,$wP,$lP) $ip += 1 ConsoleWrite("painting " & $ip & @CRLF) EndFunc I don't know how to avoid it but here is a rather dumb way to get round it, though it means you can't do anything with your gui while it's deleting things. expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <screencapture.au3> Opt('MustDeclareVars', 1) Global $ip = 0, $nop = 0 Example() Func Example() Local $listview, $button, $item1, $item2, $item3, $input1, $msg, $G1, $gui $gui = GUICreate("listview items", 420, 250, 100, 200, -1, $WS_EX_ACCEPTFILES) GUISetBkColor(0x00E0FFFF) ; will change background color GUIRegisterMsg($WM_PAINT, "Paint") $listview = GUICtrlCreateListView("col1 |col2|col3 ", 10, 10, 200, 150);,$LVS_SORTDESCENDING) $button = GUICtrlCreateButton("Value?", 75, 170, 70, 20) $item1 = GUICtrlCreateListViewItem("item2|col22|col23", $listview) $item2 = GUICtrlCreateListViewItem("item1|col12|col13", $listview) $item3 = GUICtrlCreateListViewItem("item3|col32|col33", $listview) $input1 = GUICtrlCreateInput("", 20, 200, 150) GUICtrlSetState(-1, $GUI_DROPACCEPTED) ; to allow drag and dropping GUISetState() GUICtrlSetData($item2, "ITEM1") GUICtrlSetData($item3, "||COL33") GUICtrlDelete($item1) sleep(3000) ; added code #Region hide flicker?? Local $hidew, $gp = WinGetPos($gui) _ScreenCapture_CaptureWnd("tempCover.bmp",$gui, 0,0,-1,-1,false) Local $hidew = GUICreate("", $gp[2], $gp[3], $gp[0], $gp[1], $WS_POPUP) GUISetCursor(15, 1) Local $coverpic = GUICtrlCreatePic("tempCover.bmp", 0, 0, $gp[2], $gp[3]) ;show but without flickering ;WinSetTrans($hidew, "", 0) GUISetState() WinSetOnTop($hidew, "", 1) ; WinSetTrans($hidew, "", 252) Sleep(3000) GUISwitch($gui) #EndRegion hide flicker $nop = 1 For $x = 1 To 40 $G1 = GUICtrlCreateGraphic(300, 100, 60, 60) GUICtrlSetColor($G1, 0x808080) ;Sleep(100) GUICtrlDelete($G1) ; Sleep(100) Next $nop = 0 ; end of added code GUIDelete($hidew) Do $msg = GUIGetMsg() Select Case $msg = $button MsgBox(0, "listview item", GUICtrlRead(GUICtrlRead($listview)), 2) Case $msg = $listview MsgBox(0, "listview", "clicked=" & GUICtrlGetState($listview), 2) EndSelect Until $msg = $GUI_EVENT_CLOSE EndFunc ;==>Example Func paint($hW, $iM, $wP, $lP) $ip += 1 ConsoleWrite("painting " & $ip & @CRLF) EndFunc ;==>paint Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Authenticity Posted August 7, 2009 Posted August 7, 2009 You can use another GUI child window. expandcollapse popup#include <GUIConstantsEx.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> Opt('MustDeclareVars', 1) Example() Func Example() Local $listview, $button, $item1, $item2, $item3, $input1, $msg, $G1 Local $hGUI1, $hGUI2 $hGUI1 = GUICreate("listview items", 420, 250, 100, 200, -1, $WS_EX_ACCEPTFILES) $hGUI2 = GUICreate("", 60, 60, 300, 100, $WS_CHILD, -1, $hGUI1) GUISetBkColor(0x00E0FFFF) GUISwitch($hGUI1) GUISetBkColor(0x00E0FFFF) ; will change background color $listview = GUICtrlCreateListView("col1 |col2|col3 ", 10, 10, 200, 150);,$LVS_SORTDESCENDING) $button = GUICtrlCreateButton("Value?", 75, 170, 70, 20) $item1 = GUICtrlCreateListViewItem("item2|col22|col23", $listview) $item2 = GUICtrlCreateListViewItem("item1|col12|col13", $listview) $item3 = GUICtrlCreateListViewItem("item3|col32|col33", $listview) $input1 = GUICtrlCreateInput("", 20, 200, 150) GUICtrlSetState(-1, $GUI_DROPACCEPTED) ; to allow drag and dropping GUISetState(@SW_SHOW, $hGUI1) GUISetState(@SW_SHOW, $hGUI2) GUICtrlSetData($item2, "ITEM1") GUICtrlSetData($item3, "||COL33") GUICtrlDelete($item1) ; added code GUISwitch($hGUI2) For $x = 1 to 20 $G1 = GUICtrlCreateGraphic(0, 0, 60, 60) GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0xFFFF00, 0xFFFF00) GUICtrlSetGraphic(-1, $GUI_GR_RECT, 0, 0, 60, 60) _WinAPI_InvalidateRect($hGUI2, 0, True) Sleep(200) Guictrldelete($g1) Sleep(200) Next ConsoleWrite('Here' & @CRLF) ; end of added code Do $msg = GUIGetMsg() Select Case $msg = $button MsgBox(0, "listview item", GUICtrlRead(GUICtrlRead($listview)), 2) Case $msg = $listview MsgBox(0, "listview", "clicked=" & GUICtrlGetState($listview), 2) EndSelect Until $msg = $GUI_EVENT_CLOSE EndFunc ;==>Example
Spiff59 Posted August 7, 2009 Author Posted August 7, 2009 You can use another GUI child window. expandcollapse popup#include <GUIConstantsEx.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> Opt('MustDeclareVars', 1) Example() Func Example() Local $listview, $button, $item1, $item2, $item3, $input1, $msg, $G1 Local $hGUI1, $hGUI2 $hGUI1 = GUICreate("listview items", 420, 250, 100, 200, -1, $WS_EX_ACCEPTFILES) $hGUI2 = GUICreate("", 60, 60, 300, 100, $WS_CHILD, -1, $hGUI1) GUISetBkColor(0x00E0FFFF) GUISwitch($hGUI1) GUISetBkColor(0x00E0FFFF) ; will change background color $listview = GUICtrlCreateListView("col1 |col2|col3 ", 10, 10, 200, 150);,$LVS_SORTDESCENDING) $button = GUICtrlCreateButton("Value?", 75, 170, 70, 20) $item1 = GUICtrlCreateListViewItem("item2|col22|col23", $listview) $item2 = GUICtrlCreateListViewItem("item1|col12|col13", $listview) $item3 = GUICtrlCreateListViewItem("item3|col32|col33", $listview) $input1 = GUICtrlCreateInput("", 20, 200, 150) GUICtrlSetState(-1, $GUI_DROPACCEPTED) ; to allow drag and dropping GUISetState(@SW_SHOW, $hGUI1) GUISetState(@SW_SHOW, $hGUI2) GUICtrlSetData($item2, "ITEM1") GUICtrlSetData($item3, "||COL33") GUICtrlDelete($item1) ; added code GUISwitch($hGUI2) For $x = 1 to 20 $G1 = GUICtrlCreateGraphic(0, 0, 60, 60) GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0xFFFF00, 0xFFFF00) GUICtrlSetGraphic(-1, $GUI_GR_RECT, 0, 0, 60, 60) _WinAPI_InvalidateRect($hGUI2, 0, True) Sleep(200) Guictrldelete($g1) Sleep(200) Next ConsoleWrite('Here' & @CRLF) ; end of added code Do $msg = GUIGetMsg() Select Case $msg = $button MsgBox(0, "listview item", GUICtrlRead(GUICtrlRead($listview)), 2) Case $msg = $listview MsgBox(0, "listview", "clicked=" & GUICtrlGetState($listview), 2) EndSelect Until $msg = $GUI_EVENT_CLOSE EndFunc ;==>Example Ah... That not only solves the secondary flickering issue that came up in this thread, but also provides an easy way to zap a whole flock of controls in one fell swoop (my initial question in this thread). Thank you, Sir.
jacQues Posted August 10, 2009 Posted August 10, 2009 I hadn't gotten a quick reply, so already started coding that.A mix of one and two dimension control arrays and some nested loops kept the code down to about 20 lines.The odd thing now is, when I call the routine to delete the labels/checkboxes/graphics, it caused an unrelated listview elsewhere in the GUI to flicker like crazy.Correct, each update will be drawn. Use GUISetState(@SW_LOCK) before starting and GUISetState(@SW_UNLOCK) after finishing. This will remove the flicker and also make your code run much faster.jacQues
mavor Posted December 21, 2009 Posted December 21, 2009 Lock/Unlock method worked extremely well for me. Thanks a ton for the valuable informtion
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now