Jump to content

Recommended Posts

Posted

Hi,

Can any one share inputs on how we can develop floating application that can add floating functionality for any desktop application.

 

Posted
On 9/21/2020 at 11:58 PM, zeenmakr said:

You meant WinSetOnTop()

Yes , But the idea is to make app automatic to stay always on top when only double tapped. 

Ex: Double tap ms teams app, stays always on top and float(move it around)image.png.f223ef0e33f5e581ae9889874d962bee.png

Posted (edited)
13 hours ago, WindIt said:

the idea is to make app automatic to stay always on top when only double tapped.

well, not double clicking but a shadower. don't forget the icons attached

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_icon=pin.ico
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_Run_AU3Check=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****



; ----------------------------------------------------------------------------------------------------
; Pin/Unpin or SetOnTop/NoOnTop - it jumps and follows active window
; function:
; click on the blue-pin to set that window ontop/pin or click on red-pin to undo (noontop/unpin)
; red pin - is visible indicate window is set on top/floating
; blue pin - is visible means window have NOT set ontop/pin or window NOT floating
; [...] button - click ONCE -cursor will stick/attach gui- to reposition this gui
;                (only along the window title bar). click again to set & detach the mouse cursor
; right-click - on red or blue pin for exit option
;
;
; if a window is briefly flashed and only gui show, reason is because it sitting behind
; a pinned window. to bring it to the top most simply click on the 'blue pin'
;
;
; note*: dont' foget to download pin.ico, pin_red_22x22.ico and pin_blue_22x22.ico in the attachment
; ----------------------------------------------------------------------------------------------------

#include <array.au3>
#include <Constants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <GuiToolTip.au3>
#include <Process.au3>
#include "StringSize.au3"   ;https://www.autoitscript.com/forum/topic/114034-stringsize-m23-new-version-16-aug-11/


Global Const $_GUI_OFFSET = 10
Global $_WIN_ONTOP_STATE = False
Global $_IS_DIFF_HANDLE
Global $Ver=0.1
Opt("WinTitleMatchMode",4)
Opt("GUIOnEventMode", 1)
Opt("TrayMenuMode", 1)
Opt("TrayIconHide",1)
Opt("TrayIconDebug", 1)


;Special hWnd's to be ignored.
$hS1=WinGetHandle('classname=Progman')
$hS2=WinGetHandle('classname=Shell_TrayWnd')
$hS3=WinGetHandle('SysFader')

;ini prep
$IniPath=@ScriptDir&'\pin_unpin.ini'
$offset=IniRead($IniPath,"options","offset",-155)
$transall=IniRead($IniPath,"options","transall",'off')
$movspeed=IniRead($IniPath,"options","movspeed",2)

;win ontop/pin=red or noontop/unpin=blue icon
$IconPinPath=@ScriptDir&'\pin_red_22x22.ico'
$IconUnpinPath=@ScriptDir&'\pin_blue_22x22.ico'
If FileExists($IconPinPath)=0 Then MsgBox(0,'Missing File',$IconPinPath&' is missing!')
If FileExists($IconUnpinPath)=0 Then MsgBox(0,'Missing File',$IconUnpinPath&' is missing!')

Global $hWnd=0x00
Global $bwidth=20
Global $bheight=22
$hWnd_t=WinGetHandle("[ACTIVE]")


; -------------------------
; dah gui
; -------------------------
Global $GUI=GUICreate('',2*$bwidth,$bheight,0,0,-2147483648,128)
;~ GUISetBkColor(0x000000)
Global $Grabby=GUICtrlCreateButton("...",0,0,$bwidth,$bheight)
GUICtrlSetOnEvent(-1,'_grabby')         ;click-n-drag [...] button to reposition $GUI
GUICtrlSetTip(-1, 'click once - im sticky')
Global $Button=GUICtrlCreateIcon($IconUnpinPath,-1,$bwidth,0,$bwidth,$bheight)
GUICtrlSetOnEvent($Button,'_pinUnpin')  ;click to toggle pin/ontop or unpin/noontop

;Button Context Menu / Options (right click on gui Pin|Unpin Icon)
Global $menu=GUICtrlCreateContextMenu($Button)
GUICtrlCreateMenuItem("&Pin-or-Unpin v"&$Ver,$menu)
GUICtrlCreateMenuItem("",$menu)
Global $exitmenu=GUICtrlCreateMenuItem("E&xit",$menu)
GUICtrlSetOnEvent(-1,'_Exit')

Global $GUIShown=False
GUISetState(@SW_HIDE)


Global $hWnd_i=WinGetHandle($GUI)
WinSetTrans($hWnd_i,'',IniRead($IniPath,"options","transparency",255))
Global $grabbed=False
Global $grab_xi=0
Global $grab_oi=0
WinSetOnTop($hWnd_i,'',1)
Global $dp[2]
$dp[0]=0
$dp[1]=0


; -------------------------
; keep me alive
; -------------------------
WinActivate($hWnd_t)
While 1
    Sleep(100)
    If $grabbed Then
        _grabtracker()
    Else
        _pinUnpin_indicator()
        _activewindow()
    EndIf
    
    _TopMoster($hWnd_i,1000)
    _UnloadLoop(6000)
    _quickPeekAtBelowWin()
WEnd



Func _quickPeekAtBelowWin()
    Local $guiPos = WinGetPos($hWnd_i)
    If IsArray($guiPos) And Not _IsOnTop($hWnd) Then 
        Local $winPos = WinGetPos($hWnd)
        Local $iTooltipW = 40
        Local $sTitle = StringLeft(WinGetTitle($hWnd), $iTooltipW)
        Local $sTextPixelW = _StringSize('>>     []     <<'&$sTitle)[2]

        If $guiPos[1] < 0 Then
          Local $iOffSetX = -($sTextPixelW + 50)
          Local $iOffsetY = 0; 8
        Else
          Local $iOffSetX = -($sTextPixelW + 50)
          Local $iOffsetY = 0
        EndIf
        
        ;quick peek because unpin/noontop window would be invisible/behind pin/ontop window
        If $_IS_DIFF_HANDLE <> $hWnd Then
            $_IS_DIFF_HANDLE = $hWnd
                _pinUnpin()
                WinActivate($hWnd)
                Sleep(500)
                _pinUnpin()
        EndIf
        
        ;unpin/noontop window title
        ToolTip('>>     ['& $sTitle &']     <<', $guiPos[0]+$iOffSetX, $guiPos[1]+$iOffsetY)
        Sleep(100)
        ToolTip('  >>   ['& $sTitle &']   <<  ', $guiPos[0]+$iOffSetX, $guiPos[1]+$iOffsetY)
        Sleep(100)
        ToolTip('    >> ['& $sTitle &'] <<    ', $guiPos[0]+$iOffSetX, $guiPos[1]+$iOffsetY)
    Else
        ToolTip('')
    EndIf
EndFunc   ;==>_quickPeekAtBelowWin

Func _grabtracker()
    $mgp=MouseGetPos()
    $wgp=WinGetPos($hWnd)
    $bgp=WinGetPos($hWnd_i)

    ;limit it from going off the titlebar.
    $mgp[0]-=5
    If ($mgp[0]+(2*$bwidth))>$wgp[0]+$wgp[2] Then $mgp[0]=$wgp[0]+$wgp[2]-(2*$bwidth)
    If $mgp[0]<$wgp[0] Then $mgp[0]=$wgp[0]
    
    WinMove($hWnd_i,'',$mgp[0],$bgp[1])
EndFunc   ;==>_grabtracker

; reposition gui
Func _grabby()
    Global $grab_xi,$grab_oi, $grabbed, $offset
    Switch $grabbed
        Case False
            $bgp=WinGetPos($hWnd_i)
            $grab_xi=$bgp[0]
            $grab_oi=$offset
            $grabbed=True
        Case True
            $grabbed=False
            $bgp=WinGetPos($hWnd_i)
            $offset+=$bgp[0]-$grab_xi
            ConsoleWrite($offset&'-')
            $wgp=WinGetPos($hWnd)
            $arr=false
            If IsArray($wgp) Then
                $arr=true
                $halfw=Int($wgp[2]/2)
            EndIf
            
            $value_new=Abs($offset)
            $sign_old=$grab_oi/Abs($grab_oi)
            $sign_new=$offset/$value_new
            
            If $grab_oi<0 Then
                If $offset>0 Then $offset=-1
                If $arr And $offset<(-1*$wgp[2]) Then $offset=1
            EndIf
            If $grab_oi>0 Then
                If $offset<0 Then $offset=1
                If $arr And $offset>$wgp[2] Then $offset=-1
            EndIf
            If $offset<>1 and $offset<>(-1) Then
                If $arr Then
                    If $value_new>$halfw Then 
                        $offset=$offset-($wgp[2]*$sign_new)
                    EndIf
                EndIf
            EndIf
            IniWrite($IniPath,"options","offset",$offset)
            $dp=_getdockpos($hWnd)
            
            WinMove($hWnd_i,'',$dp[0],$dp[1])
    EndSwitch
EndFunc   ;==>_grabby

;set windows ontop/pin=red or noontop/unpin=blue
Func _pinUnpin()
    $wgp=WinGetPos($hWnd)    
    Local $WinTitle = WinGetTitle($hWnd)

    Local $iPinState = _IsOnTop($hWnd)
    If $iPinState Then 
        WinSetOnTop($hWnd, '', $WINDOWS_NOONTOP)
        GUICtrlSetTip($Button,'Pin/Ontop')
    Else
        WinSetOnTop($hWnd, '', $WINDOWS_ONTOP)
        GUICtrlSetTip($Button,'UnPin/NoOnTop')
    EndIf
    
    _pinUnpin_indicator()
EndFunc   ;==>_pinUnpin

; set visual pin/unpin indicator
Func _pinUnpin_indicator()
    Local $iPinState = _IsOnTop($hWnd)
    If $iPinState Then 
        GUICtrlSetImage($Button, $IconPinPath)
    Else
        GUICtrlSetImage($Button, $IconUnpinPath)
    EndIf
EndFunc   ;==>_pinUnpin_indicator

; Check if a window is pin/ontop or not
Func _IsOnTop($hWndOrsTitle, $opt = 1, $sText = '')
  Switch $opt
      Case 1 ; by window handle
          Return BitAND(_WinAPI_GetWindowLong($hWndOrsTitle, $GWL_EXSTYLE), $WS_EX_TOPMOST) = $WS_EX_TOPMOST
      Case 2 ; by window title
          Return BitAND(_WinAPI_GetWindowLong(WinGetHandle($hWndOrsTitle, $sText), $GWL_EXSTYLE), $WS_EX_TOPMOST) = $WS_EX_TOPMOST
  EndSwitch
EndFunc   ;==>_IsOnTop

Func _activewindow()
    Global $hWndc
    Local $setpos=False
    Local $enabledOnWindow=True
    Local $dp_t
    $hWnd_t=WinGetHandle("[ACTIVE]")
    Switch $hWnd_t
        Case $hWnd, $hWnd_i, $hS1, $hS2, $hS3
            $enabledOnWindow=False
    EndSwitch

    If $enabledOnWindow Then
        $dp_t=_getdockpos($hWnd_t)
        If $dp_t[0]=-$_GUI_OFFSET Or $dp_t[1]=-$_GUI_OFFSET Then $enabledOnWindow=False
    EndIf
        
    If $enabledOnWindow Then
        If $transall<>'off' Then
            WinSetTrans($hWnd,'',255)
            WinSetTrans($hWnd_t,'',$transall)
        EndIf
        
        $hWnd=$hWnd_t
        $pid=WinGetProcess($hWnd)
        _priority_show(_ProcessGetPriority($pid))
    Else
        $dp_t=_getdockpos($hWnd)
        If IsArray($dp)=0 Or IsArray($dp_t)=0 Then Return 0
    EndIf
    If $dp_t[0]<>$dp[0] Or $dp_t[1]<>$dp[1] Then
        $dp=$dp_t
        $setpos=True
    EndIf
    If $setpos Then
        If $dp[0]=-$_GUI_OFFSET Or $dp[1]=-$_GUI_OFFSET Then
            $GUIShown=False
            GUISetState(@SW_HIDE,$GUI)
        Else
            WinSetOnTop($hwnd_i,'',1)
            If $movspeed=0 Or $GUIShown=False Then
                WinMove($hWnd_i,'',$dp[0],$dp[1])
            Else
                WinMove($hWnd_i,'',$dp[0],$dp[1],2*$bwidth, $bheight,$movspeed)
            EndIf
            GUISetState(@SW_SHOWNA,$GUI)
            $GUIShown=True
        EndIf
    Else
        Sleep(100)
    EndIf
EndFunc

Func _priority_show($i)
    Local $ii
    For $ii=0 To 5
        If $ii=$i Then
            GUICtrlSetState(Eval("priority_"&$ii),1)
        Else
            GUICtrlSetState(Eval("priority_"&$ii),4)
        EndIf
    Next
EndFunc
Func _getdockpos($h)
    $saved_height=Eval('wh'&Execute($h))
    Global $offset
    Local $a[2]
    $a[0]=-$_GUI_OFFSET
    $a[1]=-$_GUI_OFFSET
    If $saved_height<0 Then Return $a           ; window isn't visable or is disabled by gui
    
    $wgs=WinGetState ($h)
    If BitAND($wgs,1)=0 Then Return $a
    If BitAND($wgs,2)=0 Then Return $a
    If BitAND($wgs,16) Then Return $a
    ;If BitAND($wgs,32) Then Return $a          ; disable on maximized windows
    
    If _dpcurwind($h)=False Then Return $a
    
    $wgp=WinGetPos($h)
    If IsArray($wgp)=0 Then Return $a

    $rpos=$wgp[0]+$wgp[2]
    If $offset>=0 Then
        $dockpos=$wgp[0]+$offset
        If $dockpos>$rpos Then Return $a
    Else
        $dockpos=$rpos+$offset
        If $dockpos<$wgp[0] Then Return $a
    EndIf
    $a[0]=$dockpos
    $a[1]=$wgp[1]+6
    
    Return $a
EndFunc
Func _dpcurwind($h)
    $hwnd_in=WinGetHandle("[ACTIVE]")
    If $hwnd_in=0 Or $hwnd_in=$hWnd_i Then Return True
    If $hwnd_in<>$h Then
        Local $tRect=_WinAPI_GetWindowRect($hwnd_in)
        Local $wgp=WinGetPos($hwnd_i)
        Local $tPoint=_WinGetPoint($wgp)
        If $wgp[0]=-$_GUI_OFFSET Or $wgp[1]=-$_GUI_OFFSET Then Return False
        If _WinAPI_PtInRect($tRect,$tPoint) Then
            Return False
        EndIf
    EndIf
    Return True
EndFunc
Func _WinGetPoint($wgp)
    Local $s
    $s=DllStructCreate("int X;int Y")
    DllStructSetData($s,"X",$wgp[0])
    DllStructSetData($s,"Y",$wgp[1])
    Return $s
EndFunc

;dirty hack to display above TopMost windows
Func _TopMoster($hWnd,$t=1000)
    Global $_Topmoster_Timer
    If TimerDiff($_Topmoster_Timer) < $t Then Return 0
    $_Topmoster_Timer = TimerInit()
    WinSetOnTop($hWnd,'',1)
EndFunc
;uses _RedMem on a timer
Func _UnloadLoop($t=10000)
    Dim $t
    Global $_UnloadLoop_Timer
    If TimerDiff($_UnloadLoop_Timer) < $t Then Return 0
    $_UnloadLoop_Timer = TimerInit()
    _RedMem ()
EndFunc
; Reduce memory -  written by wOuter ?
Func _RedMem($i_PID = -1)
    If $i_PID <> -1 Then
        Local $ai_Handle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', 0x1F0FFF, 'int', False, 'int', $i_PID)
        Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', $ai_Handle[0])
        DllCall('kernel32.dll', 'int', 'CloseHandle', 'int', $ai_Handle[0])
    Else
        Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', -1)
    EndIf
    Return $ai_Return[0]
EndFunc

; reset all pin/ontop to unpin/noontop upon exit
Func _resetWinState()
  Local $aAllWinlist = WinList("[REGEXPTITLE:(?i)(.*)]")
  For $i = UBound($aAllWinlist)-1 To 1 Step -1      ; bottom up prevent invocking bottom most win
    If StringLen($aAllWinlist[$i][0]) Then
      WinSetOnTop($aAllWinlist[$i][1], '', $WINDOWS_NOONTOP)
    EndIf
  Next
EndFunc   ;==>_resetWinState
Func _Exit()
    _resetWinState()
    Exit
EndFunc   ;==>_Exit

 

pin_icons.zip

Edited by zeenmakr
Posted
On 9/25/2020 at 4:28 AM, zeenmakr said:

well, not double clicking but a shadower. don't forget the icons attached

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_icon=pin.ico
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_Run_AU3Check=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****



; ----------------------------------------------------------------------------------------------------
; Pin/Unpin or SetOnTop/NoOnTop - it jumps and follows active window
; function:
; click on the blue-pin to set that window ontop/pin or click on red-pin to undo (noontop/unpin)
; red pin - is visible indicate window is set on top/floating
; blue pin - is visible means window have NOT set ontop/pin or window NOT floating
; [...] button - click ONCE -cursor will stick/attach gui- to reposition this gui
;                (only along the window title bar). click again to set & detach the mouse cursor
; right-click - on red or blue pin for exit option
;
;
; if a window is briefly flashed and only gui show, reason is because it sitting behind
; a pinned window. to bring it to the top most simply click on the 'blue pin'
;
;
; note*: dont' foget to download pin.ico, pin_red_22x22.ico and pin_blue_22x22.ico in the attachment
; ----------------------------------------------------------------------------------------------------

#include <array.au3>
#include <Constants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <GuiToolTip.au3>
#include <Process.au3>
#include "StringSize.au3"   ;https://www.autoitscript.com/forum/topic/114034-stringsize-m23-new-version-16-aug-11/


Global Const $_GUI_OFFSET = 10
Global $_WIN_ONTOP_STATE = False
Global $_IS_DIFF_HANDLE
Global $Ver=0.1
Opt("WinTitleMatchMode",4)
Opt("GUIOnEventMode", 1)
Opt("TrayMenuMode", 1)
Opt("TrayIconHide",1)
Opt("TrayIconDebug", 1)


;Special hWnd's to be ignored.
$hS1=WinGetHandle('classname=Progman')
$hS2=WinGetHandle('classname=Shell_TrayWnd')
$hS3=WinGetHandle('SysFader')

;ini prep
$IniPath=@ScriptDir&'\pin_unpin.ini'
$offset=IniRead($IniPath,"options","offset",-155)
$transall=IniRead($IniPath,"options","transall",'off')
$movspeed=IniRead($IniPath,"options","movspeed",2)

;win ontop/pin=red or noontop/unpin=blue icon
$IconPinPath=@ScriptDir&'\pin_red_22x22.ico'
$IconUnpinPath=@ScriptDir&'\pin_blue_22x22.ico'
If FileExists($IconPinPath)=0 Then MsgBox(0,'Missing File',$IconPinPath&' is missing!')
If FileExists($IconUnpinPath)=0 Then MsgBox(0,'Missing File',$IconUnpinPath&' is missing!')

Global $hWnd=0x00
Global $bwidth=20
Global $bheight=22
$hWnd_t=WinGetHandle("[ACTIVE]")


; -------------------------
; dah gui
; -------------------------
Global $GUI=GUICreate('',2*$bwidth,$bheight,0,0,-2147483648,128)
;~ GUISetBkColor(0x000000)
Global $Grabby=GUICtrlCreateButton("...",0,0,$bwidth,$bheight)
GUICtrlSetOnEvent(-1,'_grabby')         ;click-n-drag [...] button to reposition $GUI
GUICtrlSetTip(-1, 'click once - im sticky')
Global $Button=GUICtrlCreateIcon($IconUnpinPath,-1,$bwidth,0,$bwidth,$bheight)
GUICtrlSetOnEvent($Button,'_pinUnpin')  ;click to toggle pin/ontop or unpin/noontop

;Button Context Menu / Options (right click on gui Pin|Unpin Icon)
Global $menu=GUICtrlCreateContextMenu($Button)
GUICtrlCreateMenuItem("&Pin-or-Unpin v"&$Ver,$menu)
GUICtrlCreateMenuItem("",$menu)
Global $exitmenu=GUICtrlCreateMenuItem("E&xit",$menu)
GUICtrlSetOnEvent(-1,'_Exit')

Global $GUIShown=False
GUISetState(@SW_HIDE)


Global $hWnd_i=WinGetHandle($GUI)
WinSetTrans($hWnd_i,'',IniRead($IniPath,"options","transparency",255))
Global $grabbed=False
Global $grab_xi=0
Global $grab_oi=0
WinSetOnTop($hWnd_i,'',1)
Global $dp[2]
$dp[0]=0
$dp[1]=0


; -------------------------
; keep me alive
; -------------------------
WinActivate($hWnd_t)
While 1
    Sleep(100)
    If $grabbed Then
        _grabtracker()
    Else
        _pinUnpin_indicator()
        _activewindow()
    EndIf
    
    _TopMoster($hWnd_i,1000)
    _UnloadLoop(6000)
    _quickPeekAtBelowWin()
WEnd



Func _quickPeekAtBelowWin()
    Local $guiPos = WinGetPos($hWnd_i)
    If IsArray($guiPos) And Not _IsOnTop($hWnd) Then 
        Local $winPos = WinGetPos($hWnd)
        Local $iTooltipW = 40
        Local $sTitle = StringLeft(WinGetTitle($hWnd), $iTooltipW)
        Local $sTextPixelW = _StringSize('>>     []     <<'&$sTitle)[2]

        If $guiPos[1] < 0 Then
          Local $iOffSetX = -($sTextPixelW + 50)
          Local $iOffsetY = 0; 8
        Else
          Local $iOffSetX = -($sTextPixelW + 50)
          Local $iOffsetY = 0
        EndIf
        
        ;quick peek because unpin/noontop window would be invisible/behind pin/ontop window
        If $_IS_DIFF_HANDLE <> $hWnd Then
            $_IS_DIFF_HANDLE = $hWnd
                _pinUnpin()
                WinActivate($hWnd)
                Sleep(500)
                _pinUnpin()
        EndIf
        
        ;unpin/noontop window title
        ToolTip('>>     ['& $sTitle &']     <<', $guiPos[0]+$iOffSetX, $guiPos[1]+$iOffsetY)
        Sleep(100)
        ToolTip('  >>   ['& $sTitle &']   <<  ', $guiPos[0]+$iOffSetX, $guiPos[1]+$iOffsetY)
        Sleep(100)
        ToolTip('    >> ['& $sTitle &'] <<    ', $guiPos[0]+$iOffSetX, $guiPos[1]+$iOffsetY)
    Else
        ToolTip('')
    EndIf
EndFunc   ;==>_quickPeekAtBelowWin

Func _grabtracker()
    $mgp=MouseGetPos()
    $wgp=WinGetPos($hWnd)
    $bgp=WinGetPos($hWnd_i)

    ;limit it from going off the titlebar.
    $mgp[0]-=5
    If ($mgp[0]+(2*$bwidth))>$wgp[0]+$wgp[2] Then $mgp[0]=$wgp[0]+$wgp[2]-(2*$bwidth)
    If $mgp[0]<$wgp[0] Then $mgp[0]=$wgp[0]
    
    WinMove($hWnd_i,'',$mgp[0],$bgp[1])
EndFunc   ;==>_grabtracker

; reposition gui
Func _grabby()
    Global $grab_xi,$grab_oi, $grabbed, $offset
    Switch $grabbed
        Case False
            $bgp=WinGetPos($hWnd_i)
            $grab_xi=$bgp[0]
            $grab_oi=$offset
            $grabbed=True
        Case True
            $grabbed=False
            $bgp=WinGetPos($hWnd_i)
            $offset+=$bgp[0]-$grab_xi
            ConsoleWrite($offset&'-')
            $wgp=WinGetPos($hWnd)
            $arr=false
            If IsArray($wgp) Then
                $arr=true
                $halfw=Int($wgp[2]/2)
            EndIf
            
            $value_new=Abs($offset)
            $sign_old=$grab_oi/Abs($grab_oi)
            $sign_new=$offset/$value_new
            
            If $grab_oi<0 Then
                If $offset>0 Then $offset=-1
                If $arr And $offset<(-1*$wgp[2]) Then $offset=1
            EndIf
            If $grab_oi>0 Then
                If $offset<0 Then $offset=1
                If $arr And $offset>$wgp[2] Then $offset=-1
            EndIf
            If $offset<>1 and $offset<>(-1) Then
                If $arr Then
                    If $value_new>$halfw Then 
                        $offset=$offset-($wgp[2]*$sign_new)
                    EndIf
                EndIf
            EndIf
            IniWrite($IniPath,"options","offset",$offset)
            $dp=_getdockpos($hWnd)
            
            WinMove($hWnd_i,'',$dp[0],$dp[1])
    EndSwitch
EndFunc   ;==>_grabby

;set windows ontop/pin=red or noontop/unpin=blue
Func _pinUnpin()
    $wgp=WinGetPos($hWnd)    
    Local $WinTitle = WinGetTitle($hWnd)

    Local $iPinState = _IsOnTop($hWnd)
    If $iPinState Then 
        WinSetOnTop($hWnd, '', $WINDOWS_NOONTOP)
        GUICtrlSetTip($Button,'Pin/Ontop')
    Else
        WinSetOnTop($hWnd, '', $WINDOWS_ONTOP)
        GUICtrlSetTip($Button,'UnPin/NoOnTop')
    EndIf
    
    _pinUnpin_indicator()
EndFunc   ;==>_pinUnpin

; set visual pin/unpin indicator
Func _pinUnpin_indicator()
    Local $iPinState = _IsOnTop($hWnd)
    If $iPinState Then 
        GUICtrlSetImage($Button, $IconPinPath)
    Else
        GUICtrlSetImage($Button, $IconUnpinPath)
    EndIf
EndFunc   ;==>_pinUnpin_indicator

; Check if a window is pin/ontop or not
Func _IsOnTop($hWndOrsTitle, $opt = 1, $sText = '')
  Switch $opt
      Case 1 ; by window handle
          Return BitAND(_WinAPI_GetWindowLong($hWndOrsTitle, $GWL_EXSTYLE), $WS_EX_TOPMOST) = $WS_EX_TOPMOST
      Case 2 ; by window title
          Return BitAND(_WinAPI_GetWindowLong(WinGetHandle($hWndOrsTitle, $sText), $GWL_EXSTYLE), $WS_EX_TOPMOST) = $WS_EX_TOPMOST
  EndSwitch
EndFunc   ;==>_IsOnTop

Func _activewindow()
    Global $hWndc
    Local $setpos=False
    Local $enabledOnWindow=True
    Local $dp_t
    $hWnd_t=WinGetHandle("[ACTIVE]")
    Switch $hWnd_t
        Case $hWnd, $hWnd_i, $hS1, $hS2, $hS3
            $enabledOnWindow=False
    EndSwitch

    If $enabledOnWindow Then
        $dp_t=_getdockpos($hWnd_t)
        If $dp_t[0]=-$_GUI_OFFSET Or $dp_t[1]=-$_GUI_OFFSET Then $enabledOnWindow=False
    EndIf
        
    If $enabledOnWindow Then
        If $transall<>'off' Then
            WinSetTrans($hWnd,'',255)
            WinSetTrans($hWnd_t,'',$transall)
        EndIf
        
        $hWnd=$hWnd_t
        $pid=WinGetProcess($hWnd)
        _priority_show(_ProcessGetPriority($pid))
    Else
        $dp_t=_getdockpos($hWnd)
        If IsArray($dp)=0 Or IsArray($dp_t)=0 Then Return 0
    EndIf
    If $dp_t[0]<>$dp[0] Or $dp_t[1]<>$dp[1] Then
        $dp=$dp_t
        $setpos=True
    EndIf
    If $setpos Then
        If $dp[0]=-$_GUI_OFFSET Or $dp[1]=-$_GUI_OFFSET Then
            $GUIShown=False
            GUISetState(@SW_HIDE,$GUI)
        Else
            WinSetOnTop($hwnd_i,'',1)
            If $movspeed=0 Or $GUIShown=False Then
                WinMove($hWnd_i,'',$dp[0],$dp[1])
            Else
                WinMove($hWnd_i,'',$dp[0],$dp[1],2*$bwidth, $bheight,$movspeed)
            EndIf
            GUISetState(@SW_SHOWNA,$GUI)
            $GUIShown=True
        EndIf
    Else
        Sleep(100)
    EndIf
EndFunc

Func _priority_show($i)
    Local $ii
    For $ii=0 To 5
        If $ii=$i Then
            GUICtrlSetState(Eval("priority_"&$ii),1)
        Else
            GUICtrlSetState(Eval("priority_"&$ii),4)
        EndIf
    Next
EndFunc
Func _getdockpos($h)
    $saved_height=Eval('wh'&Execute($h))
    Global $offset
    Local $a[2]
    $a[0]=-$_GUI_OFFSET
    $a[1]=-$_GUI_OFFSET
    If $saved_height<0 Then Return $a           ; window isn't visable or is disabled by gui
    
    $wgs=WinGetState ($h)
    If BitAND($wgs,1)=0 Then Return $a
    If BitAND($wgs,2)=0 Then Return $a
    If BitAND($wgs,16) Then Return $a
    ;If BitAND($wgs,32) Then Return $a          ; disable on maximized windows
    
    If _dpcurwind($h)=False Then Return $a
    
    $wgp=WinGetPos($h)
    If IsArray($wgp)=0 Then Return $a

    $rpos=$wgp[0]+$wgp[2]
    If $offset>=0 Then
        $dockpos=$wgp[0]+$offset
        If $dockpos>$rpos Then Return $a
    Else
        $dockpos=$rpos+$offset
        If $dockpos<$wgp[0] Then Return $a
    EndIf
    $a[0]=$dockpos
    $a[1]=$wgp[1]+6
    
    Return $a
EndFunc
Func _dpcurwind($h)
    $hwnd_in=WinGetHandle("[ACTIVE]")
    If $hwnd_in=0 Or $hwnd_in=$hWnd_i Then Return True
    If $hwnd_in<>$h Then
        Local $tRect=_WinAPI_GetWindowRect($hwnd_in)
        Local $wgp=WinGetPos($hwnd_i)
        Local $tPoint=_WinGetPoint($wgp)
        If $wgp[0]=-$_GUI_OFFSET Or $wgp[1]=-$_GUI_OFFSET Then Return False
        If _WinAPI_PtInRect($tRect,$tPoint) Then
            Return False
        EndIf
    EndIf
    Return True
EndFunc
Func _WinGetPoint($wgp)
    Local $s
    $s=DllStructCreate("int X;int Y")
    DllStructSetData($s,"X",$wgp[0])
    DllStructSetData($s,"Y",$wgp[1])
    Return $s
EndFunc

;dirty hack to display above TopMost windows
Func _TopMoster($hWnd,$t=1000)
    Global $_Topmoster_Timer
    If TimerDiff($_Topmoster_Timer) < $t Then Return 0
    $_Topmoster_Timer = TimerInit()
    WinSetOnTop($hWnd,'',1)
EndFunc
;uses _RedMem on a timer
Func _UnloadLoop($t=10000)
    Dim $t
    Global $_UnloadLoop_Timer
    If TimerDiff($_UnloadLoop_Timer) < $t Then Return 0
    $_UnloadLoop_Timer = TimerInit()
    _RedMem ()
EndFunc
; Reduce memory -  written by wOuter ?
Func _RedMem($i_PID = -1)
    If $i_PID <> -1 Then
        Local $ai_Handle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', 0x1F0FFF, 'int', False, 'int', $i_PID)
        Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', $ai_Handle[0])
        DllCall('kernel32.dll', 'int', 'CloseHandle', 'int', $ai_Handle[0])
    Else
        Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', -1)
    EndIf
    Return $ai_Return[0]
EndFunc

; reset all pin/ontop to unpin/noontop upon exit
Func _resetWinState()
  Local $aAllWinlist = WinList("[REGEXPTITLE:(?i)(.*)]")
  For $i = UBound($aAllWinlist)-1 To 1 Step -1      ; bottom up prevent invocking bottom most win
    If StringLen($aAllWinlist[$i][0]) Then
      WinSetOnTop($aAllWinlist[$i][1], '', $WINDOWS_NOONTOP)
    EndIf
  Next
EndFunc   ;==>_resetWinState
Func _Exit()
    _resetWinState()
    Exit
EndFunc   ;==>_Exit

image.thumb.png.4fcb5e11175fdc5de6d92d543c503d56.png

pin_icons.zip 5.39 kB · 4 downloads

I get the error can't open file, attached pic for your referance.

 

Posted
On 9/28/2020 at 7:25 PM, Dan_555 said:

Download the StringSize.Au3 from Here(1st post) and copy it into autoit/include/ folder.

Thank You works perfectly now.

Posted
On 9/28/2020 at 7:25 PM, Dan_555 said:

Download the StringSize.Au3 from Here(1st post) and copy it into autoit/include/ folder.

On 9/25/2020 at 4:28 AM, zeenmakr said:

well, not double clicking but a shadower. don't forget the icons attached

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_icon=pin.ico
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_Run_AU3Check=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****



; ----------------------------------------------------------------------------------------------------
; Pin/Unpin or SetOnTop/NoOnTop - it jumps and follows active window
; function:
; click on the blue-pin to set that window ontop/pin or click on red-pin to undo (noontop/unpin)
; red pin - is visible indicate window is set on top/floating
; blue pin - is visible means window have NOT set ontop/pin or window NOT floating
; [...] button - click ONCE -cursor will stick/attach gui- to reposition this gui
;                (only along the window title bar). click again to set & detach the mouse cursor
; right-click - on red or blue pin for exit option
;
;
; if a window is briefly flashed and only gui show, reason is because it sitting behind
; a pinned window. to bring it to the top most simply click on the 'blue pin'
;
;
; note*: dont' foget to download pin.ico, pin_red_22x22.ico and pin_blue_22x22.ico in the attachment
; ----------------------------------------------------------------------------------------------------

#include <array.au3>
#include <Constants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <GuiToolTip.au3>
#include <Process.au3>
#include "StringSize.au3"   ;https://www.autoitscript.com/forum/topic/114034-stringsize-m23-new-version-16-aug-11/


Global Const $_GUI_OFFSET = 10
Global $_WIN_ONTOP_STATE = False
Global $_IS_DIFF_HANDLE
Global $Ver=0.1
Opt("WinTitleMatchMode",4)
Opt("GUIOnEventMode", 1)
Opt("TrayMenuMode", 1)
Opt("TrayIconHide",1)
Opt("TrayIconDebug", 1)


;Special hWnd's to be ignored.
$hS1=WinGetHandle('classname=Progman')
$hS2=WinGetHandle('classname=Shell_TrayWnd')
$hS3=WinGetHandle('SysFader')

;ini prep
$IniPath=@ScriptDir&'\pin_unpin.ini'
$offset=IniRead($IniPath,"options","offset",-155)
$transall=IniRead($IniPath,"options","transall",'off')
$movspeed=IniRead($IniPath,"options","movspeed",2)

;win ontop/pin=red or noontop/unpin=blue icon
$IconPinPath=@ScriptDir&'\pin_red_22x22.ico'
$IconUnpinPath=@ScriptDir&'\pin_blue_22x22.ico'
If FileExists($IconPinPath)=0 Then MsgBox(0,'Missing File',$IconPinPath&' is missing!')
If FileExists($IconUnpinPath)=0 Then MsgBox(0,'Missing File',$IconUnpinPath&' is missing!')

Global $hWnd=0x00
Global $bwidth=20
Global $bheight=22
$hWnd_t=WinGetHandle("[ACTIVE]")


; -------------------------
; dah gui
; -------------------------
Global $GUI=GUICreate('',2*$bwidth,$bheight,0,0,-2147483648,128)
;~ GUISetBkColor(0x000000)
Global $Grabby=GUICtrlCreateButton("...",0,0,$bwidth,$bheight)
GUICtrlSetOnEvent(-1,'_grabby')         ;click-n-drag [...] button to reposition $GUI
GUICtrlSetTip(-1, 'click once - im sticky')
Global $Button=GUICtrlCreateIcon($IconUnpinPath,-1,$bwidth,0,$bwidth,$bheight)
GUICtrlSetOnEvent($Button,'_pinUnpin')  ;click to toggle pin/ontop or unpin/noontop

;Button Context Menu / Options (right click on gui Pin|Unpin Icon)
Global $menu=GUICtrlCreateContextMenu($Button)
GUICtrlCreateMenuItem("&Pin-or-Unpin v"&$Ver,$menu)
GUICtrlCreateMenuItem("",$menu)
Global $exitmenu=GUICtrlCreateMenuItem("E&xit",$menu)
GUICtrlSetOnEvent(-1,'_Exit')

Global $GUIShown=False
GUISetState(@SW_HIDE)


Global $hWnd_i=WinGetHandle($GUI)
WinSetTrans($hWnd_i,'',IniRead($IniPath,"options","transparency",255))
Global $grabbed=False
Global $grab_xi=0
Global $grab_oi=0
WinSetOnTop($hWnd_i,'',1)
Global $dp[2]
$dp[0]=0
$dp[1]=0


; -------------------------
; keep me alive
; -------------------------
WinActivate($hWnd_t)
While 1
    Sleep(100)
    If $grabbed Then
        _grabtracker()
    Else
        _pinUnpin_indicator()
        _activewindow()
    EndIf
    
    _TopMoster($hWnd_i,1000)
    _UnloadLoop(6000)
    _quickPeekAtBelowWin()
WEnd



Func _quickPeekAtBelowWin()
    Local $guiPos = WinGetPos($hWnd_i)
    If IsArray($guiPos) And Not _IsOnTop($hWnd) Then 
        Local $winPos = WinGetPos($hWnd)
        Local $iTooltipW = 40
        Local $sTitle = StringLeft(WinGetTitle($hWnd), $iTooltipW)
        Local $sTextPixelW = _StringSize('>>     []     <<'&$sTitle)[2]

        If $guiPos[1] < 0 Then
          Local $iOffSetX = -($sTextPixelW + 50)
          Local $iOffsetY = 0; 8
        Else
          Local $iOffSetX = -($sTextPixelW + 50)
          Local $iOffsetY = 0
        EndIf
        
        ;quick peek because unpin/noontop window would be invisible/behind pin/ontop window
        If $_IS_DIFF_HANDLE <> $hWnd Then
            $_IS_DIFF_HANDLE = $hWnd
                _pinUnpin()
                WinActivate($hWnd)
                Sleep(500)
                _pinUnpin()
        EndIf
        
        ;unpin/noontop window title
        ToolTip('>>     ['& $sTitle &']     <<', $guiPos[0]+$iOffSetX, $guiPos[1]+$iOffsetY)
        Sleep(100)
        ToolTip('  >>   ['& $sTitle &']   <<  ', $guiPos[0]+$iOffSetX, $guiPos[1]+$iOffsetY)
        Sleep(100)
        ToolTip('    >> ['& $sTitle &'] <<    ', $guiPos[0]+$iOffSetX, $guiPos[1]+$iOffsetY)
    Else
        ToolTip('')
    EndIf
EndFunc   ;==>_quickPeekAtBelowWin

Func _grabtracker()
    $mgp=MouseGetPos()
    $wgp=WinGetPos($hWnd)
    $bgp=WinGetPos($hWnd_i)

    ;limit it from going off the titlebar.
    $mgp[0]-=5
    If ($mgp[0]+(2*$bwidth))>$wgp[0]+$wgp[2] Then $mgp[0]=$wgp[0]+$wgp[2]-(2*$bwidth)
    If $mgp[0]<$wgp[0] Then $mgp[0]=$wgp[0]
    
    WinMove($hWnd_i,'',$mgp[0],$bgp[1])
EndFunc   ;==>_grabtracker

; reposition gui
Func _grabby()
    Global $grab_xi,$grab_oi, $grabbed, $offset
    Switch $grabbed
        Case False
            $bgp=WinGetPos($hWnd_i)
            $grab_xi=$bgp[0]
            $grab_oi=$offset
            $grabbed=True
        Case True
            $grabbed=False
            $bgp=WinGetPos($hWnd_i)
            $offset+=$bgp[0]-$grab_xi
            ConsoleWrite($offset&'-')
            $wgp=WinGetPos($hWnd)
            $arr=false
            If IsArray($wgp) Then
                $arr=true
                $halfw=Int($wgp[2]/2)
            EndIf
            
            $value_new=Abs($offset)
            $sign_old=$grab_oi/Abs($grab_oi)
            $sign_new=$offset/$value_new
            
            If $grab_oi<0 Then
                If $offset>0 Then $offset=-1
                If $arr And $offset<(-1*$wgp[2]) Then $offset=1
            EndIf
            If $grab_oi>0 Then
                If $offset<0 Then $offset=1
                If $arr And $offset>$wgp[2] Then $offset=-1
            EndIf
            If $offset<>1 and $offset<>(-1) Then
                If $arr Then
                    If $value_new>$halfw Then 
                        $offset=$offset-($wgp[2]*$sign_new)
                    EndIf
                EndIf
            EndIf
            IniWrite($IniPath,"options","offset",$offset)
            $dp=_getdockpos($hWnd)
            
            WinMove($hWnd_i,'',$dp[0],$dp[1])
    EndSwitch
EndFunc   ;==>_grabby

;set windows ontop/pin=red or noontop/unpin=blue
Func _pinUnpin()
    $wgp=WinGetPos($hWnd)    
    Local $WinTitle = WinGetTitle($hWnd)

    Local $iPinState = _IsOnTop($hWnd)
    If $iPinState Then 
        WinSetOnTop($hWnd, '', $WINDOWS_NOONTOP)
        GUICtrlSetTip($Button,'Pin/Ontop')
    Else
        WinSetOnTop($hWnd, '', $WINDOWS_ONTOP)
        GUICtrlSetTip($Button,'UnPin/NoOnTop')
    EndIf
    
    _pinUnpin_indicator()
EndFunc   ;==>_pinUnpin

; set visual pin/unpin indicator
Func _pinUnpin_indicator()
    Local $iPinState = _IsOnTop($hWnd)
    If $iPinState Then 
        GUICtrlSetImage($Button, $IconPinPath)
    Else
        GUICtrlSetImage($Button, $IconUnpinPath)
    EndIf
EndFunc   ;==>_pinUnpin_indicator

; Check if a window is pin/ontop or not
Func _IsOnTop($hWndOrsTitle, $opt = 1, $sText = '')
  Switch $opt
      Case 1 ; by window handle
          Return BitAND(_WinAPI_GetWindowLong($hWndOrsTitle, $GWL_EXSTYLE), $WS_EX_TOPMOST) = $WS_EX_TOPMOST
      Case 2 ; by window title
          Return BitAND(_WinAPI_GetWindowLong(WinGetHandle($hWndOrsTitle, $sText), $GWL_EXSTYLE), $WS_EX_TOPMOST) = $WS_EX_TOPMOST
  EndSwitch
EndFunc   ;==>_IsOnTop

Func _activewindow()
    Global $hWndc
    Local $setpos=False
    Local $enabledOnWindow=True
    Local $dp_t
    $hWnd_t=WinGetHandle("[ACTIVE]")
    Switch $hWnd_t
        Case $hWnd, $hWnd_i, $hS1, $hS2, $hS3
            $enabledOnWindow=False
    EndSwitch

    If $enabledOnWindow Then
        $dp_t=_getdockpos($hWnd_t)
        If $dp_t[0]=-$_GUI_OFFSET Or $dp_t[1]=-$_GUI_OFFSET Then $enabledOnWindow=False
    EndIf
        
    If $enabledOnWindow Then
        If $transall<>'off' Then
            WinSetTrans($hWnd,'',255)
            WinSetTrans($hWnd_t,'',$transall)
        EndIf
        
        $hWnd=$hWnd_t
        $pid=WinGetProcess($hWnd)
        _priority_show(_ProcessGetPriority($pid))
    Else
        $dp_t=_getdockpos($hWnd)
        If IsArray($dp)=0 Or IsArray($dp_t)=0 Then Return 0
    EndIf
    If $dp_t[0]<>$dp[0] Or $dp_t[1]<>$dp[1] Then
        $dp=$dp_t
        $setpos=True
    EndIf
    If $setpos Then
        If $dp[0]=-$_GUI_OFFSET Or $dp[1]=-$_GUI_OFFSET Then
            $GUIShown=False
            GUISetState(@SW_HIDE,$GUI)
        Else
            WinSetOnTop($hwnd_i,'',1)
            If $movspeed=0 Or $GUIShown=False Then
                WinMove($hWnd_i,'',$dp[0],$dp[1])
            Else
                WinMove($hWnd_i,'',$dp[0],$dp[1],2*$bwidth, $bheight,$movspeed)
            EndIf
            GUISetState(@SW_SHOWNA,$GUI)
            $GUIShown=True
        EndIf
    Else
        Sleep(100)
    EndIf
EndFunc

Func _priority_show($i)
    Local $ii
    For $ii=0 To 5
        If $ii=$i Then
            GUICtrlSetState(Eval("priority_"&$ii),1)
        Else
            GUICtrlSetState(Eval("priority_"&$ii),4)
        EndIf
    Next
EndFunc
Func _getdockpos($h)
    $saved_height=Eval('wh'&Execute($h))
    Global $offset
    Local $a[2]
    $a[0]=-$_GUI_OFFSET
    $a[1]=-$_GUI_OFFSET
    If $saved_height<0 Then Return $a           ; window isn't visable or is disabled by gui
    
    $wgs=WinGetState ($h)
    If BitAND($wgs,1)=0 Then Return $a
    If BitAND($wgs,2)=0 Then Return $a
    If BitAND($wgs,16) Then Return $a
    ;If BitAND($wgs,32) Then Return $a          ; disable on maximized windows
    
    If _dpcurwind($h)=False Then Return $a
    
    $wgp=WinGetPos($h)
    If IsArray($wgp)=0 Then Return $a

    $rpos=$wgp[0]+$wgp[2]
    If $offset>=0 Then
        $dockpos=$wgp[0]+$offset
        If $dockpos>$rpos Then Return $a
    Else
        $dockpos=$rpos+$offset
        If $dockpos<$wgp[0] Then Return $a
    EndIf
    $a[0]=$dockpos
    $a[1]=$wgp[1]+6
    
    Return $a
EndFunc
Func _dpcurwind($h)
    $hwnd_in=WinGetHandle("[ACTIVE]")
    If $hwnd_in=0 Or $hwnd_in=$hWnd_i Then Return True
    If $hwnd_in<>$h Then
        Local $tRect=_WinAPI_GetWindowRect($hwnd_in)
        Local $wgp=WinGetPos($hwnd_i)
        Local $tPoint=_WinGetPoint($wgp)
        If $wgp[0]=-$_GUI_OFFSET Or $wgp[1]=-$_GUI_OFFSET Then Return False
        If _WinAPI_PtInRect($tRect,$tPoint) Then
            Return False
        EndIf
    EndIf
    Return True
EndFunc
Func _WinGetPoint($wgp)
    Local $s
    $s=DllStructCreate("int X;int Y")
    DllStructSetData($s,"X",$wgp[0])
    DllStructSetData($s,"Y",$wgp[1])
    Return $s
EndFunc

;dirty hack to display above TopMost windows
Func _TopMoster($hWnd,$t=1000)
    Global $_Topmoster_Timer
    If TimerDiff($_Topmoster_Timer) < $t Then Return 0
    $_Topmoster_Timer = TimerInit()
    WinSetOnTop($hWnd,'',1)
EndFunc
;uses _RedMem on a timer
Func _UnloadLoop($t=10000)
    Dim $t
    Global $_UnloadLoop_Timer
    If TimerDiff($_UnloadLoop_Timer) < $t Then Return 0
    $_UnloadLoop_Timer = TimerInit()
    _RedMem ()
EndFunc
; Reduce memory -  written by wOuter ?
Func _RedMem($i_PID = -1)
    If $i_PID <> -1 Then
        Local $ai_Handle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', 0x1F0FFF, 'int', False, 'int', $i_PID)
        Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', $ai_Handle[0])
        DllCall('kernel32.dll', 'int', 'CloseHandle', 'int', $ai_Handle[0])
    Else
        Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', -1)
    EndIf
    Return $ai_Return[0]
EndFunc

; reset all pin/ontop to unpin/noontop upon exit
Func _resetWinState()
  Local $aAllWinlist = WinList("[REGEXPTITLE:(?i)(.*)]")
  For $i = UBound($aAllWinlist)-1 To 1 Step -1      ; bottom up prevent invocking bottom most win
    If StringLen($aAllWinlist[$i][0]) Then
      WinSetOnTop($aAllWinlist[$i][1], '', $WINDOWS_NOONTOP)
    EndIf
  Next
EndFunc   ;==>_resetWinState
Func _Exit()
    _resetWinState()
    Exit
EndFunc   ;==>_Exit

 

pin_icons.zip 5.39 kB · 9 downloads

Hi , Also since the pin is working perfectly, Is there a way to make the pinned active window (application) transparent if i select a window behind it so that this does not block the screen completely.

Something like this below which i want to include when active window is pinned.

#include <ScreenCapture.au3>
#include <WindowsConstants.au3>
#include <GUIConstants.au3>

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

Run('mspaint.exe')
Sleep(1000); to waituntil paint is opened
_ScreenCapture_Capture('pic.jpg', 0, 0, @DesktopWidth, @DesktopHeight)

$win = GUICreate('', 400, 400, -1, -1, $WS_POPUP, BitOR($WS_EX_TRANSPARENT, $WS_EX_TOPMOST))
$pic = GUICtrlCreatePic('pic.jpg', 1, 1, 0, 0)
WinSetTrans($win, '', 100)
GUISetState()
Do
    $msg = GUIGetMsg()
Until $msg = $GUI_EVENT_CLOSE
GUIDelete($win)
FileDelete('pic.jpg')

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

Posted
On 9/28/2020 at 7:25 PM, Dan_555 said:

Download the StringSize.Au3 from Here(1st post) and copy it into autoit/include/ folder.

For some reason not able to pin MS Teams window, rest of active windows are detecting. 

This is happening on few systems and some systems where teams is installed pinning is working correctly.

What could be the reason ?

 

Steps record details for referance:

image.png.80424d45b677708028613ec2702f1252.png

Attached a short video for the behavior when trying to pin the active teams window.

Posted
On 10/2/2020 at 7:21 AM, WindIt said:

Is there a way to make the pinned active window (application) transparent if i select a window behind it so that this does not block the screen completely.

here is a quick dirty way (note. right click on red/blue pins for these menu options)

replace the original with

;Button Context Menu / Options (right click on gui Pin|Unpin Icon)
Global $menu=GUICtrlCreateContextMenu($Button)
GUICtrlCreateMenuItem("Pin-or-Unpin v"&$Ver,$menu)
GUICtrlCreateMenuItem("",$menu)
GUICtrlCreateMenuItem("  0% Transparency",$menu)
GUICtrlSetOnEvent(-1,'_setTransparency_0percent')
GUICtrlCreateMenuItem("25% Transparency",$menu)
GUICtrlSetOnEvent(-1,'_setTransparency_25percent')
GUICtrlCreateMenuItem("50% Transparency",$menu)
GUICtrlSetOnEvent(-1,'_setTransparency_50percent')
GUICtrlCreateMenuItem("75% Transparency",$menu)
GUICtrlSetOnEvent(-1,'_setTransparency_75percent')
GUICtrlCreateMenuItem("",$menu)
Global $exitmenu=GUICtrlCreateMenuItem("E&xit",$menu)
GUICtrlSetOnEvent(-1,'_Exit')

add these

; set active win transparency
Func _setTransparent_0percent()
  WinSetTrans($hWnd, '', 255)
EndFunc
Func _setTransparent_25percent()
  WinSetTrans($hWnd, '', 185)
EndFunc
Func _setTransparent_50percent()
  WinSetTrans($hWnd, '', 125)
EndFunc
Func _setTransparent_75percent()
  WinSetTrans($hWnd, '', 65)
EndFunc

replace the original with these

; reset all pin/ontop to unpin/noontop upon exit
Func _resetWinState()
  Local $aAllWinlist = WinList("[REGEXPTITLE:(?i)(.*)]")
  For $i = UBound($aAllWinlist)-1 To 1 Step -1      ; bottom up prevent invocking bottom most win
    If StringLen($aAllWinlist[$i][0]) Then
      WinSetOnTop($aAllWinlist[$i][1], '', $WINDOWS_NOONTOP)
      WinSetTrans($aAllWinlist[$i][1], '', 255)
    EndIf
  Next
EndFunc   ;==>_resetWinState

 

On 10/2/2020 at 12:28 PM, WindIt said:

For some reason not able to pin MS Teams window, rest of active windows are detecting. 

This is happening on few systems and some systems where teams is installed pinning is working correctly.

are all systems running on the same os or different. also if modifications were made to the original script, you might have made a spelling error somewhere resulted event call to non existing function.

if still not working, provide the log after replacing the original with these

;set windows ontop/pin=red or noontop/unpin=blue
Func _pinUnpin($isClicked=0)
    Local $WinTitle = WinGetTitle($hWnd)
    Local $timeStamp = @HOUR&'-'&@MIN&'-'&@SEC&'.'&@MSEC

    Local $iPinState = _IsOnTop($hWnd)
    If $iPinState Then 
        WinSetOnTop($hWnd, '', $WINDOWS_NOONTOP)
        GUICtrlSetTip($Button,'Pin/Ontop')
        If $isClicked Then
            ConsoleWrite('!>!'&@ScriptLineNumber&': '&$timeStamp&' | '&$iPinState&' - Clicked Red Pin/OnTop | '&$WinTitle&@CRLF) ;Red/Brown
        EndIF
    Else
        WinSetOnTop($hWnd, '', $WINDOWS_ONTOP)
        GUICtrlSetTip($Button,'UnPin/NoOnTop')
        If $isClicked Then
            ConsoleWrite('>->'&@ScriptLineNumber&': '&$timeStamp&' | '&$iPinState&' - Clicked Blue UnPin/NoOnTop | '&$WinTitle&@CRLF) ;Blue/Cyan
        EndIF
    EndIf
    
    Local $debug = 0
    If $isClicked Then $debug = 1
    _pinUnpin_indicator($debug, $timeStamp)
EndFunc   ;==>_pinUnpin

; set visual pin/unpin indicator
Func _pinUnpin_indicator($debug=0, $timeStamp='')
    Local $WinTitle = WinGetTitle($hWnd)
    Local $iPinState = _IsOnTop($hWnd)
    If $iPinState Then 
        GUICtrlSetImage($Button, $IconPinPath)
        If $debug Then
            ConsoleWrite('!>!'&@ScriptLineNumber&': '&$timeStamp&' | '&$iPinState&' - Set Red Pin/OnTop | '&$WinTitle&@CRLF&@CRLF) ;Red/Brown
        EndIf
    Else
        GUICtrlSetImage($Button, $IconUnpinPath)
        If $debug Then
            ConsoleWrite('>->'&@ScriptLineNumber&': '&$timeStamp&' | '&$iPinState&' - Set Blue UnPin/NoOnTop | '&$WinTitle&@CRLF&@CRLF) ;Blue/Cyan
        EndIf
    EndIf
EndFunc   ;==>_pinUnpin_indicator

also replace

GUICtrlSetOnEvent($Button,'pinUnpin_clicked')  ;click to toggle pin/ontop or unpin/noontop

then add this

;debug clicked pin/unpin
Func pinUnpin_clicked()
  _pinUnpin(1)
EndFunc

 

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
  • Recently Browsing   0 members

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