Jump to content

Proper way to detect Open/Save Windows Dialogs


Go to solution Solved by Nine,

Recommended Posts

Posted


The problem:
Inside an application, whenever I want to Open/Save a file, the proposed folder on these dialogs are far away from I would like.
So, whenever a Open/Save Dialog is detected I would like to launch a scripts that allows me to easy change actual folder on Open/Save Dialog.

I already have a script running since Windows started (snipped):

Global $apos,  $error
While 1
    _MKHKS_WaitForEvent()
    If WinActive("[Class:#32770]") Then ; Open standard Windows Dialog always exists, so check active!
        ConsoleWrite("Detected Open / Save Dialog" & @CR)
        $apos =  WinGetPos("[Class:#32770]")
        If Not @error Then 
            ConsoleWrite("Dialog dimension X " & $apos[0] &  " Y " & $apos[1] & " width " & $apos[2] & " height " &  $apos[3] &  @CR)
        EndIf
        
        If Not WinExists("Jumping From Folder To...") Then  ; only once
            ShellExecute(@ScriptDir &  "\JumpingFromFolder.au3")  ; running my script to easy change folders
        
        EndIf
    EndIf
    Switch TrayGetMsg()
        Case $mnuShowArray
            _ArrayDisplay($aTable, "Hotkey Map", "", 0, Default, "Alias Name|HotkeySet|KeyB|Send|Function|Help|Registered/Fail", -175)
        Case $mnuExit
            Exit
    EndSwitch
    Sleep(50)
WEnd


Problems:
- False positives:  notepad++ shows a Message box saying a "file was modified by other program, Do you want to reload?" this window is a "[Class:#32770]" too.
I can't relay on Open/Save windows Title because Some programs says "Choose one or more File (STL/OBJ/AMF/3MF/PRUSA)". Some programs are English language and others one Spanish. Black List will be the last option I would choose.
PID of "Reload window" is the same than Open/Save Dialog
Window Handle is different can I relay on this between reboots? I mean hardcode Open Dialog handle?
- Mozilla: Sometimes JumpingFromFolder script is launched although Mozilla didn't open an Open/Save Dialog. What are you doing with your life Mozilla?

I searched the forum, I didn't get any close solution
Can I know if a control exists on a window? For example trying to know if "Edit" control exists on "[Class:#32770]" window.
I'm open to new suggestions or new methods to do that.

Control Viewer Reports:

Spoiler

###AutoIt Control Viewer Report File###

Environment : Open / Save Dialog
===========
System:   Microsoft Windows 8.1 64 bits
Aero:     Enabled

Window
======
Title:    Selecciona un archivo (3MF/AMF):
Class:    #32770
Style:    0x96CC02C4
ExStyle:  0x00010101
Position: 145, 362
Size:     1307, 614
Handle:   0x000C1DB2
PID:      5480
Path:

Control
=======
Class:    Edit  (Edit I will paste an absolute path and press Enter with my Script)
Instance: 1
ID:       1148
Style:    0x54000080
ExStyle:  0x00000000
Position: 186, 513
Size:     868, 15
Handle:   0x00041DA6
Text:

 

###AutoIt Control Viewer Report File###

Environment : notepad++ reload window
===========
System:   Microsoft Windows 8.1 64 bits
Aero:     Enabled

Window
======
Title:    Reload
Class:    #32770
Style:    0x94C801C5
ExStyle:  0x00010101
Position: 740, 452
Size:     444, 190
Handle:   0x000D1B72
PID:      5268
Path:

Control
=======
Class:
Instance:
ID:
Style:
ExStyle:
Position:
Size:
Handle:
Text:

Thank you very much for your time!

Posted (edited)

check if this help

Local $hWnd, $sWinTitle, $sText
Local $aWinList = WinList("[CLASS:#32770]")

For $x = 1 To $aWinList[0][0]
    $hWnd = $aWinList[$x][1]
    $sWinTitle = WinGetTitle($hWnd)
    $sText = WinGetText($hWnd) ;Retrieve the window text

    If StringInStr($sText, "Text Documents (*.txt)") > 0  Then ; * <- or what text have your window (look in info win in tab visible text)
        ConsoleWrite("-> hWnd:" & $hWnd &  " Title:" & $sWinTitle  & @CRLF)
;~      ExitLoop
    Else
        ConsoleWrite("   hWnd:" & $hWnd &  " Title:" & $sWinTitle  & @CRLF)
    EndIf

Next

edit:
it is better to check the content of Edit,  and not if there is Edit, because 99% Edit is there

Edited by ioa747

I know that I know nothing

Posted

Or something like this:

#include <Process.au3>
#include <WindowsConstants.au3>
#include <WinAPISysWin.au3>

Local $aWinList = WinList("[CLASS:#32770]")
For $i = 1 To $aWinList[0][0]

    If _WinAPI_GetClassName(_WinAPI_GetAncestor($aWinList[$i][1], $GA_ROOTOWNER)) = "Notepad" Then
        ConsoleWrite("! Found > Parent Window Class = Notepad" & @CRLF)
    EndIf

    If _ProcessGetName(WinGetProcess(_WinAPI_GetAncestor($aWinList[$i][1], $GA_ROOTOWNER))) = "notepad.exe" Then
        ConsoleWrite("! Found > Parent Window Process = notepad.exe" & @CRLF)
    EndIf

Next

 

Posted

Thanks!

I joined both examples:

#include <Process.au3>
#include <WindowsConstants.au3>
#include <WinAPISysWin.au3>

Local $aWinList = WinList("[CLASS:#32770]")
For $i = 1 To $aWinList[0][0]
    $hWnd = $aWinList[$i][1]
    $sWinTitle = WinGetTitle($hWnd)
    $sText = WinGetText($hWnd) ;Retrieve the window text

    $sclassName= _WinAPI_GetClassName(_WinAPI_GetAncestor($aWinList[$i][1], $GA_ROOTOWNER))
    $sProcessName= _ProcessGetName(WinGetProcess(_WinAPI_GetAncestor($aWinList[$i][1], $GA_ROOTOWNER)))
    ConsoleWrite("CLASS " & $sclassName & " PROCESS " & $sProcessName & " TITLE " & $sWinTitle & " TEXT " & $sText  & "."& @CRLF)
Next

 WITHOUT any Open/Save Dialog on screen I get

CLASS #32770 PROCESS Beats64.exe TITLE HPBeatsOSD TEXT .
CLASS #32770 PROCESS prusa-slicer.exe TITLE Import SLA archive TEXT .
CLASS #32770 PROCESS prusa-slicer.exe TITLE Cola de subida al host de impresión TEXT .
CLASS #32770 PROCESS prusa-slicer.exe TITLE  TEXT .

On Prusa-slicer I have "Open project", "import STL", "export profiles", "import profiles", "Export as STL" menu items; all of them are Open/Save Dialogs. That is, a bunch to test for a single application.


If there are no more options, I would need to create a Black List or maybe a White List based on that code.

  • Solution
Posted
3 hours ago, Lepes said:

Can I know if a control exists on a window? For example trying to know if "Edit" control exists on "[Class:#32770]" window.

Here ?

While True
  If WinActive("[Class:#32770]") Then
    If ControlGetHandle("[Class:#32770]", "", "[CLASS:Edit]") Then
      ConsoleWrite("Detected" & @CRLF)
      ExitLoop
    EndIf
  EndIf
  Sleep(50)
WEnd

 

Posted

@ioa747  : I would like from all applications, that's the point.
 

@Nine Thanks!

While 1
        If WinActive("[Class:#32770]") Then ; Open standard Windows Dialog always exist, so check active!
            Local $hwnd =  WinGetHandle("[ACTIVE]") ; Get the handle of this exact window. Not the other hidden ones
            If ControlGetHandle($hWnd, "", "[CLASS:Edit]" )Then
                ConsoleWrite("Detected" & @CRLF)
                If Not WinExists("Jumping From Folder To...") Then  ; only once
                    ShellExecute(@ScriptDir &  "\JumpingFromFolder.au3")
                    sleep(500)
                EndIf
            Else 
                ConsoleWrite("controlGetHandle fail" & @CR)
            EndIf
        EndIf
    WEnd

ControlGetHandle always returned Zero. I saw Help file Examples and I placed the WinGetHandle since I already have more than one  [Class:#32770] window.
Now it works properly.

Thank you everybody!!

Posted

It's a filter to avoid "False positives"

notepad++ Reload Window Dialog doesn't have the "Edit control" but it appears as a [class:#32770] window. 

CLASS #32770 PROCESS Beats64.exe TITLE HPBeatsOSD TEXT .
CLASS #32770 PROCESS prusa-slicer.exe TITLE Import SLA archive TEXT .
CLASS #32770 PROCESS prusa-slicer.exe TITLE Cola de subida al host de impresión TEXT .
CLASS #32770 PROCESS prusa-slicer.exe TITLE  TEXT .

Those "fake" #32770  windows doesn't have the "Edit control"

So, my script only appears on screen when a #32770 window is active and it has an Edit control in it.

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
×
×
  • Create New...