Jump to content

Recommended Posts

Posted (edited)

Hi all,
I did some experiments with FileOpenDialog function. I did this from a GUI's button click. Then i wrote another function to the same script to find the file open dialog window with WinExists function. But i can't detect the presence of the open dialog with "WinExists" function. I think when the FileOpenDialog is came, then the main script is not focused. Then i tested it with another script. That is - I run the first function (the one which contains the gui code and the fileOpenDialog code) from another IDE. And i run th window detecting function (the WinExists function) from SciTE. Then it worked. So my qustion is- Is it possible to do this task from the same script ?

This is the code that not working

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>

$hGUI = GUICreate("Window", 500, 400, -1, -1)
Global $hButton = GUICtrlCreateButton("Button", 144, 179, 202, 60)
GUISetState()

While 1
    Sleep(30)
    $hMsg = GUIGetMsg()
    Switch $hMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButton
            BtnClick()
    EndSwitch
    Checker()
WEnd

Func BtnClick()
    Local $sPath = FileOpenDialog("TestWindow","D:\AutoIt Works\EXEs","(*.*)")
    ConsoleWrite($sPath & @LF)
EndFunc

Func Checker()
    if WinExists("TestWindow") = 1 Then
        ConsoleWrite("Yes, it is there" & @CRLF)
    EndIf
EndFunc

After first failure, i ran the Checker function from SciTE and this gui function from another IDE. Then it worked. 

Edited by kcvinu
  Reveal hidden contents

 

Posted
  On 10/14/2015 at 10:28 AM, kcvinu said:

So my qustion is- Is it possible to do this task from the same script ?

No (with the current script), because function Checker will be called after the FileOpenDailog has been closed.
You could try AdLibRegister but I'm not sure if FileOpenDailog is a blocking function.

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted

@water, Thanks for pointing me the direction. Let me check the AdLibRegister function. :)

  Reveal hidden contents

 

Posted

You can do something like this:

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <WinAPIEx.au3>
#include <TrayConstants.au3>
$hGUI = GUICreate("Window", 500, 400, -1, -1)
Global $hButton = GUICtrlCreateButton("Button", 144, 179, 202, 60)
GUISetState()
GUIRegisterMsg(_WinAPI_RegisterWindowMessage('SHELLHOOK'), 'WM_SHELLHOOK')
_WinAPI_RegisterShellHookWindow($hGUI)


While 1
    Sleep(30)
    $hMsg = GUIGetMsg()
    Switch $hMsg
        Case $GUI_EVENT_CLOSE
            _WinAPI_DeregisterShellHookWindow($hGUI)
            Exit
        Case $hButton
            BtnClick()
    EndSwitch
WEnd

Func BtnClick()
    Local $sPath = FileOpenDialog("TestWindow", "D:\AutoIt Works\EXEs", "(*.*)")
    ConsoleWrite($sPath & @LF)
EndFunc   ;==>BtnClick

Func Print()
    ConsoleWrite("Yes, it is there" & @CRLF)
EndFunc   ;==>Print



Func WM_SHELLHOOK($hWnd, $iMsg, $wParam, $lParam)
    #forceref $iMsg
    Local $sTitle = ""
    Local Const $sDlgTitle = "TestWindow"
    Switch $wParam

        Case $HSHELL_WINDOWCREATED
            $sTitle = WinGetTitle($lParam)
            If WinGetProcess($lParam) = @AutoItPID And $sTitle = $sDlgTitle Then
                Print()
            EndIf

    EndSwitch
EndFunc   ;==>WM_SHELLHOOK

Saludos

Posted

@Danyfirex Perfect !. This is what i want. Now, its time to learn some new stuff. I mean the function you used. WM_SHELLHOOK. Thanks a lot for this help. I hope you don't mind if i ask some doubts about this function. :)

  Reveal hidden contents

 

Posted (edited)

In WM_SHELLHOOK function, $iParam is the process ID of TestWindow. Isn't it ?.

Shell hook message value is not a pre-defined constant like other message IDs such as WM_COMMAND. So the value must be obtained dynamically using a call toRegisterWindowMessage. Am i right ?

And tell me what is $wParam in this function. 

Edited by kcvinu
  Reveal hidden contents

 

Posted
Posted

Thanks. I have bookmarked that link for later reading.

  Reveal hidden contents

 

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