Jump to content
DoofGore

GUI Stay on Top ON OFF Button

Recommended Posts

DoofGore

Hello All, My first post I know this is pretty noobish but I'm trying to find a way to make this gui working.. searched but as I'm new to autoit I don't understand much... 

I want to make this gui on top if we press ON TOP button and off on top function when we press on top off.. Created gui with koda ... any help would be appreciated 

Regards,

 

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
Global $Form1 = GUICreate("Form1", 353, 209, 192, 114)
Global $ONTOPON = GUICtrlCreateButton("ON TOP ON", 32, 40, 137, 65)
Global $exit = GUICtrlCreateButton("EXIT", 105, 118, 137, 65)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
Global $ONTOPOFF = GUICtrlCreateButton("ON TOP OFF", 184, 41, 137, 65)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $ONTOPON

        Case $ONTOPOFF

        Case $exit
            Exit


    EndSwitch
WEnd

 

ontop.jpg

Share this post


Link to post
Share on other sites
Melba23

DoofGore,

WinSetOnTop should be the solution for which you are looking.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
DoofGore

Hello Melba23 I am playing around with WinSetOnTop but i didn't really understand it... it would be great if someone just explain how this is gona work.. Sorry for this noobish post..

Share this post


Link to post
Share on other sites
JLogan3o13

@DoofGore Did you read the help file entry for WinSetOnTop? It explains what it does pretty simply. Where exactly are you confused?


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
DoofGore
1 minute ago, JLogan3o13 said:

@DoofGore Did you read the help file entry for WinSetOnTop? It explains what it does pretty simply. Where exactly are you confused?

I am confused how to write this function to set the gui on top on button click : Can you please provide some examples? So I can learn it how to make this function work.. Thanks

Share this post


Link to post
Share on other sites
Bilgus

UH there is an example in the helpfile?

https://www.autoitscript.com/autoit3/docs/functions/WinSetOnTop.htm

;Example
#include <AutoItConstants.au3>

Example()

Func Example()
    ; Retrieve the handle of the active window.
    Local $hWnd = WinGetHandle("[ACTIVE]")

    ; Set the active window as being ontop using the handle returned by WinGetHandle.
    WinSetOnTop($hWnd, "", $WINDOWS_ONTOP)

    ; Wait for 2 seconds to display the change.
    Sleep(2000)

    ; Remove the "topmost" state from the active window.
    WinSetOnTop($hWnd, "", $WINDOWS_NOONTOP)
EndFunc   ;==>Example
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
Global $Form1 = GUICreate("Form1", 353, 209, 192, 114)
Global $ONTOPON = GUICtrlCreateButton("ON TOP ON", 32, 40, 137, 65)
Global $exit = GUICtrlCreateButton("EXIT", 105, 118, 137, 65)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
Global $ONTOPOFF = GUICtrlCreateButton("ON TOP OFF", 184, 41, 137, 65)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $ONTOPON
            Example($Form1, True)
        Case $ONTOPOFF
            Example($Form1, False)
        Case $exit
            Exit


    EndSwitch
WEnd


Func Example($hWnd, $bTrue)
    
    If Not IsHwnd($hWnd) Then Msgbox(0,"Error" "Invalid hWnd")
    If $bTrue Then
        ; Set the active window as being ontop using the handle YOU supply.
        WinSetOnTop($hWnd, "", $WINDOWS_ONTOP)
    Else
        ; Remove the "topmost" state from the handle YOU supply.
        WinSetOnTop($hWnd, "", $WINDOWS_NOONTOP)
    EndIF
EndFunc   ;==>Example
#include <AutoItConstants.au3>
    
    If Not IsHwnd($hWnd) Then Msgbox(0,"Error", "Invalid hWnd")

 

Edited by Bilgus
Couple Errors..
  • Thanks 1

Share this post


Link to post
Share on other sites
DoofGore

@Bilgus Thank you so much .... This is what i was asking for .. will give it a try now... 

Share this post


Link to post
Share on other sites
DoofGore

Made Some changes and its working..  Thank you so much ... :) 

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
#include <AutoItConstants.au3>
#Region ### START Koda GUI section ### Form=
Global $Form1 = GUICreate("Form1", 353, 209, 192, 114)
Global $ONTOPON = GUICtrlCreateButton("ON TOP ON", 32, 40, 137, 65)
Global $exit = GUICtrlCreateButton("EXIT", 105, 118, 137, 65)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
Global $ONTOPOFF = GUICtrlCreateButton("ON TOP OFF", 184, 41, 137, 65)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $ONTOPON
            Example($Form1, True)
        Case $ONTOPOFF
            Example($Form1, False)
        Case $exit
            Exit


    EndSwitch
WEnd


Func Example($Form1, $bTrue)
    ; Retrieve the handle of the active window.
    Local $hWnd = WinGetHandle("[ACTIVE]")
    If $bTrue Then
        ; Set the active window as being ontop using the handle returned by WinGetHandle.
        WinSetOnTop($hWnd, "", $WINDOWS_ONTOP)
    Else
        ; Wait for 2 seconds to display the change.
        Sleep(2000)

        ; Remove the "topmost" state from the active window.
        WinSetOnTop($hWnd, "", $WINDOWS_NOONTOP)
    EndIf
EndFunc   ;==>Example

 

Edited by DoofGore

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

  • Similar Content

    • XinYoung
      By XinYoung
      For fun, I'm building an app that opens a webpage and refreshes it every 30 seconds.
      But once the script performs _IEAction($oIE, "refresh"), the GUI closes.
      Any help is appreciated.
       

      #include <ButtonConstants.au3>
      #include <EditConstants.au3>
      #include <GUIConstantsEx.au3>
      #include <StaticConstants.au3>
      #include <WindowsConstants.au3>
      #include <WinAPIFiles.au3>
      #include <Array.au3>
      #include <File.au3>
      #include <Excel.au3>
      #include <DateTimeConstants.au3>
      #include <MsgBoxConstants.au3>
      #include <WinAPIShellEx.au3>
      #include <MsgBoxConstants.au3>
      #include <Date.au3>
      #include <ComboConstants.au3>
      #include <guimenu.au3>
      #include <IE.au3>
      HotKeySet("{F4}", "_Exit")
      ;Open the file(s) in the selected folder
      $extension = ".txt"
      $app2openWith = @SystemDir & "\notepad.exe"
      Func Begin()
          Global $loopTrick = 0
          #Region ### START Koda GUI section ### Form=c:\users\mchu\downloads\autoit\my code\form1.kxf
          Global $UI = GUICreate("Hit Em Up!", 256, 113, -1, -1)
          GUISetBkColor(0x000000)
          $menu = _GUICtrlMenu_GetSystemMenu($UI)
          _GUICtrlMenu_EnableMenuItem($menu, $SC_CLOSE, 1, False)
          Global $url = GUICtrlCreateInput("https://www.youtube.com/watch?v=dQw4w9WgXcQ", 81, 8, 160, 21)
          $Label1 = GUICtrlCreateLabel("Target:", 16, 8, 55, 17)
          GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
          GUICtrlSetColor(-1, 0x00FF00)
          Global $StartBut = GUICtrlCreateButton("Start", 16, 40, 67, 25)
          GUICtrlSetFont(-1, 13, 800, 0, "MS Sans Serif")
          GUICtrlSetBkColor(-1, 0x008000)
          $Label2 = GUICtrlCreateLabel("(Press F4 to Exit)", 96, 40, 8000, 17)
          GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
          GUICtrlSetColor(-1, 0x00FF00)
          GUISetState(@SW_SHOW)
          #EndRegion ### END Koda GUI section ###
          While 1
              $UIfunc = GUIGetMsg()
              Select
                  Case $UIfunc = $GUI_EVENT_CLOSE
                      _Exit()
                  Case $UIfunc = $StartBut
                      If GUICtrlRead($url) = "" Then
                          MsgBox(48, "Um...", "Give me a target you idiot.")
                      Else
                          GUICtrlSetState($url, $GUI_DISABLE)
                          GUICtrlSetState($StartBut, $GUI_DISABLE)
                          Start()
                      EndIf
              EndSelect
          WEnd
      EndFunc   ;==>Begin
      Func Start()
          If $loopTrick = 0 Then
              Global $oIE = _IECreate(GUICtrlRead($url))
              _IELoadWait($oIE)
              Again()
          ElseIf $loopTrick = 1 Then
              Sleep(3000)
              _IEAction($oIE, "refresh")
              Sleep(3000)
              Start()
          EndIf
      EndFunc   ;==>Start
      Func Again()
          $loopTrick = 1
          Start()
      EndFunc   ;==>Again
      Func _Exit()
          Exit
      EndFunc   ;==>_Exit
    • kcvinu
      By kcvinu
      Hi all,
      I have a button created with _GUICtrlButton_Create function. I know that this function returns a handle of button instead of an ID. So i have obtain control ID by calling _WinAPI_GetDlgCtrlID function. After that i have tried the GUICtrlSetBkColor function. But it didnt worked. Any suggestions will be appreciated. Thanks in advance. 
      Note : - The window which carries this button is not created with native gui create function. Instead, it is created with CreateWindowEx api function.
    • kcvinu
      By kcvinu
      Hi all,
      I am playing with _GUICtrlButton_Create function. How can i change this button's (or the entire form's) font ?. The in-built GUICtrlSetFont function is not working even when i convert the control handle to control ID with _WinAPI_GetDlgCtrlID ( ) function.  Do i need to use CreateFont api finction and send WM_SETFONT message ? Or is there any other easy and safe ways to do this ?. Thanks in advance.
      Note : This window is created by CreateWindowEx function, not by GUICreate function. 
    • Jake_s
      By Jake_s
      Hi All, 
       
      I am a begginer in auto it. I am trying to build simple gui that will show me if for example notepad.exe process is currently running on the system. I have built something like this, but when I execute it shows me message boxes, but I want the results to show in gui. If you can help me start with this.
       
      Thanks
       
        #include <MsgBoxConstants.au3>
      #include <GUIConstantsEx.au3>

      ActiveProcess()

      Func ActiveProcess()
      GUICreate("Act")
               ProcessExists("wuauclt.exe")

             If ProcessExists("wuauclt.exe") Then
       MsgBox($MB_SYSTEMMODAL, "", "Windows Upates are running")
           Else
       MsgBox($MB_SYSTEMMODAL, "", "Windows Updates are not running")
       EndIf
         ;Notepad

               ProcessExists("notepad.exe")

               If ProcessExists("notepad.exe") Then
      MsgBox($MB_SYSTEMMODAL, "", "Notepad is running")
              Else
      MsgBox($MB_SYSTEMMODAL, "", "Notepad is not running")
      EndIf  
       
×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.