AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Unexpected behavior of ControlSetText

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
nick



Joined: 24 Aug 2005
Posts: 345
Location: Berlin / Germany

PostPosted: Sun Nov 04, 2007 10:10 am    Post subject: Unexpected behavior of ControlSetText Reply with quote

Hello,

setting a new text into a AHK text control via ControlSetText seems to "overwrite" the existing text, if BackGroundTrans is specified in its options:
Code:
#NoEnv
SetBatchLines, -1

FormatTime, OldTime, , HH:mm:ss

Gui, Margin, 20, 20
Gui, Color, Navy
Gui, Add, Text, x50 w150 cWhite  BackgroundTrans HwndText1ID
Gui, Add, Text, x50 wp cWhite  HwndText2ID
Gui, Show, , ControlSetText

SetTimer, CurrentTime, On

Return

GuiClose:
GuiEscape:
Gui, Destroy
ExitApp

CurrentTime:
FormatTime, CurrentTime, , HH:mm:ss
If (OldTime <> CurrentTime)
{
   ControlSetText, , %CurrentTime% , ahk_id %Text1ID%
   ControlSetText, , %CurrentTime% , ahk_id %Text2ID%
   OldTime := CurrentTime
}
Return


AHK bug or Windows feature?
_________________
nick

denick @ http://de.autohotkey.com/forum/
Back to top
View user's profile Send private message
Lexikos



Joined: 17 Oct 2006
Posts: 2558
Location: Australia, Qld

PostPosted: Sun Nov 04, 2007 11:21 am    Post subject: Reply with quote

Using ControlSetText bypasses AutoHotkey's GUI system entirely (so it has no awareness of BackgroundTrans.) Use GuiControl instead:
Code:
GuiControl,, Static1, %CurrentTime%
Back to top
View user's profile Send private message
nick



Joined: 24 Aug 2005
Posts: 345
Location: Berlin / Germany

PostPosted: Sun Nov 04, 2007 9:28 pm    Post subject: Reply with quote

Sorry lexikos,

that's no answer! Did you try my code?
_________________
nick

denick @ http://de.autohotkey.com/forum/
Back to top
View user's profile Send private message
Superfraggle



Joined: 02 Nov 2004
Posts: 850
Location: London, UK

PostPosted: Sun Nov 04, 2007 10:24 pm    Post subject: Reply with quote

Basically you are using the wrong command

Code:
#NoEnv
SetBatchLines, -1

FormatTime, OldTime, , HH:mm:ss

Gui, Margin, 20, 20
Gui, Color, Navy
Gui, Add, Text, x50 w150 cWhite  BackgroundTrans HwndText1ID vtime1
Gui, Add, Text, x50 wp cWhite  HwndText2ID vtime2
Gui, Show, , ControlSetText

SetTimer, CurrentTime, On

Return

GuiClose:
GuiEscape:
Gui, Destroy
ExitApp

CurrentTime:
FormatTime, CurrentTime, , HH:mm:ss
If (OldTime <> CurrentTime)
{
   Guicontrol, , time1,%CurrentTime%
   Guicontrol, , time2,%CurrentTime%
   OldTime := CurrentTime
}
Return

_________________
Steve F AKA Superfraggle

http://r.yuwie.com/superfraggle
Back to top
View user's profile Send private message MSN Messenger
Lexikos



Joined: 17 Oct 2006
Posts: 2558
Location: Australia, Qld

PostPosted: Mon Nov 05, 2007 12:13 am    Post subject: Reply with quote

nick wrote:
Sorry lexikos,

that's no answer! Did you try my code?
Yes, I did. If you had tried my code (replacing ControlSetText with GuiControl as I said), you'd have realised that it most definitely was the answer.
Back to top
View user's profile Send private message
engunneer



Joined: 30 Aug 2005
Posts: 6772
Location: Pacific Northwest, US

PostPosted: Mon Nov 05, 2007 12:41 am    Post subject: Reply with quote

this is moved to Ask for help, since it is not a bug.
_________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM
Back to top
View user's profile Send private message Visit poster's website
nick



Joined: 24 Aug 2005
Posts: 345
Location: Berlin / Germany

PostPosted: Mon Nov 05, 2007 8:04 am    Post subject: Reply with quote

@engunneer:

So far, so good. But which command should i use to change a text control not created with AHK? Is BackgroundTrans an AHK-specific style and would Control behave different?

@lexikos:

Quote:
Yes, I did. If you had tried my code (replacing ControlSetText with GuiControl as I said), you'd have realised that it most definitely was the answer.

Would you add a picture as gui's background, please? Then you might see the difference between Control and GuiControl.
_________________
nick

denick @ http://de.autohotkey.com/forum/
Back to top
View user's profile Send private message
Lexikos



Joined: 17 Oct 2006
Posts: 2558
Location: Australia, Qld

PostPosted: Mon Nov 05, 2007 10:36 am    Post subject: Reply with quote

Interesting...

If the picture is added first, GuiControl causes everything but the first text control to disappear. If ControlSetText is used, the first text control is invisible, but everything else remains.

If the picture is added last, the first text control is invisible regardless of whether GuiControl or ControlSetText is used.

[Edit] Actually, using Superfraggles version of the script as a base, the first text control is always invisible, and everything else is always visible... [/Edit]

I see a difference, but either way the GUI as a whole is broken.


None of this changes my original point: ControlSetText cannot be expected to take into account the GUI options. In some cases, the GUI options correspond directly to standard window styles. This is not one of those cases.
Quote:
But which command should i use to change a text control not created with AHK?
I'm not sure why you addressed the question at engunneer, but anyway... ControlSetText is intended for use with external controls, just as GuiControl is intended for internal GUI controls.
Quote:
Is BackgroundTrans an AHK-specific style and would Control behave different?
Have I not already stated that ControlSetText has no awareness of BackgroundTrans?

BackgroundTrans is implemented by hooking the "CTLCOLOR" messages, and setting a "null" brush to be used for the background. In other words, there is no way for ControlSetText to know that the option is in effect. Essentially, having a null background brush means the background won't be drawn when the control redraws itself. In the case of text controls, it may leave an image of the previous text behind.

GuiControl compensates for this by invalidating the rectangle which the control occupies. I'm not sure how that causes everything else to be "hidden." ("Invalidating" is notifying the OS that the window must be redrawn. In this case it should redraw only what is behind the control, and the control itself.)

Edit: This is the AHK equivalent of what GuiControl does to redraw:
Code:
VarSetCapacity(rect,16)
DllCall("GetWindowRect","uint",Text1ID,"uint",&rect)
Gui, +LastFound
DllCall("MapWindowPoints","uint",0,"uint",WinExist(),"uint",&rect,"int",2)
DllCall("InvalidateRect","uint",WinExist(),"uint",&rect,"int",1)
Using that with ControlSetText lets it work as well as GuiControl, but the control is still invisible when I add a picture...
Back to top
View user's profile Send private message
nick



Joined: 24 Aug 2005
Posts: 345
Location: Berlin / Germany

PostPosted: Mon Nov 05, 2007 11:14 am    Post subject: Reply with quote

lexikos wrote:
In some cases, the GUI options correspond directly to standard window styles. This is not one of those cases.


O.K., that's an answer Idea
_________________
nick

denick @ http://de.autohotkey.com/forum/
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group