Jump to content

Set Chrome OnTop not working


Recommended Posts

objective: get chrome to be the topmost window or chrome is the only visible window on screen

I have a few other windows currently set as OnTop but can't get Chrome to do the same. after call the function bellow, it looks like chrome is activated but not focus unless manually clicked on. Even tried with MouseClick() but it doesn't seem to make a different.

Func _Chome_ActivateOnTop()
    Local $chrome = '[CLASS:Chrome_WidgetWin_1]'
    WinActivate($chrome)
    Local $hwnd = WinWaitActive($chrome, '', 10)
;~     MouseClick('left', 500, 500) ;focus chrome
    WinSetOnTop($hwnd, '',  $WINDOWS_ONTOP)
    WinActivate($hwnd) ;reset top most window
;~     WinSetState($chrome, '', @SW_MAXIMIZE)) ;reset top most window
;~     WinSetState($chrome, '', @SW_ENABLE)) ;reset top most window
    MsgBox(0, @ScriptLineNumber&':'&$hwnd, 'Set OnTop')
EndFunc

also tried  WinMinimizeAll() then WinActivate($chrome) but chrome does not activate at all.

anythoughts? thanks

update: tried with WinList() and extract hwnd does the trick, but any inputs regarding to the issue described above are welcome. If i could avoid WinList() and use class/title directly would be great. it seems WinList() result in a few seconds of delay retrieving those hwnds

Edited by zeenmakr
Link to comment
Share on other sites

in my windows 7  work perferct  your code

#include <AutoItConstants.au3>
  Run("C:\Program Files\Google\Chrome\Application\chrome.exe")

MsgBox(0,'','chrome is up ?')

Local $chrome = '[CLASS:Chrome_WidgetWin_1]'
    WinActivate($chrome)
    Local $hwnd = WinWaitActive($chrome, '', 10)
;~     MouseClick('left', 500, 500) ;focus chrome
    WinSetOnTop($hwnd, '',  $WINDOWS_ONTOP)
    WinActivate($hwnd) ;reset top most window
;~     WinSetState($chrome, '', @SW_MAXIMIZE)) ;reset top most window
;~     WinSetState($chrome, '', @SW_ENABLE)) ;reset top most window
    MsgBox(0, @ScriptLineNumber&':'&$hwnd, 'Set OnTop')

 

Link to comment
Share on other sites

AutoItSetOption("WinTitleMatchMode",2)
WinSetOnTop("Chrome","",1)

@quimao cool, thanks for the pointer

note: without a class id will result in matched if any window contains the word 'Chrome'. here is the update

Func _Chome_ActivateOnTop()
    AutoItSetOption("WinTitleMatchMode",2)
    Local $chrome = '[CLASS:Chrome_WidgetWin_1; TITLE:Google Chrome]'
    WinActivate($chrome)
    Local $hwnd = WinWaitActive($chrome, '', 10)
    WinSetOnTop($hwnd, '',  $WINDOWS_ONTOP)
    WinSetState($hwnd, '', @SW_MAXIMIZE))
    AutoItSetOption("WinTitleMatchMode",1)
EndFunc

 

Link to comment
Share on other sites

this is the func via WinList described earlier if anyone is interested.

#-------------------------------------------------------#
#   @classname  = 'class'   Or 'regex: .*class$'
#   @title      = 'string'  Or 'regex: .*string$'       #
#-------------------------------------------------------#
Func _WinList_SetState($classname, $title, $sw='restore', $IsClassRegex='NotRegex', $once=1, $ontop='none')

    Local $error = 2
    Local $sFlag
    Local $_HWND_LAST_WINLIST
    
    If $IsClassRegex == 'regex' Then
        Local $sTitle = "[REGEXPCLASS:"&$classname&"; REGEXPTITLE:(?i)"&$title&"]"
    Else 
        Local $sTitle = "[CLASS:"&$classname&"; TITLE:"&$title&"]"
    EndIf
    Switch $sw
        Case 'hide'
          $sFlag = @SW_HIDE       ;= Hide window
        Case 'show'
          $sFlag = @SW_SHOW       ;= Shows a previously hidden window
        Case 'min'
          $sFlag = @SW_MINIMIZE   ;= Minimize window
        Case 'max'
          $sFlag = @SW_MAXIMIZE   ;= Maximize window
        Case 'disable'
          $sFlag = @SW_DISABLE    ;= Disables the window
        Case 'enable'
          $sFlag = @SW_ENABLE     ;= Enables the window
        Case Else
          $sFlag = @SW_RESTORE    ;= Undoes a window minimization or maximization
    EndSwitch
    
    Local $aWinList = WinList($sTitle)
;~     _ArrayDisplay($aWinList)

    If UBound($aWinList) > 1 Then
        ; Loop through the array displaying only visible last active windows with match title.
        For $i = 1 To $aWinList[0][0]
            If $aWinList[$i][0] <> "" And BitAND(WinGetState($aWinList[$i][1]), 2) Then
              
                If $once == 1 And $i > 1 Then ContinueLoop
;~              MsgBox($MB_SYSTEMMODAL, "", "Title: " & $aWinList[$i][0] & @CRLF & "Handle: " & $aWinList[$i][1])
                If $i == 1 Then $_HWND_LAST_WINLIST = $aWinList[$i][1]
                WinSetState($aWinList[$i][1], '', $sFlag)
                
                If $ontop == 'noontop' Then WinSetOnTop($aWinList[$i][1], '', $WINDOWS_NOONTOP)
                If $ontop == 'ontop' Then WinSetOnTop($aWinList[$i][1], '', $WINDOWS_ONTOP)

            EndIf
        Next
        $error = 0
    EndIf
    
    Return SetError($error, @error, $_HWND_LAST_WINLIST)
EndFunc

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...