Jump to content

Can't get the result with WinExists function


kcvinu
 Share

Recommended Posts

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
Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Link to comment
Share on other sites

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:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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

Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

@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. :)

Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Link to comment
Share on other sites

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
Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Link to comment
Share on other sites

Link to comment
Share on other sites

Thanks. I have bookmarked that link for later reading.

Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

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

×
×
  • Create New...