Sign in to follow this  
Followers 0
rudi

Add Label to an *EXISTING* window

22 posts in this topic

Hi.

This must have been asked before, I'm sure, but :imwithstupid: I can't find something suitable at google or the Autoit Help System. :mad2:

I have a Delphi application, and to one control (holding buttons) I would like to add an colorful label,DetoxCenterLabel.bmp

WindowInfoTool is presenting this for the control, in which I want to create that label (or add an image):

ClassnameNN=TPanel1
Advanced Mode = [CLASS:TPanel; INSTANCE:1]
ID = 1508228 (that one changes every time the program is started)

What I would need is basically an oportunity, to add and modify controls to an *EXISTING* application's window:

  • GUICtrlCreateLabel()
  • GUICtrlSetBkColor()
  • GUICtrlSetColor
Any suggestions appreciated, Regards, Rudi.

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Share this post


Link to post
Share on other sites



You have a similar thread you started earlier this morning. Please stick to one topic; it makes it a lot easier to assist :)


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

Hi Logan,

thanks for your reply, you are right, but as this is a question for one special approach, I decided to start a new topic.

As you didn't give a solution to this question, I assume, that it's tricky to add a control to an EXISTING application window?

Another "solution" (ugly, ugly) I'm thinking of is to watch, if the "DeTox Center" window is the active one. If so, then "overlay" the title bar text with a GUICreate(.... , $WS_POPUP). But this isn't a nifty approach at all.

Hm, the other thread has not a single answer so far as well - at least it seems not to be an obvious task....

Any suggestions appreciated, regards, Rudi.


Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Share this post


Link to post
Share on other sites

AutoIt 'GUI native' controls can only modify AutoIt native controls. Your best option is to contact the developer to add the label.

1 person likes this

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

AutoIt 'GUI native' controls can only modify AutoIt native controls.

OK. And what about ADDING a control for an existing program window?

Your best option is to contact the developer to add the label.

The developer is a friend of mine. This was a program coded may be 12 years ago in an (today) outdated Delphi version with a big buch of addons packed into the IDE system. He is booked up for months with a large project, and would have to reconstruct the XP based environment he coded that prog more than a decade ago. Due to program internal constraints it's unfortunately not possible to change the "titebar text", othewise that would have been my approach. This is why I'm wondering what might be some workaround to make THIS window distinguishable to another instance of the same EXE, that was started from a different folder.

Maybe you could think of some absolutely different approach, that I cannot see right now?

Thanks for your reply, Rudi.


Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Share this post


Link to post
Share on other sites

OK. And what about ADDING a control for an existing program window?

You're missing guinness' point. Your "existing program window" was not created in AutoIt, so you can't change the GUI controls with AutoIt.

1 person likes this

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

I don't. "adding" != "changing"

So once more: I do not want to CHANGE an existing control, I want to ADD a control to an existing window.

To make it easyer for you to answer that question:

( ) it is possible to add controls to an existing "non-autoit-window"

( ) it is IMpossible to add controls to an existing "non-autoit-window"

:bye: regards, Rudi ;)

Edited by rudi

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Share this post


Link to post
Share on other sites

To make it easyer for you to answer that question:

( ) it is possible to add controls to an existing "non-autoit-window"

( ) it is IMpossible to add controls to an existing "non-autoit-window"

Wonderful attitude. It is we who have answered your question 4 different ways, none of which seem to be creating the appropriate synaptic response. Perhaps if we write it out in this font it will be easier to understand :D


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

There are 4 controls on a GUI, you add one, you have changes the GUI's controls.

Thanks John, that's the point I missed: Adding a control means changing at least one of the existing controls. I wasn't aware of this fact, and I couldn't see this coherence from the other postings of JLogan3o13.

@JLogan3o13: The answer, that I would have appreciated from your side would have been: "No, for an existing "non-autoit-window" adding a control means to change exiting control(s), and this is not possible".

Nevermind, thanks for your colorful last posting anyway ;)

Regards, Rudi.

Edited by rudi

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Share this post


Link to post
Share on other sites

Glad you liked it, and glad things finall sank in! :)


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

So your (ugly ugly) approach might be the only way.

For instance I would consider creating a small WS_POPUP gui and making it a child

of your target gui. If I am not mistaken there is a way to make it move with its parent GUI.


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

Hi John.

Thanks for your relpy. Your suggestion (WS_POPUP) was, what I wanted to express in posting #3 of this thread.

I was thinking of an (systray hidden) autoit script looping to get the position of that window, and in case it was moved, adjust the position of the WS_POPUP. Making the WS_POPUPt a child of the main program's window, that will follow the position of the main window automatically would be a much better approach, I will read that up.

I'm still wondering about this "Adding a control" == "Changing a control": So even the WINDOW of a non-autoit-application itself is a control? And Autoit can't add ANY TYPE of (autoit) controls to it, as this basically means "changing-the-existing-control" of "that-window"??

Hm.

Regards, Rudi.


Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Share this post


Link to post
Share on other sites

@rudi

What about _WinAPI_SetParent ? Then you don't have to check for the parent wnd position in order to move the child GUI because with this func the child GUI will be implemented in the parent wnd.

Or I have missed something?

Br, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

Hi.

This doesn't work as expected: As soon, as the _WinAPI_SetParent() is executed, the gui turns invisible:

#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <Array.au3>



$pid = Run("notepad.exe")
ConsoleWrite($pid & @LF)
Sleep(3000)

$hWin = WinHandFromPID($pid)
$err=@error
$ext=@extended
if $ext Then
    MsgBox(0,"Error","More than one visible window for $PID = " & $pid)
    Exit
EndIf
If $err Then
    ConsoleWrite("Error" & @LF)
    Exit
EndIf

$aPos=WinGetPos($hWin)


$MyGUI = GUICreate("", 300, 20, $aPos[0]+50, $aPos[1], $WS_POPUP)
$L = GUICtrlCreateLabel("DeTox Center", 0, 0, 300, 20)
GUICtrlSetBkColor($L, 0x00f00f)
GUISetState()
sleep(2000)
_WinAPI_SetParent($MyGUI, $hWin)


While ProcessExists($pid)
    Sleep(100)
WEnd






; Returns an array of all Windows associated with a given process
Func WinHandFromPID($pid, $winTitle = "", $timeout = 8)
    Local $secs = TimerInit()
    Do
        $wins = WinList($winTitle)
        For $i = UBound($wins) - 1 To 1 Step -1
            If (WinGetProcess($wins[$i][1]) <> $pid) Or (BitAND(WinGetState($wins[$i][1]), 2) = 0) Then _ArrayDelete($wins, $i)
        Next
        $wins[0][0] = UBound($wins) - 1

        If $wins[0][0] Then
            If $wins[0][0] = 1 Then
                Return SetError(0, 0, $wins[1][1])
            Else
                Return SetError(0, 1, $wins)
            EndIf
            Sleep(1000)
        EndIf
    Until TimerDiff($secs) >= $timeout * 1000
    Return SetError(1, 0, $wins)
EndFunc   ;==>WinHandFromPID

What do I miss?

Thanks for your reply, Rudi.


Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

@rudi

Try zero coords, your child GUI can not be in front of the edit control (I haven't searched how to do it)

Edit : Note that when using _WinAPI_SetParent, the coords start from the parent wnd and not from the top left pos of your screen.

Br, FireFox.

Edited by FireFox

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

here is some simpler code to get you to where you thought you would be with the code above.

To have the child move with the parent, I think you need to use GUIRegisterMsg() func, and have

the callback function calculate the pos of parent, and move child accordingly.

#include <WindowsConstants.au3>

$pid = Run("calc.exe")
$HWnd = WinWait("Calculator")

$aPos=WinGetPos($HWnd)

$MyGUI = GUICreate("", 34, 30, $aPos[0]+19, $aPos[1] + 178, $WS_POPUP,$WS_EX_TOPMOST)
$L = GUICtrlCreateLabel("label", 0, 0, 34, 20)

GUISetState()

While ProcessExists($pid)
    Sleep(100)
WEnd
Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

Hi.

Child doesn't work with zero cords as well.

This works:

#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <Array.au3>



$pid = Run("notepad.exe")
ConsoleWrite($pid & @LF)
Sleep(3000)

$hWin = WinHandFromPID($pid)
$err=@error
$ext=@extended
if $ext Then
    MsgBox(0,"Error","More than one visible window for $PID = " & $pid)
    Exit
EndIf
If $err Then
    ConsoleWrite("Error" & @LF)
    Exit
EndIf

$aPos=WinGetPos($hWin)


$MyGUI = GUICreate("", 300, 20, 0,0, $WS_POPUP)
$L = GUICtrlCreateLabel("DeTox Center", 0, 0, 300, 20)
GUICtrlSetBkColor($L, 0x00f00f)
GUISetState() ; popup will appear in monitor's left upper corner
WinSetOnTop($MyGUI,"",1)




While ProcessExists($pid)
    $aPos=WinGetPos($hWin)
    if IsArray($aPos) Then
        ConsoleWrite("isarr" & @LF)
        WinMove($MyGUI,"",$aPos[0]+100,$aPos[1]+3)
    EndIf
    Sleep(100)
WEnd






; Returns an array of all Windows associated with a given process
Func WinHandFromPID($pid, $winTitle = "", $timeout = 8)
    Local $secs = TimerInit()
    Do
        $wins = WinList($winTitle)
        For $i = UBound($wins) - 1 To 1 Step -1
            If (WinGetProcess($wins[$i][1]) <> $pid) Or (BitAND(WinGetState($wins[$i][1]), 2) = 0) Then _ArrayDelete($wins, $i)
        Next
        $wins[0][0] = UBound($wins) - 1

        If $wins[0][0] Then
            If $wins[0][0] = 1 Then
                Return SetError(0, 0, $wins[1][1])
            Else
                Return SetError(0, 1, $wins)
            EndIf
            Sleep(1000)
        EndIf
    Until TimerDiff($secs) >= $timeout * 1000
    Return SetError(1, 0, $wins)
EndFunc   ;==>WinHandFromPID

Thanks, Regards, Rudi.

Edited by rudi

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Share this post


Link to post
Share on other sites

#20 ·  Posted (edited)

I think it might be easier to hide the original window and just create a totally new GUI. Controls can be set to send messages to the hidden controls (I think - you have to try it). I suppose it depends on how complicated the original GUI is.

Edited by czardas

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  
Followers 0