Sign in to follow this  
Followers 0
johnmcloud

[SOLVED] Button on active window

11 posts in this topic

#1 ·  Posted (edited)

Hi guys,

I'd like to add a simple button on active window. This is what i have done:

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

HotKeySet("{Esc}", "_Exit")

Global $Width = 80
Global $Height = 30

$GUI = GUICreate("Test", $Width, $Height, 0, 0, $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST))
$Button = GUICtrlCreateButton("Button", 0, 0, $Width, $Height)
GUISetState(@SW_SHOW)

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button
MsgBox(0, 0, "Test")
EndSwitch
Move()
WEnd

Func _Exit()
Exit 0
EndFunc ;==>_Exit

Func Move()
Local $size = WinGetPos("[active]")
Local $x = $size[0] + $size[2] - ($Width * 2.5)
Local $y = $size[1]
WinSetOnTop("Test", "", 1)
WinMove($GUI, "", $x, $y)
EndFunc ;==>Move

I have a couple of problem:

1) If no windows is selected, i see a phantom moving button :D you can easily see, just adjust the speed:

WinMove($GUI, "", $x, $y, 80, 30, 100)

I want to see the button only if a active windows exist, not over the desktop

2) The button not work, when you click on it...disappears

Please help me out to improve the script/resolve this problems,

Thanks ;)

EDIT: I have reposted the script, the autoit code have some problem

Edited by johnmcloud

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

UPDATE: New Script:

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

HotKeySet("{Esc}", "_Exit")

Global $Width = 60
Global $Height = 25

$GUI = GUICreate("Test", $Width, $Height, 0, 0, $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST))
$Button = GUICtrlCreateButton("Button", 0, 0, $Width, $Height)
GUISetState(@SW_SHOWNOACTIVATE)

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit
  Case $Button
   MsgBox(0, 0, "Test")
EndSwitch
Move()
WEnd

Func _Exit()
Exit 0
EndFunc   ;==>_Exit

Func Move()
WinSetOnTop("Test", "", 1)
Local $size = WinGetPos("[active]")
Local $name = WinGetTitle("[active]")
Local $x = $size[0] + $size[2] - ($Width * 2.5)
Local $y = $size[1]
If $name <> "Test" Then
  WinMove($GUI, "", $x, $y)
EndIf
EndFunc   ;==>Move

Resolved:

1) Now button work ;)

2) No more phantom button moving

To Resolve:

1) Don't show button on desktop

2) Give to the last active window the focus, it lose

Please if someone know how to improve/resolve post here,

Thanks ;)

Edited by johnmcloud

Share this post


Link to post
Share on other sites

Hi,

It's not perfect, but this is how I would do it (without thinking how I could do it better) :

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

HotKeySet("{ESC}", "_Exit")

Global $Width = 60, $Height = 25, $hLastActiveWnd = -1, $hDesktopWnd = WinGetHandle("[TITLE:Program Manager;CLASS:Progman]")

$GUI = GUICreate("Test", $Width, $Height, 0, 0, $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST))
$Button = GUICtrlCreateButton("Button", 0, 0, $Width, $Height)
GUISetState()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button
            MsgBox(64, "", "Test")
    EndSwitch

    Move()
    Sleep(50)
WEnd

Func _Exit()
    Exit
EndFunc   ;==>_Exit

Func Move()
    Local $hActiveWnd = WinGetHandle("[active]")

    If $hActiveWnd <> $hLastActiveWnd And $hActiveWnd <> $hDesktopWnd Then
        Local $aSize = WinGetClientSize($hActiveWnd)
        If Not IsArray($aSize) Then Return ;Exit Func

        _WinAPI_SetParent($GUI, $hActiveWnd)

        WinMove($GUI, "", $aSize[0] - ($Width * 2.5), 10)

        If Not WinActive($hActiveWnd) Then WinActivate($hActiveWnd)

        $hLastActiveWnd = $hActiveWnd
    EndIf
EndFunc   ;==>Move

Br, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Thanks FireFox, but work wroste then mine, i can't click on the button, if i reduce the size of the window the button will disappear etc..

Thanks for trying, for now i'll tring to make the focus to the previus windows when you click on the button, how to do?

Maybe with WinList() but the help doesn' help me ;)

Edited by johnmcloud

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I suggest you to create the button on every visible window :

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

HotKeySet("{ESC}", "_Exit")

Opt("GUIOnEventMode", 1)

Global $iWidth = 60, $iHeight = 25, $hDesktopWnd = WinGetHandle("[TITLE:Program Manager;CLASS:Progman]")

Global $aWinList = WinList()

For $iWnd = 1 To $aWinList[0][0]
    ; Only display visble windows that have a title
    If $aWinList[$iWnd][0] <> "" And IsVisible($aWinList[$iWnd][1]) Then
        If $aWinList[$iWnd][1] <> $hDesktopWnd Then
            _AttachGUI($aWinList[$iWnd][1])
        EndIf
    EndIf
Next

While 1
    Sleep(1000)
WEnd

Func _Exit()
    Exit
EndFunc   ;==>_Exit

Func _AttachGUI($hWnd)
    Local $aSize = WinGetClientSize($hWnd)
    If Not IsArray($aSize) Then Return ;Exit Func

    $GUI = GUICreate("Test", $iWidth, $iHeight, $aSize[0] - $iWidth - 10, 10, $WS_CHILD, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST), $hWnd)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

    GUICtrlCreateButton("Button", 0, 0, $iWidth, $iHeight)
    GUICtrlSetOnEvent(-1, "_toto")

    GUISetState(@SW_SHOW, $GUI)
    _WinAPI_SetParent($GUI, $hWnd) ;GUICreate parent param does not work on all wnds
EndFunc   ;==>_AttachGUI

Func IsVisible($handle)
    If BitAND(WinGetState($handle), 2) Then
        Return 1
    Else
        Return 0
    EndIf
EndFunc   ;==>IsVisible

Func _toto()
    MsgBox(64, "", "toto")
EndFunc   ;==>_toto

Then you can check for every new wnd (add attached wnds handle into an array)

Edit : You should add the SciTE wnd to the exclude list, it does not work properly (or find another way).

Br, FireFox.

Edited by FireFox

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

My little attempt at your problem

It no longer displays a active button on desktop, taskbar or menu. I only have windows 7 so i donno if it will work on other OS's.

One idea i did have is maybe. On the active-window, u get the style of the window "and if the style is one with a windows border, min, max, close. Then to add your button"

Here is the code for just the desktop problem + improving perfomnce load on cpu.

#Notrayicon ;Makes the script start faster, easier for me to test and i hate tray icons :)
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Array.au3>

local $HandleStore
local $ActiveSizeStore[2]
local $Temp ;This is used to stop it moving the GUI tones, when its not needed. Mostly wasted on good pcs, but i perfer programing with performance in  mind.
local $ArrayOfActiveWindows[1]

$GUI = GUICreate("Test", 60, 25, 0, 0, $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST))
$Button = GUICtrlCreateButton("Button", 0, 0, 60, 25)
GUISetState(@SW_SHOWNOACTIVATE)

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit
Case $Button
   _ArrayDisplay($ArrayOfActiveWindows)
  ; MsgBox(0, 0, "Test")
EndSwitch
Move()
WEnd

Func Move()
$ActiveHandle = WinGetHandle("[Active]")
$ActiveTitle = WinGetTitle($ActiveHandle)
If $ActiveTitle = "Test" or $ActiveTitle = "Start menu" or $ActiveTitle = "Program Manager" or StringRight(WinGetText($ActiveHandle), 21) > "Running applications" Then Return 0 ;Stops It being shown on desktop or taskbar

If Not($HandleStore = $ActiveHandle) Then
   For $i = 0 to ubound($ArrayOfActiveWindows)-1
 If $ArrayOfActiveWindows[$i] = $ActiveHandle then
_ArrayDelete($ArrayOfActiveWindows,$i)
ExitLoop
 EndIf
   Next
   _ArrayAdd($ArrayOfActiveWindows, $ActiveHandle)
WinSetOnTop("Test", "", 1) ;See top comment on why i have done this as wellif
ConsoleWrite("A")
EndIf

$HandleStore = $ActiveHandle 

$ActiveSize = WinGetPos($ActiveHandle)
If IsArray($ActiveSize) Then
   If Not($ActiveSize[0] = $ActiveSizeStore[0]) or Not($ActiveSize[1] = $ActiveSizeStore[1]) Then $Temp = 2
   If $Temp > 0 Then
 WinMove($GUI, "", $ActiveSize[0] + $ActiveSize[2]-150, $ActiveSize[1]) ;I know this looks ulgy, and i did try and better lookink away but it causes "lag" where this is no lag while still being kind 2 the cpu as its only run 3 times per any movement rather then unlimited.
 $Temp -= 1
   EndIf
$ActiveSizeStore = $ActiveSize
EndIf
EndFunc   ;==>Move

**Edit Fixed a small problem by when the button became active, it causes a endless loop of moving the button :>

**Edit Newer version with Array support for rememebring Focus windows (not finished yet, it can only remember not act) still working on it.

Edited by IanN1990

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Nice IanN1990, there is only one problem, the focus didn't come to the previus windows.

On my first script i have add the WinList() and WinActivate() for the focus problem and work fine.

But not work on your. The focus it's the major problem, if example i want to create a "Copy" button ( Send("^c") ) need to do:

1) Click on "copy" button

2) Give focus to the previus window ( ==>_WinPrevious )

3) Send("^c")

With my original script work, but don't know on your script where to add this.

Thanks

EDIT: Solved, i have removed the array part, now work very well. Thanks guys, without your help without you I would not have been able to resolve ;)

Edited by johnmcloud

Share this post


Link to post
Share on other sites

Yea, i was working on the array part but then got called away with family bussniness and didn't get a chance to finish it *which is also why it was only half finished, all it did was record which windows you had been to, and kept your most active windows at the top of the array list" :( I am sry about that but i am glad at lest one part was helpful to you :)

Is there any chance you could post your finished product, as i would like to have a look. I was have thinking of using it on my pc as well.

Share this post


Link to post
Share on other sites

Is there any chance you could post your finished product, as i would like to have a look. I was have thinking of using it on my pc as well.

Sure, why not. I'll post the script when is all completed ;)

Share this post


Link to post
Share on other sites

johnmcloud,

This is all very interesting, but, what is it good for?

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

@John So, were you ever able to get it all finished and polished nicely ?

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

  • Similar Content

    • AppSoftwareVld
      By AppSoftwareVld
      Hello,
       
      I need this for a project and I don't find a method for the next problem.
      I want when I click a button to create a variable ("$variable1") so if I press one more time to create one more ("$variable2") and create more and more how many times you press the button.
       
      Do you have an idea ? 
      Thank you for your attention !
    • Jibberish
      By Jibberish
      Hi,
      I am maybe an intermediate AutoIt script writer, but have no experience creating GUIs.
      I have a script with two functions. One for Checkboxes and another with radio buttons. Each function creates it's own window.
      I'd like to use one window with both checkboxes and radio buttons.
      I pulled samples from AutoIt Help and other places and worked it into this: (RadioCheck still uses the example Case and MsgBoxes. I will clean this up soon)
      Func CheckOptions() ; Create a GUI with various controls. Local $hGUI = GUICreate("SGX4CP Options", 275, 250) ; Create a checkbox control. Local $iLoopCheckbox = GUICtrlCreateCheckbox("Loop", 10, 10, 185, 25) Local $iFullScreenCheckbox = GUICtrlCreateCheckbox("Fullscreen", 10, 40, 185, 25) Local $iRestartPlaybackCheckbox = GUICtrlCreateCheckbox("Restart Playback from Sleep", 10, 70, 185, 25) GUICtrlSetState($iRestartPlaybackCheckbox, $GUI_CHECKED) Local $iDisableSleepCheckbox = GUICtrlCreateCheckbox("Disable Sleep", 10, 100, 185, 25) Local $iLogCheckbox = GUICtrlCreateCheckbox("Show Log", 10, 130, 185, 25) GUICtrlSetState($iLogCheckbox, $GUI_CHECKED) Local $idClose = GUICtrlCreateButton("Next", 110, 220, 85, 25) ; Display the GUI. GUISetState(@SW_SHOW, $hGUI) ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $idClose ExitLoop Case $iLoopCheckbox If _IsChecked($iLoopCheckbox) Then $bLoopChecked = True Else $bLoopChecked = False EndIf Case $iFullScreenCheckbox if _IsChecked($iFullScreenCheckbox) Then $bFullScreenChecked = True Else $bFullScreenChecked = False EndIf Case $iRestartPlaybackCheckbox if _IsChecked($iRestartPlaybackCheckbox) Then $bRestartPlaybackChecked = True Else $bRestartPlaybackChecked = False EndIf Case $iDisableSleepCheckbox if _IsChecked($iDisableSleepCheckbox) Then $bDisableSleepChecked = True Else $bDisableSleepChecked = False EndIf Case $iLogCheckbox if _IsChecked($iLogCheckbox) Then $bLogChecked = True Else $bLogChecked = False EndIf EndSwitch WEnd ; Delete the previous GUI and all controls. GUIDelete($hGUI) EndFunc Func RadioCheck() GUICreate("Select Test",300,180) ; will create a dialog box that when displayed is centered Local $idRadio1 = GUICtrlCreateRadio("Loop Forever", 10, 10) Local $idRadio2 = GUICtrlCreateRadio("Play each video 3 times", 10, 40) Local $idRadio3 = GUICtrlCreateRadio("Play each video separately", 10, 70) GUICtrlSetState($idRadio1, $GUI_CHECKED) Local $idClose = GUICtrlCreateButton("Start Test", 120,100) GUISetState(@SW_SHOW) Local $idMsg ; Loop until the user exits. While 1 $idMsg = GUIGetMsg() Select Case $idMsg = $GUI_EVENT_CLOSE ExitLoop Case $idMsg = $idRadio1 And BitAND(GUICtrlRead($idRadio1), $GUI_CHECKED) = $GUI_CHECKED MsgBox($MB_SYSTEMMODAL, 'Info:', 'The app will run forever, playing each video once, then looping back to the first video.') $bTestSelectForever = True Case $idMsg = $idRadio2 And BitAND(GUICtrlRead($idRadio2), $GUI_CHECKED) = $GUI_CHECKED MsgBox($MB_SYSTEMMODAL, 'Info:', 'Each video will loop 3 times then move to the next video.') $bTestSelect3Times = True Case $idMsg = $idRadio3 And BitAND(GUICtrlRead($idRadio2), $GUI_CHECKED) = $GUI_CHECKED MsgBox($MB_SYSTEMMODAL, 'Info:', 'Player opens, first video plays, player closes. Player opens, second video plays, player closes, etc.') $bTestSelectSingleVideo = True EndSelect WEnd EndFunc I would like to combine the checkbox "Loop" and the radio button $idRadio2. Radio2 requires Loop to be checked.
      I planned to remove the Loop checkbox and only enable it if Radio2 is selected.
      Can I combine these two functions into one with one window with both Checkboxes and Radio Buttons?
      Thanks
      Jibberish
    • rte7
      By rte7
      Hello. We work with the BMC Remedy site to manage incidents and would like to automate the processes of clicking through this button code:
      <a href="javascript:" class="btn btn3d menu" style="top:21; left:184; width:21; height:21;"> <img class="btnimg" src="../../../../resources/images/mt_sprites.gif" alt="menu category issue" title=""> </a> I use firefox with mozrepl and autoit with include FF.au3
      I need your help
      I read the topic https://www.autoitscript.com/forum/topic/95595-ffau3-v0601b-10/ but I could not run the code from the listed commands
      ...
      It is necessary to press the button and from the list of the menu of cahorsations to select the item = "zone of trust abonent"
      Screen # 1 http://joxi.ru/52aJK7bh4a7ypA or below.
      1) Press button
      <a href="javascript:" class="btn btn3d menu" style="top:21; left:184; width:21; height:21;"> <img class="btnimg" src="../../../../resources/images/mt_sprites.gif" alt="menu category issue" title=""> </a>
      2) After pressing the button, I need to choose in this menu of 4 items to select an item called "zone of trust abonent", Screen # 2 - http://joxi.ru/p27gwQKHo71VQ2
      html code table items
      <table class="MenuTable" cellpadding="0" cellspacing="0" style="width: 179px;"> <tbody class="MenuTableBody"> <tr class="MenuTableRow"> <td class="MenuEntryName" nowrap="">zone of trust abonent</td> <td class="MenuEntryNoSub" arvalue="zone of trust abonent"></td> </tr> <tr class="MenuTableRow"><td class="MenuEntryName" nowrap="">zone of trust operator</td> <td class="MenuEntryNoSub" arvalue="zone of trust operator"></td> </tr> <tr class="MenuTableRow"><td class="MenuEntryName" nowrap="">zone of trust third operator</td> <td class="MenuEntryNoSub" arvalue="zone of trust third operator"></td></tr> <tr class="MenuTableRow"><td class="MenuEntryNameHover" nowrap="">No settings</td> <td class="MenuEntryNoSubHover" arvalue="No settings"></td> </tr> </tbody> </table>
       
       
      More in detail, I choose from the menu item "zone of trust abonent" Screen # 3 - http://joxi.ru/GrqVq4ZIQEPW4m

       
      3) The choice is made, Screen # 4 http://joxi.ru/v297w6aC3PovLr
      <textarea class="text sr " wrap="off" id="arid_WIN_0_1000002488" cols="20" maxlen="60" style="top:21; left:0; width:179; height:21;" armenu="CFG:PRC:CategoryHPD-Res-T1-Q" mstyle="2" arautoc="1" arautocmb="1" arautocak="0" arautoctt="400" rows="1"> </textarea>
       
      It's all. I would be very grateful to you =) !!!!!!!!!!
      Here are more detailed codes in the attachment. 
      button1.txt
      menu - table.txt
      all.txt
    • Nareshm
      By Nareshm
      I create message box but i dont know how to add button action when i click it.

      Help for : Add script for Button : Left, Right, Right Finger
      example when i press Left finger button do Case $idNotepad
                      $iPID = WinActivate ( " :PS :: Version - 2.8.0.0  - [eFS Bill]")
                              ControlSend(" :DS  - eF :: Version - 2.8.0.0  - [eF Bill]", "", "[NAME:btnReset]", "{esc}")
                              ControlClick ( " :DS  - eF :: Version - 2.8.0.0  - [eF Bill]", "", "[NAME:txtrdNo]")
                              ControlSend(" :DS  - eF:: Version - 2.8.0.0  - [eF Bill]", "", "[NAME:txtrdNo]", "^v")
                              ControlSend(" :DS  - eF :: Version - 2.8.0.0  - [eF Bill]", "", "[NAME:txtrdNo]", "{enter}")
      How to add like above ?
                    
                                                                sorry for my bad english
       
    • nacerbaaziz
      By nacerbaaziz
      Hi friends, I have a question, please.
      I have created a window containing a edit box
      I need to know how to change the keyboard language,
      e.g :
      if a user open the  script  it will be change the keyBord language   in window automatically into English
      I found more examples but didn't work with me .
      Note:  
       I use the windows 10 os
      Please help me .
      thanks in advance to all
      with my Greetings and my appreciation for all users and admins