Sign in to follow this  
Followers 0
computergroove

Can I make a hovering button that runs a macro?

7 posts in this topic

I have a project where I want to make a small button in the corner of the screen (1.5 inches by 1.5 inches) that always sits on top of other programs and when I click the button I want it to make another program active. I need the button to only show a picture that I have so no borders or title bars. Can I do this in autoit?


Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Share this post


Link to post
Share on other sites



You could use a gui with the $WS_POPUP parameter, so you'd have no title bar or borders. Use GUICtrlCreatePic to set a picture to fill the area of the GUI, and then use the picture as a if it were a button by using GUICtrlSetOnEvent to fire off the function you want to run. To keep the window on top, you'd use GUICtrlSetState ( controlID, $GUI_ONTOP). Hope that points you in the right direction.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

You could use a gui with the $WS_POPUP parameter, so you'd have no title bar or borders. Use GUICtrlCreatePic to set a picture to fill the area of the GUI, and then use the picture as a if it were a button by using GUICtrlSetOnEvent to fire off the function you want to run. To keep the window on top, you'd use GUICtrlSetState ( controlID, $GUI_ONTOP). Hope that points you in the right direction.

OK, I tried the following:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)

Example2()

Func Example2()
    Local $gui, $background, $pic, $basti_stay, $msg
    Local $sFile = "..\GUI\MACFinal200x180.gif"

    $gui = GUICreate("Background", 400, 100)
    ; background picture
    $background = GUICtrlCreatePic("..\GUI\MACFinal200x180.jpg", 0, 0, 400, 100)

    GUISetState(@SW_SHOW)

    ; transparent MDI child window
    $pic = GUICreate("", 169, 68, 20, 20, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $gui)
    ; transparent pic
    $basti_stay = GUICtrlCreatePic($sFile, 0, 0, 169, 68)
    GUISetState(@SW_SHOW)

    Do
        $msg = GUIGetMsg()

    Until $msg = $GUI_EVENT_CLOSE
EndFunc   ;==>Example2

which is actually the exact example from the autoit functions reference online: http://www.autoitscript.com/autoit3/docs/functions/GUICreate.htm only I changed the picture name. The first thing that I notice is that there is a title bar. I tried erasing the "background" name and leaving it blank and also tried just using "" with errors and no luck. The second thing I notice is that there is no picture showing up in the button. I tried renaming the picture name to have no spaces but to no avail. Is GUICreate the function you were talking about?


Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Your first GUI does to have the recomended $WS_POPUP.

Try this:

#include <GUIConstantsEx.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
Local $Button1, $b1label
GUICreate("My GUI Button", 100, 25, @DesktopWidth - 100, 1, $WS_POPUP)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
$Button1 = GUICtrlCreatePic("..\GUI\MACFinal200x180.jpg", -1, -1, 0, 0)
GUICtrlSetState(-1, $GUI_DISABLE)
Opt("GUICoordMode", 2)
$b1label = GUICtrlCreateLabel("Run Notepad", 1, 1, 100, 25, 0x201);Can leave the label as ""
GUICtrlSetBkColor($b1label, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetOnEvent($b1label, "Change")
GUISetState() 
; Run the GUI until the dialog is closed
While 1
    Sleep(11)
WEnd
Func Change()
    Run('Notepad.exe') ; Will Run/Open Notepad
EndFunc   ;==>Change
Func _Exit()
    Exit
EndFunc   ;==>_Exit
Edited by JoHanatCent

Share this post


Link to post
Share on other sites

That was very helpful but I'm still not getting an image on the button. I added $WS_EX_TOPMOST to get the button to stay on top of all other windows. The following:

$Button1 = GUICtrlCreatePic("c:\Program Files\AutoIt3\Examples\GUI\MACFinal200x180.jpg", -1, -1, 0, 0)

appears to misinterpret the file path. I am just guessing as I have tried several things to get it to work. Any suggestions?


Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Share this post


Link to post
Share on other sites

jpg files in that location is working for me.

Is c:\Program Files\AutoIt3\Examples\GUI\MACFinal200x180.jpg valid?

Else post the file here then I can test.


Share this post


Link to post
Share on other sites

Wow I feel stupid. The file was named something else. The above worked. Is there a way to get the picture to auto stretch/shrink to fit the window?

Also I have a picture that is 200x188 pixels (reported in both paint and Photoshop 7) and when I use the following code:

GUICreate("MAC Hovering Button", 200, 188, @DesktopWidth - 188, 1, $WS_POPUP, $WS_EX_TOPMOST)

I get a frame that is too big. Are the 200 and 188 measurements in pixels?


Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0