SlowCoder74 Posted February 18, 2014 Share Posted February 18, 2014 As explained before, in another thread, I am developing a wallboard, which contains many labels (up to 384) that are dynamically created. I may run multiple instances of the EXE at one time. It seems if I run instance 1, and while it is creating the labels I run instance 2/3/4, the labels in the other instances are not created correctly. A subsequent reload of the other instances allows them to load correctly. It's as if they are sharing a master process (they aren't, in my code), or there is leakage of data. I think I've tracked it down to a call to ControlGetPos(), which doesn't always seem to return an array of data. At first thought, you'd think maybe the window or label hWnd were invalid, but then a simple addition of a conditional loop around the ControlGetPos() func until it returns an array: $ControlParams="" while not IsArray($ControlParams) $ControlParams=ControlGetPos(WinGetTitle($FrmHWnd),"",$LabelHwnd) wend partially fixes the problem, and there are no errors. At this point, it's like we're waiting for the label to actually be created. But still the function doesn't seem to return the proper parameters, as the label is then not properly repositioned with the following command: $VPadding=1 GUICtrlSetPos($LabelhWnd,Default,Default,Default,$ControlParams[3]+($VPadding*2)) Here is my full function: expandcollapse popup#include "_StringSize.au3" ;supplied by Melba23 Func _CreateLabel($FrmHWnd,$Txt,$X,$Y,$W=-1,$H=-1,$VPadding=0,$FontSize="10",$FontFace="Times New Roman",$Style="BOLD",$Align="LEFT",$FGColor="777777",$BGColor="000000") ;Creates label based on provided parameters, and returns the hWnd of the label control ;$FrmHWnd=control ID of form to add label to ;$Txt=text to display ;X=left,Y=top ;W=[width],H=[height]. If either is omitted, that parameter is variable. Otherwise, static ;$VPadding=[vertical padding] ;$FontSize=fontsize,$FontFace=[fontface] ;$Style=[NORMAL,BOLD,ITALIC,UNDERLINE,STRIKE] ;$Align=[LEFT,RIGHT,HCENTER,VCENTER] ; Note: using VCENTER seems to disable multiline support in the labels ;$FGColor=[RRGGBB],$BGColor=[RRGGBB] ;convert RGB HTML (#) to RGB Hex (0x) colors $FGColor = _RGBColor($FGColor,"0x") $BGColor = _RGBColor($BGColor,"0x") ;set default values if $X="" then $X=0 ;left if $Y="" then $Y=0 ;top if $W="" then $W=-1 ;width if $H="" then $H=-1 ;height if $VPadding="" then $VPadding=0 ;get styles $FontStyle=0 if StringInStr($Style,"ITALIC",0) > 0 then $FontStyle = $FontStyle + 2 if StringInStr($Style,"UNDERLINE",0) > 0 then $FontStyle = $FontStyle + 4 if StringInStr($Style,"STRIKE",0) > 0 then $FontStyle = $FontStyle + 8 $FontWeight=400 ;default font weight if StringInStr($Style,"BOLD",0) > 0 then $FontWeight = 800 ;get alignment $AlignMode=$GUI_SS_DEFAULT_LABEL if StringInStr($Align,"LEFT",0) > 0 then $AlignMode = BitOR($AlignMode,$SS_LEFT) if StringInStr($Align,"HCENTER",0) > 0 then $AlignMode = BitOR($AlignMode,$SS_CENTER) if StringInStr($Align,"RIGHT",0) > 0 then $AlignMode = BitOR($AlignMode,$SS_RIGHT) if StringInStr($Align,"VCENTER",0) > 0 then $AlignMode = BitOR($AlignMode,$SS_CENTERIMAGE) ;note: using VCENTER seems to disable multiline support in the labels ;determine label size $LabelParams=_StringSize($Txt,int($FontSize),int($FontWeight),$FontStyle,$FontFace) ;get required parameters to display label if $W=-1 then $W=$LabelParams[2] ;variable width, based on label if $H=-1 then $H=$LabelParams[3] ;variable height, based on label ;create label $LabelhWnd=GUICtrlCreateLabel($Txt,$X,$Y,$W,$H,$AlignMode) ;create label GUICtrlSetFont($LabelhWnd,$FontSize,$FontWeight,$FontStyle,$FontFace) ;adjust font if $FGColor<>"" then GUICtrlSetColor($LabelhWnd, $FGColor) ;foreground color if $BGColor<>"" then GUICtrlSetBkColor($LabelhWnd, $BGColor) ;background color. If "", will be transparent ;add vertical padding if IsNumber($VPadding) and $VPadding<>"" Then $ControlParams = "" while Not IsArray($ControlParams) $ControlParams=ControlGetPos(WinGetTitle($FrmHWnd),"",$LabelHwnd) WEnd GUICtrlSetPos($LabelhWnd,Default,Default,Default,$ControlParams[3]+($VPadding*2)) EndIf Return $LabelhWnd EndFunc (Sorry, looks like indentation got a little screwed up) Link to comment Share on other sites More sharing options...
Solution BrewManNH Posted February 18, 2014 Solution Share Posted February 18, 2014 Don't use WinGetTitle for the windows you're creating, use their handles to reference them. Also, why are you attempting to get the control's position, don't you already know them? If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
SlowCoder74 Posted February 18, 2014 Author Share Posted February 18, 2014 Don't use WinGetTitle for the windows you're creating, use their handles to reference them. Also, why are you attempting to get the control's position, don't you already know them? No, I don't specifically know the positions, because they are dynamically created based on a number of agents, rows, columns, etc. Removing WinGetTitle seems to have fixed it! I'm sure I had a great reason for putting it in there in the beginning. Maybe ControlGetPos didn't support just using hWnd when I wrote the function? I dunno. Link to comment Share on other sites More sharing options...
BrewManNH Posted February 18, 2014 Share Posted February 18, 2014 If you create the controls, you have a way of keeping track of where they are when you create them. Dynamically or not, you have to tell the interpreter where to put them at some point in your script. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
SlowCoder74 Posted February 18, 2014 Author Share Posted February 18, 2014 If you create the controls, you have a way of keeping track of where they are when you create them. Dynamically or not, you have to tell the interpreter where to put them at some point in your script. I guess I'll put it this way. The positions and sizes are calculated dynamically during creation, based on the number of agents, text size, etc. I did not consciously decide the specific locations of each, other than to build the calculation algorithm. So, yes, the locations are "known", but not necessarily stored in any variables within my app. After the labels have been created, sized and placed, only the text and colors have to be updated as the new wallboard information is retrieved. If you're interested, I've attached an image of the wallboard. The columns and rows can be configured, as well as font, font size, etc. Everything is dynamic. Link to comment Share on other sites More sharing options...
BrewManNH Posted February 18, 2014 Share Posted February 18, 2014 My point was, you should be storing the locations if you need to know where they are, instead of trying to find where they're located after the fact. You've already got the $ControlParam3[3] information, it's your $H variable, why not just use that in your GUICtrlSetPos, or completely get rid of the GUICtrlSetPos function and just add the padding information when you create the label if needed. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
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