Jump to content

Window Visible (Taskbar)


Touch
 Share

Recommended Posts

How can I tell if a window is visible and is shown on the task bar?

Thanks!

[center][font="Arial"]If practise makes perfect and no-ones perfect whats the point of practise?[/font]Sorry for my rude attitude when I started here.[/center]

Link to comment
Share on other sites

How can I tell if a window is visible and is shown on the task bar?

Thanks!

You can check if the window is «APP Window», and if it's have an $WS_VISIBLE style, like this:

#include <WindowsConstants.au3>

$hWnd = GUICreate("", 200, 300, -1, -1, -1, BitOR($WS_EX_TOOLWINDOW, $WS_EX_APPWINDOW))
GUISetState()

;~ $hWnd            = WinGetHandle("[ACTIVE]")

$iIsAppWindow   = _WinIsAppWindow($hWnd)
$iIsVisible     = _WinIsVisible($hWnd)

$sResults       = StringFormat("Is APP Window:\t\t%s\nIs Visible Window:\t%s\n", $iIsAppWindow, $iIsVisible)

ConsoleWrite($sResults)
Sleep(2000)

Func _WinIsAppWindow($hWnd)
    Local $iWindowStyle = _WinGetStyle($hWnd, 0)
    Local $iWindowExStyle = _WinGetStyle($hWnd, 1)
    
    Return BitAND($iWindowStyle, $WS_EX_APPWINDOW) = $WS_EX_APPWINDOW Or BitAND($iWindowExStyle, $WS_EX_APPWINDOW) = $WS_EX_APPWINDOW
EndFunc

Func _WinIsVisible($hWnd)
    Return BitAND(_WinGetStyle($hWnd), $WS_VISIBLE) = $WS_VISIBLE
    ;Return BitAND(WinGetState($hWnd), 2) = 2
EndFunc

Func _WinGetStyle($hWnd, $iIndex=0)
    Local Const $GWL_STYLE = -16, $GWL_EXSTYLE = -20
    
    Local $iGWL_Index = $GWL_STYLE
    If $iIndex > 0 Then $iGWL_Index = $GWL_EXSTYLE
    
    Local $aStyles = DllCall('User32.dll', 'long', 'GetWindowLong', 'hwnd', $hWnd, 'int', $iGWL_Index)
    Return $aStyles[0]
EndFunc
Edited by MrCreatoR

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

How would I make this run through all items on the task bar?

[center][font="Arial"]If practise makes perfect and no-ones perfect whats the point of practise?[/font]Sorry for my rude attitude when I started here.[/center]

Link to comment
Share on other sites

So you want to get the list of windows that is visible and present on taskbar?

Try this:

#include <WindowsConstants.au3>

$aWinList = WinList()
$sAppVisible_Wins = ""

For $i = 1 To $aWinList[0][0]
    ;If $aWinList[$i][0] = "" Then ContinueLoop ;To ignore windows without titles
    
    If _WinIsAppWindow($aWinList[$i][1]) And _WinIsVisible($aWinList[$i][1]) Then $sAppVisible_Wins &= $aWinList[$i][0] & @CRLF
Next

ConsoleWrite($sAppVisible_Wins)

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

This is weird. Basically this function should loop through every window on the taskbar and screenshot it:

; This function creates a screenshot of every visible window, stores it to a temp location and keeps it in an array
Func ThumbScreen()
    Local $hWindows = WinList()
; Loop through each task bar control
    For $i = 0 To $hWindows[0][0]
        If _WinIsAppWindow($hWindows[$i][1]) Then 
            $iRandTmp = StringRand()
            _ScreenCapture_CaptureWnd($sLocation & $iRandTmp & ".jpg", WinGetHandle($hWindows[$i][0]))
            $aThumb[$i][0] = $sLocation & $iRandTmp & ".jpg"
        EndIf
    Next
EndFunc

It just ends up taking pictures of random things.

[center][font="Arial"]If practise makes perfect and no-ones perfect whats the point of practise?[/font]Sorry for my rude attitude when I started here.[/center]

Link to comment
Share on other sites

The window should be activated (and visible) to take the screenshot from it. And also you don't have to use WinGetHandle, you already have that in the WinList array...

; This function creates a screenshot of every visible window, stores it to a temp location and keeps it in an array
Func ThumbScreen()
    Local $hWindows = WinList()
; Loop through each task bar control
    For $i = 0 To $hWindows[0][0]
        If _WinIsAppWindow($hWindows[$i][1]) And _WinIsVisible($aWinList[$i][1]) Then
            WinActivate($aWinList[$i][1])
            WinWaitActive($aWinList[$i][1])
            $iRandTmp = StringRand()
            _ScreenCapture_CaptureWnd($sLocation & $iRandTmp & ".jpg", $hWindows[$i][1])
            $aThumb[$i][0] = $sLocation & $iRandTmp & ".jpg"
        EndIf
    Next
EndFunc

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

Ah right. Is there anyway without activating the window?

[center][font="Arial"]If practise makes perfect and no-ones perfect whats the point of practise?[/font]Sorry for my rude attitude when I started here.[/center]

Link to comment
Share on other sites

Ah right. Is there anyway without activating the window?

Hi,

If your window is visible and if you want to capture it only check it size and capture screen only with coords of window with this function _ScreenCapture_Capture

Link to comment
Share on other sites

Hi,

If your window is visible and if you want to capture it only check it size and capture screen only with coords of window with this function _ScreenCapture_Capture

Are you sure in that? :) - The window must be activated, otherwise the capture function gets only the frontal (top most) area. I wish we could capture background windows (without activating them first)...

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

Are you sure in that? :) - The window must be activated, otherwise the capture function gets only the frontal (top most) area. I wish we could capture background windows (without activating them first)...

Why the window must be activated if you do screenshot ? All windows on screen will be visible with _ScreenCapture_Capture
Link to comment
Share on other sites

That's what I need. I am replicating the Windows Vista Task bar hover thing. I can't keep looking through active windows.

[center][font="Arial"]If practise makes perfect and no-ones perfect whats the point of practise?[/font]Sorry for my rude attitude when I started here.[/center]

Link to comment
Share on other sites

This is my attempt at converting this.

Global $Struct = DllStructCreate("int Left;int Top;int Right;int Bottom")

$Desktop = GetDesktopWindow()
$hdcSrc = GetWindowDC($Desktop)
$hdcDest = CreateCompatibleDC($hdcSrc)
$hBitmap = CreateCompatibleBitmap($hdcSrc, GetDeviceCaps($hdcSrc, 8), GetDeviceCaps($hdcSrc, 10))

SelectObject($hdcDest, $hBitmap)
BitBlt($hdcDest, 0, 0, GetDeviceCaps($hdcSrc, 8), GetDeviceCaps($hdcSrc, 10), $hdcSrc, 0, 0, 0x00CC0020)

Func GetWindowRect($intPtr, $lpRect)
    DllStructSetData($Struct, "Left", $lpRect[0])
    DllStructSetData($Struct, "Top", $lpRect[1])
    DllStructSetData($Struct, "Right", $lpRect[2])
    DllStructSetData($Struct, "Bottom", $lpRect[3])
    Return DllCall("user32.dll", "int", "GetWindowRect", "hwnd", $intPtr, "ptr", DllStructGetPtr($Struct))
EndFunc

Func GetDesktopWindow()
    Return DllCall("user32.dll", "int", "GetDesktopWindow")
EndFunc

Func GetWindowDC($hWnd)
    Return DllCall("user32.dll", "int", "GetWindowDC", "int", $hWnd)
EndFunc

Func ReleaseDC($hWnd, $hdc)
    Return DllCall("user32.dll", "int", "ReleaseDC", "int", $hWnd, "int", $hdc)
EndFunc

Func BitBlt($hdcDest, $nXDest, $nYDest, $nWidth, $nHeight, $hdcSrc, $nXSrc, $nYSrc, $dwRop)
    Return DllCall("gdi32.dll", "int", "BitBlt", "int", $hdcDest, "int", $nXDest, "int", $nYDest, "int", $nWidth, "int", $nHeight, _
    "int",  $hdcSrc, "int", $nXSrc, "int", $nYSrc, "int", $dwRop)
EndFunc

Func CreateCompatibleBitmap($hdc, $nWidth, $nHeight)
    Return DllCall("gdi32.dll", "int", "CreateCompatibleBitmap", "int", $hdc, "int", $nWidth, "int", $nHeight)
EndFunc

Func CreateCompatibleDC($hdc)
    Return DllCall("gdi32", "int", "CreateCompatibleDC", "int", $hdc)
EndFunc

Func DeleteDC($hdc)
    Return DllCall("gdi32", "int", "DeleteDC", "int", $hdc)
EndFunc

Func DeleteObject($hObject)
    Return DllCall("gdi32", "int", "DeleteObject", "int", $hObject)
EndFunc

Func GetDeviceCaps($hdc, $nIndex)
    Return DllCall("gdi32", "int", "GetDeviceCaps", "int", $hdc, "int", $nIndex)
EndFunc

Func SelectObject($hdc, $hdiobj)
    Return DllCall("gdi32", "int", "CreateCompatibleDC", "int", $hdc, "int", $hdiobj)
EndFunc

Not sure how it works though :blush: - no errors though :)

[center][font="Arial"]If practise makes perfect and no-ones perfect whats the point of practise?[/font]Sorry for my rude attitude when I started here.[/center]

Link to comment
Share on other sites

Why the window must be activated if you do screenshot ?

I thought that i answered on that one in my previous post :).

All windows on screen will be visible with _ScreenCapture_Capture

We are talking about capturing specific window that is not currently active.

This is my attempt at converting this.

I am not sure that this is the correct way, i also found this (on russian), there is some code (post #12), but as the OP sais, if the window is not from our application, then returned black screen:

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

Global Const $PRF_CHILDREN = 0x10
Global Const $PRF_CLIENT = 0x4
Global Const $PRF_ERASEBKGND = 0x8
Global Const $PRF_NONCLIENT = 0x2
Global Const $PRF_OWNED = 0x20

Global Const $WM_PRINT = 0x317
Global Const $WM_PRINTCLIENT = 0x318

$hDesktop = _WinAPI_GetDesktopWindow()
$hDCMem = _WinAPI_CreateCompatibleDC(0)
$stRect = _WinAPI_GetWindowRect($hDesktop)

$iRect_Right = DllStructGetData($stRect, "Right")
$iRect_Left = DllStructGetData($stRect, "Left")
$iRect_Bottom = DllStructGetData($stRect, "Bottom")
$iRect_Top = DllStructGetData($stRect, "Top")

$hDC = _WinAPI_GetDC($hDesktop)
$hBmp = _WinAPI_CreateCompatibleBitmap($hDC, $iRect_Right - $iRect_Left, $iRect_Bottom - $iRect_Top)
_WinAPI_ReleaseDC($hDesktop, $hDC)

$hOld = _WinAPI_SelectObject($hDCMem, $hBmp)
_SendMessage($hDesktop, $WM_PRINT, $hDCMem, BitOR($PRF_CHILDREN, $PRF_CLIENT, $PRF_ERASEBKGND, $PRF_NONCLIENT, $PRF_OWNED))
_WinAPI_SelectObject($hDCMem, $hOld)
_WinAPI_DeleteObject($hDCMem)

_ScreenCapture_SaveImage(@ScriptDir & "\Test.png", $hBmp)

;~ _ClipBoard_Open($hDesktop)
;~ _ClipBoard_Empty()
;~ _ClipBoard_SetData($hBmp, $CF_BITMAP)
;~ _ClipBoard_Close()

I tried to play with it, but no luck so far...

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

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...