Jump to content

Add Label to an *EXISTING* window


rudi
 Share

Recommended Posts

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!

Link to comment
Share on other sites

  • Moderators

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

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
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!

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

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_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: 22/04/2018

Link to comment
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!

Link to comment
Share on other sites

  • Moderators

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.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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

No matter how many ways you word it, the answer is the same.

And using the word impossible here is foolish.

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

Monkey's are, like, natures humans.

Link to comment
Share on other sites

  • Moderators

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

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

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!

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

Link to comment
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!

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

Link to comment
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!

Link to comment
Share on other sites

@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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...