AutoHotkey Community

It is currently May 26th, 2012, 10:04 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: October 17th, 2009, 3:26 pm 
Online

Joined: April 8th, 2009, 7:49 pm
Posts: 6065
Location: San Diego, California
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 17th, 2009, 4:00 pm 
Offline

Joined: June 8th, 2006, 9:38 pm
Posts: 307
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 :)

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


Report this post
Top
 Profile  
Reply with quote  
PostPosted: October 17th, 2009, 4:01 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 17th, 2009, 4:17 pm 
Offline

Joined: June 8th, 2006, 9:38 pm
Posts: 307
Nice :) What's 0x201? Apart from WM_LBUTTONDOWN :?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 17th, 2009, 4:44 pm 
Offline

Joined: October 7th, 2006, 4:50 pm
Posts: 3157
Location: MN, USA
0x201 = 0x1 + 0x200

0x1 = SS_CENTER (horizontal)
0x200 = SS_CENTERIMAGE (vertical)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 17th, 2009, 5:22 pm 
Offline

Joined: June 8th, 2006, 9:38 pm
Posts: 307
Thanks jaco :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 17th, 2009, 6:57 pm 
Online

Joined: April 8th, 2009, 7:49 pm
Posts: 6065
Location: San Diego, California
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. :oops:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 18th, 2009, 2:31 am 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
Leef_me wrote:
It's also interesting that one is catagorized for Text the other for Picture. :oops:


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.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Google [Bot], hyper_, JSLover, Leef_me, patgenn123 and 60 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group