Jump to content

Hide taskbar icon of App - but with still GUICreate element visible


LukasChury
 Share

Go to solution Solved by LukasChury,

Recommended Posts

Hi,

I have the code, that create an element, which hide (overlay) Close a Minimalize buttons of the Chromium App.
(Because I need that users close the App on the Web in Chromium, because beforeunload dont work already in these days and I need make some clear things before App exit...).

I found an solution that hide the buttons (overlay them) and works fine (if is better solution, maybe without overlay, happy to listen! 🙂 )

image.png.f176e41511cc934454eef2b7f25f27a7.png

But I need run my AutoIt program without taskbar icon - only in tray, if needed.

image.png.00587f3c610fd52eb7f8ca9eaa45d979.png

All that I tried and found on this forum do not work 😞
If I use
@SW_HIDE, element that overlay the close buttons will disappears too.

My code:

#NoTrayIcon
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPISysWin.au3>
#include <ColorConstants.au3>
#include <WinAPISys.au3>
#include <Constants.au3>

Local $ySize=_WinAPI_GetSystemMetrics ( 31 ) + 8 ;~ SM_CYSIZE
Local $xSize=_WinAPI_GetSystemMetrics ( 30 ) + 56 ;~ SM_CXSIZE

Local $sizeBlock=86
Local $adjustment=$sizeBlock+ 8 + 6

Local $hGui=GUICreate("Welcome", $xSize, $ySize, 100, 100, BitOR($WS_SYSMENU,$WS_POPUP), 0)

GUISetBkColor($COLOR_WHITE,$hGui)
; Display the GUI.
$hwndActive=wingethandle("My App", "")
GUISetState(@SW_SHOW, $hGUI)
WinActivate($hwndActive)

; Loop until the user exits.
While 1
    $hwndActive=wingethandle("My App", "")
    if ($hWndActive <> $hGui) Then
        $hwndPrevious=$hwndActive
        $aPos = WinGetPos("My App")
        $newColor=pixelgetcolor($apos[0] + $aPos[2] - 106, $aPos[1] + 14)
        GUISetBkColor($newColor,$hGui)
    EndIf

    ;~  WinMove($hGui,"",$apos[0], $aPos[1])

     ; Apply the style
    _WinAPI_SetWindowPos($hGui, $HWND_TOPMOST, $apos[0] + $aPos[2] - $adjustment, $apos[1]+1, 0, 0, BitOR($SWP_FRAMECHANGED, $SWP_NOSIZE))

WEnd

Is there a way to OTHER SOLUTION FOR HIDE CLOSE/MINIMALIZE BUTTON or HIDE ICON OF AUTOIT COMPILED EXE SCRIPT IN TASKBAR (with the overlay show on)?

Thanks a lot.

Edited by LukasChury
Link to comment
Share on other sites

one way i know is with $WS_EX_TOOLWINDOW

#NoTrayIcon
#include <WindowsConstants.au3>

$xSize = 200
$ySize = 200
Local $hGui=GUICreate("Welcome", $xSize, $ySize, 100, 100, $WS_SYSMENU, $WS_EX_TOOLWINDOW)
GUISetState(@SW_SHOW)

;**********************************
While 1
    Switch GUIGetMsg()
        Case -3 ;$GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd
;**********************************

 

I know that I know nothing

Link to comment
Share on other sites

15 minutes ago, ioa747 said:

one way i know is with $WS_EX_TOOLWINDOW

#NoTrayIcon
#include <WindowsConstants.au3>

$xSize = 200
$ySize = 200
Local $hGui=GUICreate("Welcome", $xSize, $ySize, 100, 100, $WS_SYSMENU, $WS_EX_TOOLWINDOW)
GUISetState(@SW_SHOW)

;**********************************
While 1
    Switch GUIGetMsg()
        Case -3 ;$GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd
;**********************************

 

It doesnt work as I need to.

image.png.0305758da49b25d36eb93b977283d151.png

Link to comment
Share on other sites

But i finally found the solution (thanks to ChatGPT 🙂 ).

#include <WinAPI.au3>

;Just for where the $hGui variable is:
;Local $hGui=GUICreate("Welcome", $xSize, $ySize, 100, 100, BitOR($WS_SYSMENU,$WS_POPUP), 0)

_WinAPI_ShowWindow($hGui, @SW_HIDE) ; Hide the window
_WinAPI_SetWindowLong($hGui, $GWL_EXSTYLE, BitOR(_WinAPI_GetWindowLong($hGui, $GWL_EXSTYLE), $WS_EX_TOOLWINDOW)) ; Set the window as a tool window
WinSetState($hGui, "", @SW_HIDE) ; Hide the window from the taskbar

Iam so happy 🙂

Link to comment
Share on other sites

Another approach, that allows to move the window and change z-order of windows :

#NoTrayIcon
#include <WinAPI.au3>
#include <GUIConstants.au3>

Run("Notepad")
Local $hApp = WinWait("[CLASS:Notepad]")

Local $iHeight = _WinAPI_GetSystemMetrics($SM_CYCAPTION)
Local $iWidth = 100

Local $aPos = WinGetPos($hApp), $aPosPrev = $aPos

Local $hOver = GUICreate("Over", $iWidth - 8, $iHeight, $aPos[0] + $aPos[2] - $iWidth, $aPos[1] + 1, $WS_POPUP, $WS_EX_TOOLWINDOW)
GUISetBkColor(0xFFFFFF)
GUISetState(@SW_SHOWNOACTIVATE)

_WinAPI_SetWindowLong($hOver, $GWL_HWNDPARENT, $hApp)

While WinExists($hApp)
  Sleep(10)
  $aPos = WinGetPos($hApp)
  If $aPos[0] = $aPosPrev[0] And $aPos[1] = $aPosPrev[1] Then ContinueLoop
  WinMove($hOver, "", $aPos[0] + $aPos[2] - $iWidth, $aPos[1] + 1)
WEnd

 

Link to comment
Share on other sites

  • Solution
6 hours ago, Nine said:

Another approach, that allows to move the window and change z-order of windows :

#NoTrayIcon
#include <WinAPI.au3>
#include <GUIConstants.au3>

Run("Notepad")
Local $hApp = WinWait("[CLASS:Notepad]")

Local $iHeight = _WinAPI_GetSystemMetrics($SM_CYCAPTION)
Local $iWidth = 100

Local $aPos = WinGetPos($hApp), $aPosPrev = $aPos

Local $hOver = GUICreate("Over", $iWidth - 8, $iHeight, $aPos[0] + $aPos[2] - $iWidth, $aPos[1] + 1, $WS_POPUP, $WS_EX_TOOLWINDOW)
GUISetBkColor(0xFFFFFF)
GUISetState(@SW_SHOWNOACTIVATE)

_WinAPI_SetWindowLong($hOver, $GWL_HWNDPARENT, $hApp)

While WinExists($hApp)
  Sleep(10)
  $aPos = WinGetPos($hApp)
  If $aPos[0] = $aPosPrev[0] And $aPos[1] = $aPosPrev[1] Then ContinueLoop
  WinMove($hOver, "", $aPos[0] + $aPos[2] - $iWidth, $aPos[1] + 1)
WEnd

 

Thank you! I add the changing the background of the overlay, and now it works nicely! 🙂

The final code:

#NoTrayIcon
#include <WinAPI.au3>
#include <GUIConstants.au3>

Local $hApp = WinWait("My App")

Local $iHeight = _WinAPI_GetSystemMetrics($SM_CYCAPTION)
Local $iWidth = 100

Local $aPos = WinGetPos($hApp), $aPosPrev = $aPos

Local $hOver = GUICreate("Over", $iWidth - 8, $iHeight+7, $aPos[0] + $aPos[2] - $iWidth, $aPos[1]+1, $WS_POPUP, $WS_EX_TOOLWINDOW)
GUISetBkColor(0xFFFFFF)
GUISetState(@SW_SHOWNOACTIVATE)

$newColor=pixelgetcolor($apos[0] + $aPos[2] - 106, $aPos[1] + 14)
GUISetBkColor($newColor,$hOver)

_WinAPI_SetWindowLong($hOver, $GWL_HWNDPARENT, $hApp)

While WinExists($hApp)
  Sleep(10)
  $newColor=pixelgetcolor($apos[0] + $aPos[2] - 106, $aPos[1] + 14)
  GUISetBkColor($newColor,$hOver)
  $aPos = WinGetPos($hApp)
  If $aPos[0] = $aPosPrev[0] And $aPos[1] = $aPosPrev[1] Then ContinueLoop
  WinMove($hOver, "", $aPos[0] + $aPos[2] - $iWidth, $aPos[1] + 1)
WEnd

 

Link to comment
Share on other sites

 

#NoTrayIcon
#include <WinAPI.au3>
#include <GUIConstants.au3>

Local $hApp = WinWait("My App")

Local $iHeight = _WinAPI_GetSystemMetrics($SM_CYCAPTION)
Local $iWidth = 100

Local $aPos = WinGetPos($hApp), $aPosPrev = $aPos

Local $hOver = GUICreate("Over", $iWidth - 8, $iHeight + 7, $aPos[0] + $aPos[2] - $iWidth, $aPos[1] + 1, $WS_POPUP, $WS_EX_TOOLWINDOW, $hApp) ; * <- 1
;~ GUISetBkColor(0xFFFFFF)
GUISetState(@SW_SHOWNOACTIVATE)

WinActivate($hApp) ; * <- 2
$newColor = PixelGetColor($aPos[0] + $aPos[2] - 106, $aPos[1] + 14)
GUISetBkColor($newColor, $hOver)

;~ _WinAPI_SetWindowLong($hOver, $GWL_HWNDPARENT, $hApp)

While WinExists($hApp)
    Sleep(10)
;~  $newColor = PixelGetColor($aPos[0] + $aPos[2] - 106, $aPos[1] + 14)
;~  GUISetBkColor($newColor, $hOver)
    If WinActive($hOver) Then WinActivate($hApp) ; * <- 3
    $aPos = WinGetPos($hApp)
    If @error Then Exit  ConsoleWrite('-> unexpected exit' & @CRLF)  ; * <- 4
    If $aPos[0] = $aPosPrev[0] And $aPos[1] = $aPosPrev[1] Then ContinueLoop
    $aPosPrev = $aPos  ; * <- 5
    WinMove($hOver, "", $aPos[0] + $aPos[2] - $iWidth, $aPos[1] + 1)
WEnd

 

I know that I know nothing

Link to comment
Share on other sites

1 hour ago, ioa747 said:

 

#NoTrayIcon
#include <WinAPI.au3>
#include <GUIConstants.au3>

Local $hApp = WinWait("My App")

Local $iHeight = _WinAPI_GetSystemMetrics($SM_CYCAPTION)
Local $iWidth = 100

Local $aPos = WinGetPos($hApp), $aPosPrev = $aPos

Local $hOver = GUICreate("Over", $iWidth - 8, $iHeight + 7, $aPos[0] + $aPos[2] - $iWidth, $aPos[1] + 1, $WS_POPUP, $WS_EX_TOOLWINDOW, $hApp) ; * <- 1
;~ GUISetBkColor(0xFFFFFF)
GUISetState(@SW_SHOWNOACTIVATE)

WinActivate($hApp) ; * <- 2
$newColor = PixelGetColor($aPos[0] + $aPos[2] - 106, $aPos[1] + 14)
GUISetBkColor($newColor, $hOver)

;~ _WinAPI_SetWindowLong($hOver, $GWL_HWNDPARENT, $hApp)

While WinExists($hApp)
    Sleep(10)
;~  $newColor = PixelGetColor($aPos[0] + $aPos[2] - 106, $aPos[1] + 14)
;~  GUISetBkColor($newColor, $hOver)
    If WinActive($hOver) Then WinActivate($hApp) ; * <- 3
    $aPos = WinGetPos($hApp)
    If @error Then Exit  ConsoleWrite('-> unexpected exit' & @CRLF)  ; * <- 4
    If $aPos[0] = $aPosPrev[0] And $aPos[1] = $aPosPrev[1] Then ContinueLoop
    $aPosPrev = $aPos  ; * <- 5
    WinMove($hOver, "", $aPos[0] + $aPos[2] - $iWidth, $aPos[1] + 1)
WEnd

 

Thank you! 🙂
But if you remove this two lines inside While:

$newColor = PixelGetColor($aPos[0] + $aPos[2] - 106, $aPos[1] + 14)
GUISetBkColor($newColor, $hOver)

Then the background of "Over" is no updated while the window is active/unactive.
(because the background of Title window has different color when Window is active/unactive)

Is there a better solution with this?

Edited by LukasChury
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...