kcvinu

Can't get the result with WinExists function

9 posts in this topic

#1 ·  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

My Contributions

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)

 

Share this post


Link to post
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.

1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2016-08-18 - Version 1.4.6.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2016-12-04 - Version 1.2.2.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

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


My Contributions

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)

 

Share this post


Link to post
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

1 person likes this

Share this post


Link to post
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. :)


My Contributions

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)

 

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

#7 ·  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

My Contributions

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)

 

Share this post


Link to post
Share on other sites

Is not like get it dinamically. I more like create/register that message.

Here are the parameters.

https://msdn.microsoft.com/en-us/library/windows/desktop/ms633573(v=vs.85).aspx


Saludos

1 person likes this

Share this post


Link to post
Share on other sites

Thanks. I have bookmarked that link for later reading.


My Contributions

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)

 

Share this post


Link to post
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

  • Similar Content

    • afallenhope
      By afallenhope
      Hello all I am trying to use this function to detect if a specific window is running. Then for it to activate it and send an ALT+F command to close the window. But I cannot seem to get it to detect the window and subsequently the rest of the code does not work. 
      #include <MsgBoxConstants.au3> Handleit() Func Handleit() If WinExists("[CLASS:MsiDialogCloseClass]","InstallShield") Then WinActivate("[CLASS:MsiDialogCloseClass]","Installshield") Send("!f") Else MsgBox($MB_SYSTEMMODAL, "", "Uhhh... something didn't work. Fix it!") EndIf EndFunc Is there anything that I can substitute for the CLASS? 
      Thank you for taking the time to read my question! 
      -Richard
    • NiceBoy1234
      By NiceBoy1234
      I want to check if the cmd.exe + window of it is running, if it is running I want to put the window to the foreground, but somehow this does not work:
       
      Local $sCommandlinePath = "C:\Windows\system32\cmd.exe" RunCm() Func RunCm() If FileExists($sCommandlinePath) Then If ProcessExists("cmd.exe") Then If WinExists("[CLASS:ConsoleWindowClass]") And WinActive("[CLASS:ConsoleWindowClass]") Then Local $hCmdWindow = WinGetHandle("[CLASS:ConsoleWindowClass]") WinSetOnTop($hCmdWindow, "", $WINDOWS_ONTOP) EndIf Else Local $iCmMax = Run($sCommandlinePath, "", @SW_SHOWMAXIMIZED) EndIf EndIf EndFunc I started the command line and put another window above it then I started my script and it did not put the command line window to the foreground.
    • grimmlock
      By grimmlock
      I am looking for some help with my code. I want to be able to have this script always run, and append a file each time a program is opened adding a new line. Here is my code, and help would be greatly appreciated.
      #include <MsgBoxConstants.au3> #include <FileConstants.au3> #include <File.au3> Local $aLines, $iCount = 0 local $hDate = @YEAR & '-' & @MON & '-' & @MDAY & ' ' & @HOUR & ':' & @MIN & ':' & @SEC local $hfile=FileOpen("C:\Users\public\Desktop\new1.txt", $FO_APPEND) Local $hComputername = @ComputerName ; Computer Name Local $hUsername = @UserName ; User Name While 1     If $hfile = -1 Then         SplashTextOn("Error", "Unable to open and append the log file.", 300, 50)         Sleep(2000)         SplashOff()     EndIf         _FileReadToArray("C:\Users\public\Desktop\new1.txt", $aLines)         If Not @error Then             ; if the file exists look for the ID starting on the last line             For $i = $aLines[0] To 1 Step -1                 If StringLeft($aLines[$i], 2) == "id" Then             ; get the ID number                     $iCount = Int(StringRegExpReplace($aLines[$i], "id(\d*):.*", "$1"))                     ExitLoop                 EndIf             Next             ; Check we found an ID             If $i = 0 Then                 MsgBox(0, "Error", "No line id found")                 Exit             EndIf         EndIf     If WinExists("[Class:Notepad]", "") Then             FileWrite($hfile, _LineID() & '|' & $hDate & '|' & $hComputername & '|' & "Notepad was opened by " & $hUsername & @CRLF)             Sleep(10)             FileClose($hfile)             Sleep(1000)     EndIf WEnd Func _LineID()     $iCount += 1     Return "id" & StringFormat("%04i", $iCount) & ": " EndFunc ;==> LineID Thanks!
    • grimmlock
      By grimmlock
      Good Morning,
      I have a wierd question, that I have not been able to solve. If anyone has used Team Viewer before you know that when you are done accessing a PC (using the Personal Free Version) that the TeamViewer window pop up. So I have created a small little script that runs and closes the window if it exists.

        If winexists('TeamViewer', '') Then winclose('Teamviewer', '') Endif    
      However I just ran into a snag where if I open a browser and try to login to my Team Viewer account it closes the browser, because I have told the script to close any and all windows that have TeamViewer at the title to close. Is there a way to have the script know the difference between a browser tab and the app? That way I can access my TeamViewer account using a browser but still have the TeamViewer App windows close.
      Thanks in advance.
      Grimm
    • atnextc
      By atnextc
      I have been trying to write a script to silently install CRM Outlook client for about the past 6 days. No matter what I have tried this doesn't seem to be doing anything.

      Code is below. Any help is appreciated.


      Opt("TrayIconDebug",1) ShellExecute("R:\IT\SoftLib\CRM2011\CRM2011-Client-ENU-i386\SetupClient.exe") winwait("Microsoft Dynamics CRM 2011 for Outlook Setup") WinActivate("Microsoft Dynamics CRM 2011 for Outlook Setup") WinExists("Microsoft Dynamics CRM 2011 for Outlook Setup","I &accept the license agreement") ControlClick("Microsoft Dynamics CRM 2011 for Outlook Setup","I &accept the license agreement",1007) WinExists("Microsoft Dynamics CRM 2011 for Outlook Setup","&Next") ControlClick("Microsoft Dynamics CRM 2011 for Outlook Setup","&Next",1008) WinExists("Microsoft Dynamics CRM 2011 for Outlook Setup","Install Now") ControlClick("Microsoft Dynamics CRM 2011 for Outlook Setup","&Install Now",1019) WinExists("Microsoft Dynamics CRM 2011 for Outlook Setup","The installation completed successfully.") ControlClick("Microsoft Dynamics CRM 2011 for Outlook Setup","&Close",1038)