Jump to content
Sign in to follow this  
Mucho

WinGetTitle gives different results after compilation.

Recommended Posts

Mucho

If I run the following code in SciTE, I get the first seven characters of the title. But if I run its executable, I got a "0" in the msgbox. What am I missing?

Opt("WinWaitDelay",100)

Opt("WinTitleMatchMode",2)

Opt("WinDetectHiddenText",1)

Opt("MouseCoordMode",1)

Opt("TrayIconHide", 0)

Opt("TrayIconDebug", 1)

#include <GUIConstants.au3>

#include <GUIConstantsEx.au3>

#Include <GuiEdit.au3>

#include <Date.au3>

#include <File.au3>

#include <Array.au3>

#include <Misc.au3>

Dim $hWinActive, $WinTitle

$hWinActive = WinGetHandle("[ACTIVE]")

$WinTitle = StringLeft(WinGetTitle($hWinActive),7)

MsgBox(4096, "", $WinTitle)

Share this post


Link to post
Share on other sites
Melba23

Mucho,

It works for me - both in SciTE and compiled. However, I did put in a short delay so I could activate different windows to test.

When you run from SciTE the active window is obvious. Are you sure the active window is the one you think should be active when you run the executable? :D

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Mucho

M23,

Absolutely. I tested it with only one program running. When I had only Firefox running, I got the same result like the attachment.(I have a problem attaching the jpeg file. Will upload again.)

I need to get the title of the active window so that I can write a script to act on it.

Edited by Mucho

Share this post


Link to post
Share on other sites
Melba23

Mucho,

How are you running the compiled exe file? If you run it from Explorer (or something similar) that might make the wrong window active.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Mucho

M23,

I running the compiled exe file from the taskbar but I got the same blank result from the quick launch. How do I focus on the last window before I click on the exe icon?

Share this post


Link to post
Share on other sites
Mucho

m23,

I could get the following code to work for me, but with imperfection. It cycles through all minimized windows and I need to add an "EXIT" to prevent it from executing more than one. Please help to clean up for me or help me with a better alternative.

$ChartList = WinList ("", "Processing data")
For $Chart = 1 to UBound ($ChartList) - 2
   $Winstate = WinGetState($ChartList[$Chart][1], "")
   If BitAnd($Winstate, 16) Then
       .
       .
       .
   Else
       .
       .
       .
   Endif
   Exit
Next

Share this post


Link to post
Share on other sites
chachew

I ran this through SciTE and compiled and its working fine for me as well

Share this post


Link to post
Share on other sites
Melba23

Mucho,

Why not go for simplicity and add a short Sleep to your original script as I suggested earlier? :D

Then you can start your exe, reactivate the correct window by clicking on it while the script is Sleeping, and then when it awakes again it will correctly detect the active window and get to work. :oops:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Mucho

Mucho, Why not go for simplicity and add a short Sleep to your original script as I suggested earlier? M23

Got it.

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
Sign in to follow this  

  • Similar Content

    • Yirrlaar
      By Yirrlaar
      #Include <WinAPI.au3> local $ClassName = _WinAPI_GetClassName(WinGetHandle(WinGetTitle("[ACTIVE]"))) ControlClick(WinGetTitle("[ACTIVE]"), "", "[CLASS:"&$ClassName&"; INSTANCE:1]", "primary") When I am running this script it just gives me a ConsoleWrite output of "0x001D04A8"
      When using "AutoIT v3 Window Info" all the info I need for the ControlClick is there and displayed perfectly as if I typed it in normally.
      Upon click the button it should be clicking it, I see the following inn the console window:
      If I replace the $ClassName with the actual ClassName of "WindowsForms10.BUTTON.app.0.3296db7_r14_ad1" it works just fine, any ideas???
    • danusko
      By danusko
      Hi, 
      I have autoit program on my computer only portable version. I use Autoit vs 3.1.1.68
      I want to use WinGetTitle but it always return 0. 
      I want to use it for retriev windows title and then i want to switch between windows. 
      E.g. - On start is msgbox where is info - "now choose yourt first window", i click first win - e.g. Excel, then 2. msgbox "now choose your 2. window" and i choose e.g. window folder. Then i want, that my script will switch between this windws and make my routine. 
      But my test code for retrieve win title still return 0. I try this on comp in work. I dont have admin rights but i belive, that this is not a reason, bacause Au3.SPY, show me win title correctly. 
      This is my sample code. 
      Pls. any suggestions?
      thx a lot
      Sleep( 2000 ) ; Allows switching to some other window to see if can get its title. $title = WinGetTitle("[active]") If $title Then MsgBox(0, "", $title) Else MsgBox(0, "", "nothing") EndIf  
    • DLS
      By DLS
      I have a working script that changes the core affinity and process priority of multiples of a specific application I have running.  
      I have that part figured out.

      I would like to make a little modification to it.

      Windows10 introduced virtual desktops.  I am trying to have different core affinity and priority of processes on the visible and non-visible desktops.  
      What I need is a bool function that could be described as IsWindowOnCurrentDesktop($hWnd).  I have searched the winAPI.au3 but I do not believe anything like that exists built it.
      I have searched multiple places before asking for help. I found a Microsoft supplied example of the function I need using C#, but I am unfamiliar with C# to a degree that I cannot port the system call over.
      https://blogs.msdn.microsoft.com/winsdk/2015/09/10/virtual-desktop-switching-in-windows-10/
      Help is appreciated but not expected.  Thanks in advanced.   In the meantime I will be learning C# syntax and class structure.
    • WoodGrain
      By WoodGrain
      Hi All,
      I run multiple AutoIT scripts concurrently, is there a way of distinguishing between them?
      When I look under Details in task manager I just see a bunch of "AutoIt3.exe" processes. Under the processes tab I again just see a bunch of "AutoIt v3 Script" or "AutoIt v3 Script (32 bit)" applications. When I hover my mouse over the tray icon I can see the tooltip "AutoIt - Current Time.au3" but am not sure how to reference this.
      For example if I run a script called "Current Time.au3", how can I determine from another au3 script if this "Current Time.au3" script is running and grab it's handle (using WinGetHandle() or similar)? Following from that l'd even like to pause/resume the script, if that's possible..
      Cheers!
×