Hi all, I am writing some scripts to control some lab equipment, and sometimes I observe that the script "misses" one of the steps, leading to cascading errors. For example, at one part of the code I wrote this:
Most of the times this works, but I found that in some occasions the windows fail to close. Then, the code becomes a mess, because a second instance of the program will launch, and both windows now have the same title. I think I can solve this problem with this code:
I would like to know if anybody has any other suggestions for this kind of redundant code. Thanks,
I'm trying to fill a ListView with all normal viewable windows to act with them.
First I tried with WinList:
Local $aWinList = WinList("[REGEXPTITLE:(?i)(.+)]") Local $aTmp, $iID ;~ _ArrayDisplay($aWinList) For $i = $aWinList To 1 Step -1 ; going backwards not disturbing the index while cycling through and deleting some If StringStripWS( $aWinList[$i], 3) == "" Or _ Not BitAND(WinGetState($aWinList[$i]), $WIN_STATE_VISIBLE) Or _ BitAND(WinGetState($aWinList[$i]), $WIN_STATE_MINIMIZED ) Then _ArrayDelete($aWinList, $i) Else ; Window has a Title and is "visible" $aTmp = WinGetPos($aWinList[$i]) If $aTmp < -1000 Or $aTmp < -1000 Then ; Window is minimized or tray icon _ArrayDelete($aWinList, $i) EndIf EndIf Next $aWinList = UBound($aWinList)-1 ; getting actual # of windows ; Each row is now [ID]=> [Title], [hWnd] But it keeps getting Windows which are definitely not there at least not visible:
Those windows "Rechner", "Einstellungen", "Netflix", "Microsoft Store", ... are not there!?!
It should list only the first three windows, which are real.
I even tried it with _WinAPI_ UDF:
$hWnd = _WinAPI_GetForegroundWindow() ; Add items _GUICtrlListView_BeginUpdate($idListview) If $hWnd <> 0 Then $iI = 0 Do If _WinAPI_IsWindow($hWnd) And _WinAPI_IsWindowVisible Then _GUICtrlListView_AddItem($idListview, WinGetTitle($hWnd)) _GUICtrlListView_AddSubItem($idListview, $iI, $hWnd, 1) $iI += 1 $hWnd = _WinAPI_GetWindow($hWnd, $GW_HWNDNEXT) EndIf Until $hWnd = 0 EndIf But it is the same...
How can i distinguish those invisible windows from normal ones?
PS: I'm using Windows 10, maybe it is important to know?
I'm trying to:
1) Open a hidden browser session
2) Do some stuff in the background
3) Make the hidden window visible
This is my code:
Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase $oIE = _IECreate("https://www.google.co.uk/",0,0) $oSearchBox = _IEGetObjById($oIE, "lst-ib") $oSearchBox.innertext = "AutoIT" $oForm = _IEFormGetObjByName($oIE,"f") _IEFormSubmit($oForm) WinSetState("Google","",@SW_SHOW)
It dosen't work
The last line does make the window visible but it is an empty greyed out box that disappears as soon as I click on it.
I have a sort of workaround that hides the browser window as soon as I have created it which works fine:
$oIE = _IECreate("https://www.google.co.uk/") WinSetState("Google","",@SW_HIDE) . . . WinSetState("Google","",@SW_SHOW) But this looks a bit pants as the newly created window flashes on then off of the screen.
Am I using the wrong method to make the browser window visible?
I have come across a weird issue that I am not sure how to solve. For some reason, whenever I call WinActivate in certain scenarios instead of opening the single window that already exists, it will create a new blank tab. It should be able to be recreated with this:
AutoItSetOption("WinTitleMatchMode", 2) Sleep(1000) For $i=0 To 10 WinActivate("Internet Explorer") Next I am not actually doing this in my code, it is just to demonstrate the fact that new tabs keep popping up. Does anyone know why this happens?
EDIT: So I am not sure how reproducible this is, because it only happens every once in a while for me. I will update with more info if I find out anything.
I'm trying to take screenshot from webpage and if found code that could take screenshot even when window is minimized but sometimes i get image like Image Attached I'm trying for 4 hours ago to know where is the problem ...
Notice: for some reason I'm need to run site minimized
;coded by UEZ 2012 #include <Array.au3> #include <Constants.au3> #include <WindowsConstants.au3> #include <GDIPlus.au3> #include <IE.au3> Opt("WinTitleMatchMode", 2) Local $oIE = _IECreate("https://mybanner.qu.edu.qa/PROD/twbkwbis.P_WWWLogin") opt('winwaitdelay', 0) ;to make it run a little bit faster WinWait("User Login") $handle = WinMove("User Login - Internet Explorer","",0,0,877, 516) WinSetState("User Login","",@SW_SHOWMINIMIZED) _IELoadWait($oIE) Sleep(2000) WinSetState("User Login","",@SW_SHOWDEFAULT) $aWinlist = GetAllWindow() $handle = WinMove("Student Employment Time Attendance","",0,0,877, 516) $MyWindow=WinGetHandle("[Class:IEFrame]") ConsoleWrite($MyWindow) For $i = 0 To UBound($aWinlist) - 1 $hWnd = $aWinlist[$i] If Not WinActive($hWnd) Then ExitLoop Next If $i = UBound($aWinlist) Then Exit MsgBox(0, "Info", "No inactive window found", 10) _GDIPlus_Startup() $hBitmap = Capture_Window($MyWindow, 877, 516) _GDIPlus_ImageSaveToFile($hBitmap, @ScriptDir & "Test.jpg") _GDIPlus_BitmapDispose($hBitmap) ShellExecute(@ScriptDir & "Test.jpg") _GDIPlus_Shutdown() Exit Func Capture_Window($hWnd, $w, $h) Local $hDC_Capture = _WinAPI_GetWindowDC($hWnd) Local $hMemDC = _WinAPI_CreateCompatibleDC($hDC_Capture) Local $hHBitmap = _WinAPI_CreateCompatibleBitmap($hDC_Capture, $w, $h) Local $hObject = _WinAPI_SelectObject($hMemDC, $hHBitmap) DllCall("user32.dll", "int", "PrintWindow", "hwnd", $hWnd, "handle", $hMemDC, "int", 0) _WinAPI_DeleteDC($hMemDC) ; Local $hObject = _WinAPI_SelectObject($hMemDC, $hObject) _WinAPI_ReleaseDC($hWnd, $hDC_Capture) Local $hBmp = _GDIPlus_BitmapCreateFromHBITMAP($hHBitmap) _WinAPI_DeleteObject($hHBitmap) Return $hBmp EndFunc ;==>Capture_Window Func GetAllWindow() ;code by Authenticity - modified by UEZ Local $aWin = WinList(), $aWindows Local $iStyle, $iEx_Style, $iCounter = 0 Local $i, $hWnd_state, $aWinPos For $i = 1 To $aWin $iEx_Style = BitAND(_WinAPI_GetWindowLong($aWin[$i], $GWL_EXSTYLE), $WS_EX_TOOLWINDOW) $iStyle = BitAND(WinGetState($aWin[$i]), 2) If $iEx_Style <> -1 And Not $iEx_Style And $iStyle Then $aWinPos = WinGetPos($aWin[$i]) If $aWinPos > 1 And $aWinPos > 1 Then $aWindows[$iCounter] = $aWin[$i] $aWindows[$iCounter] = $aWin[$i] $aWindows[$iCounter] = $aWinPos $aWindows[$iCounter] = $aWinPos $iCounter += 1 EndIf ReDim $aWindows[$iCounter + 1] EndIf Next ReDim $aWindows[$iCounter] Return $aWindows EndFunc ;==>GetAllWindow