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 

GUI window size & added picture affect control location

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



Joined: 08 Apr 2009
Posts: 5336
Location: San Diego, California

PostPosted: Sat Oct 17, 2009 2:26 pm    Post subject: GUI window size & added picture affect control location Reply with quote

I want window with an image background and no caption/border
with a single a text control, (or a place to show text), that is centered x & y,
and I want to specify window width & height

Standard (as shown) provides a window with coltrol centered as desired.

But if I specify picture control first (as a pseudo background) or if I specify window size
the text control is no longer centered in either direction.

Can I do this w/o extensive calculations to place the control ? Can anyone correct my code ?

Thanks in advance

Leef_me

Code:
Width2 := 530, Height2 := 230  ; solid or gradient portion
win2 = solid

;Gui, 2: -Caption  +AlwaysOnTop +ToolWindow +OwnDialogs
Gui, 2: +AlwaysOnTop
Gui, 2: Font, s48

;Gui, 2: add, picture, x0 y0 w%Width2% h%height2%, Dots4.bmp

Gui, 2:add, text,  center cred BackgroundTrans vdtime, 00:00

Gui, 2: Show,    center, %win2%

;Gui, 2: Show,  w%Width2% h%height2%  center, %win2%

return
Back to top
View user's profile Send private message
Roland



Joined: 08 Jun 2006
Posts: 307

PostPosted: Sat Oct 17, 2009 3:00 pm    Post subject: Reply with quote

I think you've misunderstood what "center" does: It centers the contents of the text control within the control itself; it doesn't center the control within the GUI.

Anyway, here's my solution - it does require calculations, but they're really not that extensive Smile

Code:
#NoEnv
#SingleInstance force
SetWorkingDir %a_scriptDir%

width:=530, height:=230

Gui, +toolwindow -caption
Gui, Margin, 0, 0
Gui, Font, s48 cred
Gui, Add, Pic, w%width% h%height%, pic.jpg
Gui, Add, Text, vtext w%width% center backgroundTrans, 00:00
Gui, Show, hide
GuiControlGet, text, pos
GuiControl, Move, text, % "y" (height/2)-(textH/2)
Gui, Show, h%height%
return
Back to top
View user's profile Send private message
SKAN



Joined: 26 Dec 2005
Posts: 8688

PostPosted: Sat Oct 17, 2009 3:01 pm    Post subject: Re: GUI window size & added picture affect control locat Reply with quote

Leef_me wrote:
Can I do this w/o extensive calculations to place the control ?


Code:
Gui, 2:add, picture, x0 y0 w%Width2% h%height2%, Dots4.bmp
Gui, 2:add, text,  xp yp wp hp 0x201 BackgroundTrans vdtime, 00:00
Back to top
View user's profile Send private message Send e-mail
Roland



Joined: 08 Jun 2006
Posts: 307

PostPosted: Sat Oct 17, 2009 3:17 pm    Post subject: Reply with quote

Nice Smile What's 0x201? Apart from WM_LBUTTONDOWN Confused
Back to top
View user's profile Send private message
jaco0646



Joined: 07 Oct 2006
Posts: 3113
Location: MN, USA

PostPosted: Sat Oct 17, 2009 3:44 pm    Post subject: Reply with quote

0x201 = 0x1 + 0x200

0x1 = SS_CENTER (horizontal)
0x200 = SS_CENTERIMAGE (vertical)
Back to top
View user's profile Send private message Visit poster's website
Roland



Joined: 08 Jun 2006
Posts: 307

PostPosted: Sat Oct 17, 2009 4:22 pm    Post subject: Reply with quote

Thanks jaco Smile
Back to top
View user's profile Send private message
Leef_me



Joined: 08 Apr 2009
Posts: 5336
Location: San Diego, California

PostPosted: Sat Oct 17, 2009 5:57 pm    Post subject: Reply with quote

Roland wrote:
think you've misunderstood what "center" does:
I knew that, sorry I wasn't clear. The centering of the control within the window is because some default setting when there are no other controls to the left/right. I like your coding, but SKAN's is what I was hoping for. BTW, thanks for asking about 0x201.

@ SKAN thanks again, that's what I couldn't think to do (styles are somewhat new to me)

@jaco0646 thanks for posting the definitions.
It's interesting they are both called 'center' but one is vertical the other horizontal.
It's also interesting that one is catagorized for Text the other for Picture. Embarassed
Back to top
View user's profile Send private message
SKAN



Joined: 26 Dec 2005
Posts: 8688

PostPosted: Sun Oct 18, 2009 1:31 am    Post subject: Reply with quote

Leef_me wrote:
It's also interesting that one is catagorized for Text the other for Picture. Embarassed


If you inspect Text and Picture control with a AU3 spy, you can see that the class name is Static for both.. but I never knew when I discovered it with Brute Force method.
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
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