 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Veovis
Joined: 13 Feb 2006 Posts: 390 Location: Utah
|
Posted: Sun Apr 09, 2006 10:27 pm Post subject: |
|
|
That has been requested soooo many times!
Nice work! I like your Always @ Bottem and Replace Start Button Tips as well! _________________
"Power can be given overnight, but responsibility must be taught. Long years go into its making." |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 5882
|
Posted: Sun May 14, 2006 10:11 am Post subject: |
|
|
| Quote: | How to Simulate a Graphical Button in a GUI?
http://www.autohotkey.com/forum/viewtopic.php?p=59899#59899
| Quote: | Foreword: This post is NOT about adding a Picture to a GUI Button.
If you are interested and want to know How to Create a Picture Button,
you may visit corrupt's post: Graphic Buttons |
PART 1 : Efficiently using picture(s) to Simulate the Effect of Button Press.
A regular GUI Button is a 3D object. That is, the Button is displayed projected (in default state) and looks sunkenwhen depressed. The GUI Button remains sunken until you release the Mouse Button ( gLabel will not be executed unless the mouse button is released).
A Button has two states - ON ( Sunken ) / OFF ( Projected ) . Its obvious that we need two semi identical pictures to display the sunken & projected state of a button.
Do we always need two pictures to simulate a Button Press?
The answer is NO! In most cases a single picture would suffice.
Instead of the Projected & Sunken states of a Button I have attempted to simulate Flat & Sunken
states using a single ICON with the following code: | Code: | Gui, -Sysmenu +Toolwindow
Gui, Add , Picture, x13 y13 w32 h32 E0x200 vState1 icon1 , %A_AhkPath%
Gui, Add , Picture, x+10 y13 w34 h34 Border vState0 icon1 , %A_AhkPath%
Gui, Add, Text , x13 ,E0x200 Border
Gui, Show, x50 y50 AutoSize, Picture Options
Return
GuiEscape:
ExitApp
Return | Snapshot: 
- Have used Border in the Picture's option for drawing a thin border around the Flat Button
- Have used an Extend Style E0x200 in the Picture's option for simulating the Sunken Button effect.
- The default size of Icon is w32 h32, but Extend Style E0x200 increases the size of the Sunken Button
- Flat button has been sized two pixels extra to match the size of Sunken Button.
The following code overlaps the two Styles (of the same Icon) to simulate a Graphical Checkbox
| Code: | ; Toggle.ahk - Readymade code for a Graphical Checkbox
Gui, +Sysmenu +ToolWindow
Gui, Margin,12,12
Gui, Add , Picture, x13 y13 w32 h32 E0x200 vState1 icon1 gSubRoutine1, %A_AhkPath%
Gui, Add , Picture, x13 y13 w34 h34 Border vState0 icon1 gSubRoutine1, %A_AhkPath%
GoSub, Toggle_Switch
Gui, Show, x50 y50 AutoSize, Toggle
Return
Toggle_Switch:
If Toggle=0
{
GuiControl, Hide, State0
GuiControl, Show, State1
Toggle=1
}
Else {
GuiControl, Hide, State1
GuiControl, Show, State0
Toggle=0
}
Return
SubRoutine1:
GoSub,Toggle_Switch
; < - - - - - - - - P U T Y O U R C O D E H E R E
Return
GuiEscape:
GuiClose:
ExitApp
Return |
Snapshots: <-OFF/ON-> 
The following code overlaps the two Styles (of the same Icon) to simulate a Graphical Button. | Code: | ;RegularButton.ahk - Readymade Code testing a Graphical Button
Gui, +Sysmenu +ToolWindow
Gui, Margin,12,12
Gui, Add , Picture, x13 y13 w34 h34 E0x200 vState1 icon1 gSubRoutine1, %A_AhkPath%
Gui, Add , Picture, x13 y13 w32 h32 0x400000 vState0 icon1 gSubRoutine1, %A_AhkPath%
Gui, Show, x50 y50 AutoSize, Button
Return
SubRoutine1:
GuiControl, Hide, State0
Sleep 250
GuiControl, Show, State0
Msgbox, < - - - - - - - - P U T T H E M A I N C O D E H E R E
Return
GuiEscape:
GuiClose:
ExitApp
Return |
Note: Unlike in a Graphical Checkbox, I have used 0x400000 to display the Graphical Button projected.
|
| Quote: | How to Simulate a Graphical Button in a GUI?
PART 2 : An Advanced Technique - MPPS type Button
| In PART ONE I wrote: |
A regular GUI Button is a 3D object. That is, the Button is displayed projected (in default state) and looks sunken when depressed. The GUI Button remains sunken until you release the Mouse Button ( gLabel will not be executed unless the mouse button is released).
|
PART 1 dealt with the techniques in creating a Graphical Button / Graphical Checkbox and
we know that a Push button has two states : ON and OFF. Both the examples posted were
calling Subroutine1 which we could use as a Toggle switch.
In this PART, I am posting the resultant code of my experiment to simulate a third state.
The code demonstrates the detection of Button-Press duration of a Graphical button.
In simple terms:
- a Normal Mouse click on the Graphical button will be used to toggle a variable ( calls Subroutine1 ) , and
- a Long Mouse click on the Graphical button will trigger a special routine ( calls Subroutine2 ).
| Code: | ; MPPS_Type_Button.ahk
;#InstallMouseHook
/*
- A Normal Click on the Graphical button will call Subroutine0
- A Long Click (Keep the "Left Mouse Button" down on the graphical button
for 1 second) will trigger Subroutine1
*/
Gui, +Sysmenu +ToolWindow +AlwaysOnTop
Gui, Margin,12,12
Gui, Add , Picture, x13 y13 w32 h32 E0x200 vState1 icon1 gMPPS_Type_Button, %A_AhkPath%
Gui, Add , Picture, x13 y13 w34 h34 Border vState0 icon1 gMPPS_Type_Button, %A_AhkPath%
Gui, Show, x50 y50 AutoSize, MPPS
Return
MPPS_Type_Button:
GuiControl Hide, State0
TC := A_TickCount
Loop, {
MouseDown:=GetKeyState("LButton","P")
If (!MouseDown) {
LongClick=0
Break
}
If (A_TickCount-TC) > 1000 {
LongClick=1
Break
}
}
GuiControl Show, State0
IfEqual,LongClick,1,GoSub,SubRoutine1
else GoSub, SubRoutine0
Return
SubRoutine1:
Msgbox,64, Subroutine1
,That was a Long Click..`n`nThis Subroutine may be used to execute a Special task, 10
Return
SubRoutine0:
Msgbox,64, Subroutine0
,That was a Normal Click..`n`nThis Subroutine may be used to Toggle a Variable, 10
Return
GuiEscape:
GuiClose:
ExitApp
Return |
- MPPS type button requires Mouse Hook (Windows NT/2000/XP or later)
| Quote: | MPPS in MPPS type button stands for
Mobile Phone Power Switch
The Acronym that came to my mind when I applied the concept to a Graphical Button.
I do not know about international preferences for Mobiles,
but in India, 80% of the Mobiles are from Nokia and the function of its Power button is like follows:-
- A Long press switches it ON
and when ON
- A Short press will show a Confirmation menu to switch it off
- A Long press will switch it Off without confirmation.
I have mimicked this functionality for the Graphic Button. |
Visit the following post for a Utility based on this concept.
Crazy Scripting : Muter v1.0 ( MPPS type Button )
|
Credits: Post by PhiLho @ Ask for Help Topic: Picture buttons.... by jsmain
Regards,
PS: Feedback please!
Last edited by SKAN on Mon Jun 16, 2008 7:28 am; edited 7 times in total |
|
| Back to top |
|
 |
PhiLho
Joined: 27 Dec 2005 Posts: 6721 Location: France (near Paris)
|
Posted: Sun May 14, 2006 12:45 pm Post subject: |
|
|
What is MPPS?
I tested the code in the first part, it is excellent! I like the sunken effect done without using two pictures. Very good idea!
The second part I will test later, because I think it won't work on Win98 (I am on my old computer right now). _________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2") |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 5882
|
Posted: Sun May 14, 2006 1:13 pm Post subject: |
|
|
Dear PhiLho,
| You wrote: | | I tested the code in the first part, it is excellent! I like the sunken effect done without using two pictures. Very good idea! |
Thanks! . I did refer your post http://www.autohotkey.com/forum/viewtopic.php?p=52707#52707
and forgot to give credit. (It took me more than 5 hours to compile this post, and it slipped off my mind!).
Now, I have edited the post & have given the credit.
| You wrote: | | The second part I will test later, because I think it won't work on Win98 (I am on my old computer right now). |
I await your valuable opinion on the MPPS type Button.
Regards, 
Last edited by SKAN on Mon Jun 16, 2008 7:29 am; edited 1 time in total |
|
| Back to top |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 4015 Location: Pittsburgh
|
Posted: Sun May 14, 2006 6:23 pm Post subject: |
|
|
| You can simulate button up/down effects also with GroupBoxes. |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 5882
|
Posted: Sun May 14, 2006 6:45 pm Post subject: |
|
|
Dear Laszlo,
How to Create a Vertical / Horizontal line in a GUI ?
That was my long standing question. I did not want Bump that topic because it was posted in "Wish List".
So I post my Thanks here.
I would have never imagined that the font size could be less than "8".
Regards,  _________________ SKAN - Suresh Kumar A N
Last edited by SKAN on Sun May 14, 2006 7:38 pm; edited 1 time in total |
|
| Back to top |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 4015 Location: Pittsburgh
|
Posted: Sun May 14, 2006 7:25 pm Post subject: |
|
|
| Vertical and horizontal lines can be drawn also with SplashImage, although they are not part of a Gui. If you want them moveable with your Gui, you have to dock them. And, of course, you can always create an empty, narrow Gui, without caption. Its border provides the lines. Inside a GUI, other narrow controls work, too, but GroupBoxes looked the simplest. |
|
| Back to top |
|
 |
PhiLho
Joined: 27 Dec 2005 Posts: 6721 Location: France (near Paris)
|
Posted: Mon May 15, 2006 9:18 am Post subject: |
|
|
| Goyyah wrote: | I await your valuable opinion on the MPPS type Button.  | Not much to say, it offers an interesting functionnality, and it works well. I still don't know what is MPPS...
Note on lines: you can make them with a Picture element, using a one pixel image (or 2/3 pixels for shadow effects). I still have to study how to use an image defined in the script without writing it to disk.
Side-note: I think this topic belongs more to the Scripts & Functions section, this one is for topics slightly outside AHK's realm (external utilities that can be used with AutoHotkey). What do you think? _________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2") |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 5882
|
Posted: Mon May 15, 2006 10:06 am Post subject: |
|
|
Dear PhiLho,
| You wrote: | | Not much to say, it offers an interesting functionnality, and it works well. I still don't know what is MPPS... |
. I have particularly not replied it - means there is an Unread PM lying in your inbox
| You wrote: | | Note on lines: you can make them with a Picture element, using a one pixel image (or 2/3 pixels for shadow effects). I still have to study how to use an image defined in the script without writing it to disk. |
I am aware of that technique.
| You wrote: | | I think this topic belongs more to the Scripts & Functions section, this one is for topics slightly outside AHK's realm (external utilities that can be used with AutoHotkey). What do you think? |
| Quote: | Ask for Help
Ask questions and (hopefully) get answers. Post helpful tips and tricks. |
Or maybe in the above section?
I will have to bump the topic two/three times a day to keep it in the first page.
I am still learning AHK & whenever I come out with interesting things, I want to post it under one topic. And I want this topic to be easily accessible so that it does not get lost in this ocean of posts.
Not everybody can search successfully. Especially, when they cannot put in words of what they have in mind. Don`t you agree?
I leave it to Mr.Chris to decide where this topic should be.
Regards, 
Last edited by SKAN on Mon Jun 16, 2008 7:29 am; edited 2 times in total |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10467
|
Posted: Mon May 15, 2006 1:15 pm Post subject: |
|
|
I've moved it to Scripts & Functions because I think many people do not even visit the Utilities forum (believing it to be somewhat off-topic, which it usually is).
It seems likely to get more viewings here. |
|
| Back to top |
|
 |
PhiLho
Joined: 27 Dec 2005 Posts: 6721 Location: France (near Paris)
|
Posted: Mon May 15, 2006 1:36 pm Post subject: |
|
|
| Goyyah wrote: | | You wrote: | | Not much to say, it offers an interesting functionnality, and it works well. I still don't know what is MPPS... |
. I have particularly not replied it - means there is an Unread PM lying in your inbox  | ? Oh, you sent a Private Message. I have no access to my private mailbox during the day, and I fail to see the "You have 1 new message" link in the forum.
OK, you made up this abbreviation. But it is fine, you can "disclose it", I think, it is a smart and useful use of graphic buttons. _________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2") |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 5882
|
Posted: Mon May 15, 2006 8:54 pm Post subject: |
|
|
| Chris wrote: | I've moved it to Scripts & Functions because I think many people do not even visit the Utilities forum (believing it to be somewhat off-topic, which it usually is).
It is likely to get more viewings here. |
Thank you Mr.Chris
| PhiLho wrote: | | OK, you made up this abbreviation. But it is fine, you can "disclose it", I think, it is a smart and useful use of graphic buttons. |
Edit: Updated the Original Post.
Regards,  _________________ SKAN - Suresh Kumar A N |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 5882
|
Posted: Tue May 16, 2006 9:46 pm Post subject: |
|
|
| Quote: | How to Draw Lines in a GUI? GuiDrawLine()
http://www.autohotkey.com/forum/viewtopic.php?p=60228#60228
| Quote: | Foreword:
Thanks to Laszlo & PhiLho for invoking
creativity in me. (Please refer the above few posts.)
I hope, someday AHK will have something like:
Gui, Draw, Line,,
Gui, Draw, Box,,
|
GuiDrawLine(X,Y,LineLength,Horizontal,Gui_Instance_Number)
Note: All the 5 parameters are expected as numbers.
- The X Coordinate on the GUI
- The Y Coordinate on the GUI
- The Length of the line
- 0 for Vertical Line and 1 for Horizontal Line.
- GUI Instance Number 1-99
| Code: | GuiDrawLine(X,Y,Size,VH="",Guin="") {
If (Guin="" OR Guin<1 OR Guin>99)
Guin=1
If VH=
VH=1
Size+=4
Gui, %Guin%:Font, S1
if VH
Gui, %Guin%:Add, Text, x%X% y%Y% w%Size% 0x10
Else
Gui, %Guin%:Add, Text, x%X% y%Y% h%Size% 0x11
Gui, %Guin%:Font, S
Return errorlevel
} |
Important Notes:- The lines drawn are Text Control so GUI, Font affects it. The functions sets it to lowest! (Thanks to Laszlo!)
- For example, if the Font size was 14 when GuiDrawLine() was called, it will be reset to Windows Default Font Size.
- You may add line: GUI, Font, s%RequiredFontSize% after calling GuiDrawLine().
- Again, remember that the lines are Text Control and that there is an upper limit to controls. ( 5000+ ?! ).
- I tested a 100 Pixels wide line, and only 96 pixels wide line was drawn.
- To overcome this, I have included the line Size+=4 on the function.
- One should/may modify it ( to suit needs ) if the lines are not in proper size.
| Code: | Gui, 1:+ToolWindow
Gui,1:Margin,0,0
GuiDrawLine(20,20,80)
GuiDrawLine(20,20,80,0)
GuiDrawLine(80, 0,80,0)
GuiDrawLine(0, 80,80)
Gui,1:Show,x10 y10 w100 h100,GUI:1
Gui, 2:+ToolWindow
GuiDrawLine(0,10,100,1,2)
GuiDrawLine(0,90,100,1,2)
GuiDrawLine(10,0,100,0,2)
GuiDrawLine(90,0,100,0,2)
Gui,2:Show,x125 y10 w100 h100,GUI:2
Gui, 3:+ToolWindow
GuiDrawLine(0,33,100,1,3)
GuiDrawLine(0,66,100,1,3)
GuiDrawLine(33,0,100,0,3)
GuiDrawLine(66,0,100,0,3)
Gui,3:Show,x240 y10 w100 h100,GUI:3
Return
; Copy and Paste GuiDrawLine() below |
| Code: | Gui,1:+ToolWindow
Gui,1:Margin,0,0
Gui, 1:Font, s36 Bold , Verdana
Gui, 1:Add, Text, x10 y10 w400, Text Written Before Line Drawing
LineSize=1
y=1
Loop, 65 {
GuiDrawLine(0,Y,LineSize,1,1)
LineSize+=5
y+=6
}
Gui, 1:Font, s36 Bold
Gui, 1:Add, Text, x10 y200 w400 BackgroundTrans, Transparent Text Written After Drawing
Gui,1:Show, ,GUI:1
Return
; Copy and Paste GuiDrawLine() below |
Comments / Suggestions are welcome.
|
Last edited by SKAN on Mon Jun 16, 2008 7:29 am; edited 2 times in total |
|
| Back to top |
|
 |
evl
Joined: 24 Aug 2005 Posts: 1238
|
Posted: Tue May 16, 2006 10:10 pm Post subject: |
|
|
Interesting effect. Now if you want a real challenge you can try to get your head around the line drawing code that shimanov posted a while back (and is used for the window/control highlighting in the AHK Window Info script) - I've been meaning to make a window/control highlighting function, but never enough time
Reminds me of a line-drawing 3D first person shooting game that I played a few times on my old TI-85 graphics calculator If it can be done on a calculator with a few MHz of processing power it's only a matter of time before it's done in AHK  |
|
| Back to top |
|
 |
Veovis
Joined: 13 Feb 2006 Posts: 390 Location: Utah
|
Posted: Tue May 16, 2006 10:33 pm Post subject: |
|
|
Nice Work! I remember reading a post in which groupboxes where used draw boxes and lines, and i couldnt get it to work. This works perfectly! Your TipsNTricks continue to amaze me! Keep up the good work! _________________
"Power can be given overnight, but responsibility must be taught. Long years go into its making." |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|