AutoHotkey Community

It is currently May 27th, 2012, 5:55 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 17 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: September 12th, 2010, 9:36 pm 
Offline

Joined: July 25th, 2010, 11:36 pm
Posts: 154
I can't upload images and don't have a website to link, so you will have to furnish your own. Images: Background w172 h101; 12 buttons w22 h22 (6 for down and 6 for up positions); 1 w12 h12 for close. Leave any questions and I will check back later.
Code:
#NoTrayIcon
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetBatchLines, -1

   IniRead, left, Options.ini, Position, left
   IniRead, top,  Options.ini, Position, top

Gui, Font, s9, Tahoma
Gui, Add, Picture, x0 y0, Images\BG.png

Gui, Add, Text, xm25 ym0  cWhite center BackgroundTrans, Select a button...
Gui, Add, Picture, xm-2   ym+25 gShutdown  vButShutDown, Images\ShutDownUp.png
Gui, Add, Picture, xm+25  ym+25 gRestart   vButRestart, Images\RestartUp.png
Gui, Add, Picture, xm+52  ym+25 gLogOff    vButLogOff, Images\LogOffUp.png
Gui, Add, Picture, xm+79  ym+25 gLockPC    vButLockPC, Images\LockPCUp.png
Gui, Add, Picture, xm+106 ym+25 gSuspend   vButSuspend, Images\SuspendUP.png
Gui, Add, Picture, xm+133 ym+25 gHibernate vButHibernateUp, Images\HibernateUP.png
Gui, Add, Text,    xm+0   ym+50 w140 r2 cWhite center BackgroundTrans, Clock
Gui, Add, Picture, xm+144   ym+1  gClose     vButClose, Images\Close.png
Gui, -Caption +ToolWindow
Gui, Show, x%left% y%top% w172 h101, Power Options
;WinSet, Region, 0-0 172-0 172-95 0-95 w172 h101 r20-20, Power Options ;Set the color black as transparent

OnMessage(0x112, "WM_SYSCOMMAND")
OnMessage(0x200, "WM_MOUSEMOVE") ; add this line in the auto-execute section
OnMessage(0x201, "WM_LBUTTONDOWN") ; add this line in the auto-execute section

;#Persistent
settimer, update, 1000
   Gosub Update

; Intercept Win+D are pressed to minimize the desktop.
#d::
   Send, {LWin down}{d}   ; Force Win+D after inteception.
   Send, {LWin up}{d}      ; Restore LWin in up posiiton.
   Sleep, 50   ; Required to allow desktop to be minimized.
   WinActivate, Power Options   ; Restore window immediately.
Return

Update:
   FormatTime, var, , MMM. dd,yyyy HH:mm:ss
   GuiControl,,Static9, % var
Return

WM_LBUTTONDOWN(wParam, lParam)
{
   If !A_GuiControl   ; Enable window dragging.
      PostMessage, 0xA1, 2 ; 0xA1 = WM_NCLBUTTONDOWN Does not work on clickable control.
   WinGetPos, left, top, , , Power Options   ; Track position of window and
   IniWrite, %left%, Options.ini, Position, left   ; save for next time
   IniWrite, %top%, Options.ini, Position, top   ; it is opened.
}

; Set message at top of window and change cursor.
WM_MOUSEMOVE()
{   hCursor := DllCall("LoadCursor", "Uint", NULL, "Int", 32649, "Uint")
   oldCursor := DllCall("SetCursor", "uint", hCursor)
   MouseGetPos, , , , ctrl
   If ctrl = Static3
      GuiControl,, Static2, Shutdown
   Else If ctrl = Static4
      GuiControl,, Static2, Restart
   Else If ctrl = Static5
      GuiControl,, Static2, Log Off
   Else If ctrl = Static6
      GuiControl,, Static2, Lock PC
   Else If ctrl = Static7
      GuiControl,, Static2, Suspend (Sleep)
   Else If ctrl = Static8
      GuiControl,, Static2, Hibernate
   Else
   {
      sleep, 100
      GuiControl,, Static2, Select a button...
      DllCall("SetCursor", "uint", oldCursor)

   }
   If ctrl = Static10
      tooltip, Close
   Else
      Tooltip
   sleep, 10

}

; First 3 options will clear all programs so a message box is needed.
Shutdown:
   GuiControl, , ButShutDown, Images\ShutDownDn.png
    KeyWait, LButton, U
   GuiControl, , ButShutDown, Images\ShutDownUp.png
   MsgBox, 36,, Shutdown computer? (press Yes or No)
   IfMsgBox Yes
      Run, Shutdown.exe /p   ; Shutdown
Return

Restart:
   GuiControl, , ButRestart, Images\RestartDn.png
    KeyWait, LButton, U
   GuiControl, , ButRestart, Images\RestartUp.png
   MsgBox, 36,, Restart computer? (press Yes or No)
   IfMsgBox Yes
      Run, shutdown.exe -r -t 0 -f   ; Restart
Return

LogOff:
   GuiControl, , ButLogOff, Images\LogOffDn.png
    KeyWait, LButton, U
   GuiControl, , ButLogOff, Images\LogOffUp.png
   MsgBox, 36,, Log off computer? (press Yes or No)
   IfMsgBox Yes
      Run, Shutdown.exe /l   ; Logoff
Return

LockPC:
   GuiControl, , ButLockPC, Images\LockPCDn.png
    KeyWait, LButton, U
   GuiControl, , ButLockPC, Images\LockPCUp.png
   Run rundll32 user32.dll LockWorkStation
Return


Suspend:
   GuiControl, , ButSuspend, Images\SuspendDn.png
    KeyWait, LButton, U
   GuiControl, , ButSuspend, Images\SuspendUp.png
   DllCall("PowrProf\SetSuspendState", "int", 0, "int", 0, "int", 0)Return
Return

Hibernate:
   GuiControl, , ButHibernate, Images\HibernateDn.png
    KeyWait, LButton, U
   GuiControl, , ButHibernate, Images\HibernateUp.png
   DllCall("PowrProf\SetSuspendState", "int", 1, "int", 0, "int", 0)Return
Return

Close:

GuiClose:
ExitApp


Report this post
Top
 Profile  
Reply with quote  
PostPosted: September 12th, 2010, 11:34 pm 
Online

Joined: September 15th, 2009, 1:14 am
Posts: 562
Location: Tempe, Arizona
Why not use autohotkey.net?
It's free, you just need to register.
Please upload the images there so we can see a working product without having to do the work (I'm lazy).


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 12th, 2010, 11:50 pm 
Offline

Joined: January 2nd, 2008, 4:47 am
Posts: 150
Location: Freenode IRC
Quote:
DllCall("PowrProf\SetSuspendState", "int", 0, "int", 0, "int", 0)Return

Your usage of Return is quite incorrect. Return should appear alone on a line of its own.

Quote:
Run, Shutdown.exe /p ; Shutdown

You should use the Shutdown command instead.
Shutdown, n ; Logoff 0, Shutdown 1, Reboot 2, Force 4, Power off 8

Quote:
Run rundll32 user32.dll LockWorkStation

DllCall("LockWorkStation")

_________________
Image

Need help right away? Get live support on IRC.
Already have an IRC client installed? /join #ahk


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 13th, 2010, 1:21 am 
Offline

Joined: July 25th, 2010, 11:36 pm
Posts: 154
codybear I uploaded the files to AutoHotKey.net, but I don't have any idea how to create a link to them.

Raccoon
Quote:
DllCall("PowrProf\SetSuspendState", "int", 0, "int", 0, "int", 0)Return
I didn't check the paste to the site and this was an error on my part.

Quote:
Run, Shutdown.exe /p ; Shutdown
I don't know what version of windows you are running, but this came from 7 and is correct along with all of the other values in the program. There are some values for Shutdown that will not work on some models because of the firmware, that is why I used what I did.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 13th, 2010, 1:36 am 
Offline

Joined: July 25th, 2010, 11:36 pm
Posts: 154
ok, here is the link to the files: http://www.autohotkey.net/~nothere2/PowerOptions.zip


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 13th, 2010, 2:03 am 
Online

Joined: September 15th, 2009, 1:14 am
Posts: 562
Location: Tempe, Arizona
nothere wrote:
ok, here is the link to the files: http://www.autohotkey.net/~nothere2/PowerOptions.zip

Sweet, looks good.
Thanks for sharing!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 13th, 2010, 3:21 am 
Offline

Joined: January 2nd, 2008, 4:47 am
Posts: 150
Location: Freenode IRC
nothere wrote:
I don't know what version of windows you are running, but this came from 7 and is correct along with all of the other values in the program. There are some values for Shutdown that will not work on some models because of the firmware, that is why I used what I did.


I think you're missing the point. And that point is AutoHotkey has a built in Shutdown command which uses the legal, appropriate, and recognized shutdown API.

Code:
Shutdown, 9
for instance, to shut down the computer.

_________________
Image

Need help right away? Get live support on IRC.
Already have an IRC client installed? /join #ahk


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 13th, 2010, 1:36 pm 
Offline

Joined: July 25th, 2010, 11:36 pm
Posts: 154
Raccoon, I appreciate the advice. Force is not an option that I would ever use in a program, it can mess up an operating system. MS has been known to write back code to their programs during operations of the system. If this code is traped with a force, it will be saved and "can" cause unknown problems on bootup. Suspend/Hibernate are shown as DLL solutions. That leaves 4 functions which AutoHotKey has to point at the operating system internally, I just took the short cut to speed up the program a little - same amount of code.

BTW: The help file shows a link to Suspend/Hibernate under Shutdown that does not exist.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 13th, 2010, 6:51 pm 
Offline

Joined: January 2nd, 2008, 4:47 am
Posts: 150
Location: Freenode IRC
nothere wrote:
Raccoon, I appreciate the advice. Force is not an option that I would ever use in a program.

I didn't suggest you use the force option. I'm just stating that the built-in Shutdown command is better than calling an .exe file that doesn't exist in every flavor of windows. The Shutdown command on the other hand is compatible with all flavors of Windows from 95 to 7, and uses the same method as your shutdown.exe file.

nothere wrote:
BTW: The help file shows a link to Suspend/Hibernate under Shutdown that does not exist.

There is no "link" in the help file. I don't know what you are referring to.

_________________
Image

Need help right away? Get live support on IRC.
Already have an IRC client installed? /join #ahk


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 13th, 2010, 9:51 pm 
Offline

Joined: May 2nd, 2006, 11:16 pm
Posts: 800
Location: Greeley, CO
The ZIP file comes down as "Corrupted";
I've tried multiple times in multiple browsers;
Any suggestions?

[edit] Disregard;
Tried another PC and download came down fine.

_________________
Image
SoggyDog
Dwarf Fortress:
"The most intriguing game I've ever played."


Last edited by SoggyDog on September 13th, 2010, 9:58 pm, edited 3 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 13th, 2010, 9:54 pm 
Offline

Joined: July 25th, 2010, 11:36 pm
Posts: 154
Raccoon,
I am starting to wonder why you are so infatic about me using Shutdown rather than a call to the API; please explain...

I did make a mistake with your help file, but not about the link. Here is your help file:
Quote:
Logoff 0
Shutdown 1
Reboot 2
Force 4
Power down 8
Suspend/Hibernate See DllCall example at the bottom of this page.
This is shown as a link. The version of AutoHotKey is: 1.0.48.05 - September 25, 2009. I must have scrolled to the bottom of the short page when I pressed the link and nothing happened - it does worlk


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 13th, 2010, 10:25 pm 
Offline

Joined: January 2nd, 2008, 4:47 am
Posts: 150
Location: Freenode IRC
I'm not being emphatic about anything. I'm merely pointing out inconsistencies in your script.

For shutdown, your script is using "Run, Shutdown.exe /p". this shutdown.exe does not exist on all versions of windows. You call this "using API" but it's not, you are using an "external process" which may or may not exist.

The built-in Shutdown command uses the API, which is DllCall("ExitWindowsEx", ...) along with the appropriate system token privilege requests. Basically, your "shutdown.exe" is built right-into AutoHotkey, so why depend on an exterior process (that doesn't exist on everyone's computer).

The same thing with your call to "Run rundll32 user32.dll LockWorkStation". This is silly. AutoHotkey's built-in DllCall() function negates the need to externally execute "Run rundll32" which is subject to permission failure.

If you like, I can stop helping you all together.

_________________
Image

Need help right away? Get live support on IRC.
Already have an IRC client installed? /join #ahk


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 13th, 2010, 10:35 pm 
Offline

Joined: July 25th, 2010, 11:36 pm
Posts: 154
No comment!!!


Report this post
Top
 Profile  
Reply with quote  
PostPosted: September 13th, 2010, 10:47 pm 
Offline

Joined: January 2nd, 2008, 4:47 am
Posts: 150
Location: Freenode IRC
Since this is topical, and someone just asked me this question on IRC. I tested the Shutdown command with each possible value, in Windows XP.

Code:
Red = unique behavior. (use these values)

; Shutdown, n
; Logoff = 0, Shutdown = 1, Reboot = 2, Force = 4, Power down = 8

Shutdown,  0  ; Logs out user. (0)
Shutdown,  1  ; Shuts down and powers off. (1)
Shutdown,  2  ; Shuts down and reboots. (2)
Shutdown,  3  ; Shuts down and reboots. (2+1)
Shutdown,  4  ; Applications are closed forcefully. Logs out user. (4+0)
Shutdown,  5  ; Applications are closed forcefully. Shuts down and powers off. (4+1)
Shutdown,  6  ; Applications are closed forcefully. Shuts down and reboots. (4+2)
Shutdown,  7  ; Applications are closed forcefully. Shuts down and reboots. (4+2+1)
; (... expand for more)
Shutdown,  8  ; Shuts down and powers off. (8)
Shutdown,  9  ; Shuts down and powers off. (8+1)
Shutdown, 10  ; Shuts down and powers off. (8+2)   (Reboot flag is ignored.)
Shutdown, 11  ; Shuts down and powers off. (8+2+1) (Reboot flag is ignored.)
Shutdown, 12  ; Applications are closed forcefully. Shuts down and powers off. (8+4)
Shutdown, 13  ; Applications are closed forcefully. Shuts down and powers off. (8+4+1)
Shutdown, 14  ; Applications are closed forcefully. Shuts down and powers off. (8+4+2)   (Reboot flag is ignored.)
Shutdown, 15  ; Applications are closed forcefully. Shuts down and powers off. (8+4+2+1) (Reboot flag is ignored.)
Shutdown, 16  ; No such flag. Just Logs out user. (0)

Note: the Power down = 8 flag is likely only useful on Windows 9x, since Shutdown = 1 flag automatically powers down the computer on 2K, XP, Vista, Se7en.

Raccoon

_________________
Image

Need help right away? Get live support on IRC.
Already have an IRC client installed? /join #ahk


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 13th, 2010, 11:05 pm 
Offline

Joined: July 25th, 2010, 11:36 pm
Posts: 154
ok,


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 17 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Apollo, Exabot [Bot], Google Feedfetcher, JamixZol and 23 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