AutoHotkey Community

It is currently May 27th, 2012, 4:21 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: February 22nd, 2010, 2:56 pm 
I made this script and it works ok.
But there should be a better way.

This is what it does:
If your mouse position is above the text it changes the text color(like in a menu or button).
And the text functions as a buttons.


Code:
Gui +LastFound -Caption Border
Gui, Color, Black, Black

Gui, Font, S10 cWhite, Comic Sans MS
Gui, Add, Text, gReload x2 y2 w80 h20 , Reload
Gui, Add, Text, gPauze x2 y22 w80 h20 , Pauze
Gui, Add, Text, gSuspend x2 y42 w80 h20 , Suspend

Gui, Show,  w80 h63, MenuOptions

GoSub Position
Return



Position:
if WinActive("ahk_class AutoHotkeyGUI")
CoordMode, Mouse, Relative ;get mouse position
Loop
{
; get the position of the text
   MouseGetPos, VarX, VarY
   
   ;-------------------------
   If VarX between 2 and 80
      TempX = 1
   Else
      TempX = 0
   ;--------------
   If VarY between 2 and 21
      TempY = 1
   Else if VarY between 22 and 41
      TempY = 2
   Else if VarY between 42 and 62
      TempY = 3
   Else
      TempY = 0
   ;-------------------------
   
   If (TempX = 1 and TempY = 1)
   {
      Gosub  TReload ; mouse is above the text Reload
   }
   Else if (TempX = 1 and TempY = 2)
   {
      Gosub TPauze ; mouse is above the text Pauze
   }
   Else if (TempX = 1 and TempY = 3)
   {
      Gosub TSuspend ; mouse is above the text Suspend
   }
   Else
   {
      Gosub TOutside ; mouse is not above any text (only usefull if there are other things in the gui)
   }
}

Return



TReload:
Gui, Font, S10 cYellow, Comic Sans MS
GuiControl, Font, Reload  ;change color yellow

Gui, Font, S10 cWhite, Comic Sans MS
GuiControl, Font, Pauze ;change color white

Gui, Font, S10 cWhite, Comic Sans MS
GuiControl, Font, Suspend ;change color white
Return

TPauze:
Gui, Font, S10 cYellow, Comic Sans MS
GuiControl, Font, Pauze

Gui, Font, S10 cWhite, Comic Sans MS
GuiControl, Font, Suspend

Gui, Font, S10 cWhite, Comic Sans MS
GuiControl, Font, Reload
Return

TSuspend:
Gui, Font, S10 cYellow, Comic Sans MS
GuiControl, Font, Suspend

Gui, Font, S10 cWhite, Comic Sans MS
GuiControl, Font, Pauze

Gui, Font, S10 cWhite, Comic Sans MS
GuiControl, Font, Reload
Return

TOutside:
Gui, Font, S10 cWhite, Comic Sans MS
GuiControl, Font, Suspend

Gui, Font, S10 cWhite, Comic Sans MS
GuiControl, Font, Pauze

Gui, Font, S10 cWhite, Comic Sans MS
GuiControl, Font, Reload
Return



Reload:
   Reload
Return

Suspend:
   Suspend
Return

Pauze:
   Pause
Return



So my question is how can i make the code shorter and less noobish?
Ideas or example's are welcome.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 22nd, 2010, 5:44 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
There is no need to make changes if you wrote the code and feel comfortable with it.

If however you're interested in some tips here is one suggestion: GUI fonts can be combined like so -

Code:
TOutside:
Gui, Font, S10 cWhite, Comic Sans MS
GuiControl, Font, Suspend
GuiControl, Font, Pauze
GuiControl, Font, Reload
Return

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 23rd, 2010, 9:49 am 
Offline

Joined: February 7th, 2008, 9:48 pm
Posts: 509
I played around with this idea of changing text color when mouse_over and stumbled on a problem when using event mouse tracking.

It works well until you put a g-label then sometimes it does not work and you have to move the mouse a bit over the text.

I removed the g-labels except on pause text.You can see the difference moving over suspend or reload text and the pause text that has a g-label.

Does anyone sees the origin of the problem?

Code:
Gui +LastFound  -Caption +Border
Gui, Color, Black, Black
Gui, Font, S10 cWhite, Comic Sans MS
Gui, Add, Text,  x2 y2 w80 h20 , Reload
Gui, Add, Text,  x2 y22 w80 h20 vpause gpause, Pause
Gui, Add, Text,  x2 y42 w80 h20 , Suspend
Gui, Show,  w80 h63, MenuOptions
handle:=winexist()

list=static1,static2,static3

OnMessage(0x200,"OnMouseMove")
OnMessage(0x2A3,"OnMouseLeave")
VarSetCapacity(TME,16,0), NumPut(16,TME,0), NumPut(2,TME,4), NumPut(handle,TME,8)

Return


OnMouseMove( wParam, lParam, Msg ) {
   Global
   DllCall( "TrackMouseEvent","uint",&TME )
   MouseGetPos, ,,foundhandle,controlvar
   ToolTip, %controlvar%
   Gosub, setcolor
return
}

setcolor:
stringSplit, change,list,`,
Loop %change0%
{
control:=change%A_Index%

if (control = controlvar)
{
Gui, Font, S10 cYellow, Comic Sans MS
GuiControl, Font, %controlvar% 
}
else
{
Gui, Font, S10 cwhite, Comic Sans MS
GuiControl, Font, %control% 
}
}
return



OnMouseLeave() {
  Global
  Gui, Font, S10 cwhite, Comic Sans MS
  GuiControl, Font, %controlvar% 
return
}

pause:
MsgBox, ,,pause,2
return

suspend:
MsgBox, ,,suspend,2
return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 24th, 2010, 11:59 pm 
thank you for the reply's

althoug i dont understand al the code in yume's script jet.
so i cant help you with the origin of the problem..

bye


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: Mickers, rbrtryn and 69 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