Chimp

how to change bgcolor of a control belonging to another window?

37 posts in this topic

Hi,

I have 2 distinct script running; program1 and program2. both are compiled.
Program2 has some "Label" controls on his gui, and I've the window handle and the handle of the control that I would change the background color (it's an "Label" control). The scipt that wants to change the color is program1 and the target control belongs to the gui of program2.
It is easily feasible?
Thanks for any suggestions


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites



Chimp,

I would use some form of InterProcessCommunication (I always recommend trancexx's MailSlot UDF) and do the change internally when Program2 receives the required message from Program1.

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

#3 ·  Posted (edited)

Thanks Melba,
I would prefer a way that may leave program2 completely free from this task and passively receive the setting of the color from Program1 ... something like "ControlSetText" (ControlSetBkColor would be perfect if only it existed...)

Edited by Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

Chimp,

I would prefer...

But the reality is that ControlSetBkColor does not exist, so......

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

Yes, indeed, :(

but maybe someone come out with a surprisingly way...... :)


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

Chimp,

Rather than waiting hopefully (and no doubt fruitlessly) I think your time would be better spent getting an IPC solution to work. I have some old MailSlot scripts somewhere - I will see what I can do as an example.

M23

1 person likes this

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

...thanks...


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Chimp,

That was easy (thanks to trancexx!):

Program1:

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

#include "MailSlot.au3"

; Get MailSlot address for Program2

Global $sMailSlotListFile = @ScriptDir & "\MailSlotList.lst"
Global $sMailSlotName = "\\.\mailslot\" & IniRead($sMailSlotListFile, "MailSlots", "Program2", "")

; Create GUI
$hGUI = GUICreate("Program1", 200, 200, 100, 100)

$cRecolour = GUICtrlCreateButton("Recolour", 10, 10, 80, 30)

$cColour = GUICtrlCreateLabel("", 10, 100, 180, 90)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cRecolour

            ; Create random colour
            $iColour = Dec(Hex(Random(0, 255, 1), 2) & Hex(Random(0, 255, 1), 2) & Hex(Random(0, 255, 1), 2))
            ; Send to Program2's MailSlot

            _MailSlotWrite($sMailSlotName, String($iColour))
            ; Colour own label
            GUICtrlSetBkColor($cColour, $iColour)
    EndSwitch



WEnd

Program2:

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

#include "MailSlot.au3"

; Create the Mailslot

Global $sMailSlotListFile = @ScriptDir & "\MailSlotList.lst"
Global $sMailSlotTitle = "Program2"
Global $sRandomMailSlotname = _RandomStr()
Global Const $sMailSlotName_Receive = "\\.\mailslot\" & $sRandomMailSlotname

Global $hMailSlot = _MailSlotCreate($sMailSlotName_Receive)
If @error Then
    MsgBox(48, "MailSlot for Program2", "Failed to create account!")
    Exit
EndIf

; Add to the master list
IniWrite($sMailSlotListFile, "MailSlots", $sMailSlotTitle, $sRandomMailSlotname)

; Create GUI
$hGUI = GUICreate("Program2", 200, 200, 400, 100)

$cColourVal = GUICtrlCreateLabel("", 10, 10, 80, 20)

$cColour = GUICtrlCreateLabel("", 10, 100, 180, 90)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch



    ; Is there a message?
    Local $iSize = _MailSlotCheckForNextMessage($hMailSlot)
    If $iSize Then
        ; If so then read it
        $sMessage = _MailSlotRead($hMailSlot, $iSize, 1)
        $iColour = Number($sMessage)
        ; Show colour
        GUICtrlSetData($cColourVal, Hex($iColour, 6))
        ; Colour label
        GUICtrlSetBkColor($cColour, $iColour)
    EndIf



WEnd



Func _RandomStr()
    Local $sString

    For $i = 1 To 13
        $sString &= Chr(Random(97, 122, 1))
    Next
    Return $sString

EndFunc   ;==>__RandomStr

Compile both and run Program2 before Program1 so that there is a MailSlot created for Program1 to address.

M23

Edited by Melba23
Typo
1 person likes this

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

Thanks Melba,  I tried your example, it is interesting.
 It's ok to solve what I've asked in my question,
anyway, I think it's not the right choice for my specific problem. (sorry if I've not explained well the exact problem in my first post) I try to say better here in short:
1) I have  a "Main program" with say 1000 "Label" controls on his Gui
2) I have a number of separate running Processes and each of them need to change the color of some of the "Label" controls on the Gui of the Main program.
3) The problem using "Mailslot" is that the "Main Program" should check _MailSlotCheckForNextMessage() for incoming "messages" in a sequential way and change the color of the "Labels" one after one according to the received messages.
4) In my intentions instead, the purpose of the many running processes should be to allow the "update" of the colours of the "Labels" in a "Parallel" way. That is, each process write directly the colour of the "Labels" on the Gui of the "main Program", even more than one labels updated simultaneously  by the many running processes.

... I'm pretty sure that I was not clear, however, this is what I'm trying to achieve.


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

Chimp,

As I said, I am not at all sure that you will ever get what you want - direct control of label colour by another process - so you are probably stuck with some form of IPC to pass the required details to the process which owns the label.  And that process will probably only ever be able to deal with one colour change at a time, so you will always be in Serial rather then Parallel mode. Bit if you want to wait, let me know when Godot comes along and gives you the answer.....

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

OK, thanks Melba for your help and explanations,

P.S. Godot, if you walk around here, please give a call... :P


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

... to be continued here:

Edited by Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

Godot was here. Run Program1.au3.

Program1.au3

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

Opt( "MustDeclareVars", 1 )

Example()

Func Example()
  ShellExecute( "Program2.au3" )
  While Not FileExists( "Labels.txt" )
    Sleep( 50 )
  WEnd

  Local $sLabels = FileReadLine( "Labels.txt" )
  Local $aLabels = StringSplit( $sLabels, "|", 2 ) ; 2 = $STR_NOCOUNT
  Local $hProgram2 = $aLabels[0] ; 101 rows in $aLabels, $hProgram2 = $aLabels[0], labels in $aLabels[1-100]

  Local $tRECT = DllStructCreate( $tagRECT )
  DllStructSetData( $tRECT, 'Left', 0 )
  DllStructSetData( $tRECT, 'Top', 0 )
  DllStructSetData( $tRECT, 'Right', 70 )
  DllStructSetData( $tRECT, 'Bottom', 20 )
  Local $pRECT = DllStructGetPtr( $tRECT )

  Local $hProgram1 = GUICreate( "Program 1", 200, 100, 100, 100 )
  Local $idColors = GUICtrlCreateButton( "Set colors", 50, 30, 100, 40 )
  GUISetState( @SW_SHOW, $hProgram1 )

  Local $hDC, $iColor, $hBrush, $sCtrl

  While 1
    Switch GUIGetMsg()
      Case $idColors
        For $i = 1 To 100
          $hDC = _WinAPI_GetDC( $aLabels[$i] )
          $iColor = ColorConvert( Random(0,255,1)+256*Random(0,255,1)+256*256*Random(0,255,1) ) ; BGR
          $hBrush = _WinAPI_CreateSolidBrush( $iColor )
          _WinAPI_FillRect( $hDC, $pRECT, $hBrush )
          _WinAPI_SetBkColor( $hDC, $iColor )
          _WinAPI_DrawText( $hDC, $i, $tRECT, $DT_CENTER)
          _WinAPI_ReleaseDC( $aLabels[$i], $hDC )
          _WinAPI_DeleteObject( $hBrush )
        Next
      Case $GUI_EVENT_CLOSE
        ExitLoop
    EndSwitch
  WEnd

  FileDelete( "Labels.txt" )
  GUIDelete( $hProgram1 )
  WinClose( $hProgram2 )
EndFunc

; RGB to BGR or BGR to RGB
Func ColorConvert($iColor)
  Return BitOR(BitAND($iColor, 0x00FF00), BitShift(BitAND($iColor, 0x0000FF), -16), BitShift(BitAND($iColor, 0xFF0000), 16))
EndFunc

Program2.au3

#include <GUIConstantsEx.au3>

Opt( "MustDeclareVars", 1 )

Example()

Func Example()
  Local $hProgram2 = GUICreate( "Program 2", 810, 310 )
  Local $sLabels = $hProgram2
  For $i = 0 To 99
    $sLabels &= "|" & GUICtrlGetHandle( GUICtrlCreateLabel( $i+1, 10+80*Mod($i,10), 10+30*Int($i/10), 70, 20, 0x01 ) ) ; 0x01 = $SS_CENTER
  Next

  Local $hFile = FileOpen( "Labels.txt", 2 ) ; 2 =  $FO_OVERWRITE
  FileWriteLine( $hFile, $sLabels )
  FileClose( $hFile )

  GUISetState( @SW_SHOW, $hProgram2 )
  GUISwitch( $hProgram2 )

  While GUIGetMsg() <> $GUI_EVENT_CLOSE
  WEnd
EndFunc

 

1 person likes this

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

Wow, :o ... nice workaround! :)

I've tried your way in the following script and it works well,
Using your solution, I'm testing what I've explained in previous post #9, and it works well concerning the changing of the colors, (even if it seems that using more processes gives no improvements in terms of speed cause of the bottle neck of the signals queue of the window)
One more question please about your solution: Is there a way to automatically get the dimensions of the control instead of hardcoding it in the last two  DllStructSetData 'Right' and "Bottom"?
Thanks a lot for your nice solution!

Main script (before running this script you have to compile the TX script that follow)

#include <Array.au3>
Local $Step = 250; 200; number of "Label" reference passed to separate processes

; Create a GUI containing a matrix of little squares (made by "Label" controls)
Local $hGui = GUICreate('Test', 810, 330)
GUISetBkColor("0x9A9A9A", $hGui)

; create the "panel" of labels within the GUI. All IDs of the labels are returned in an Array
Local $aGuiCtrlsMatrix = _GUICtrlsMatrix_Create(5, 5, 50, 20, 15, 15)
GUISetState(@SW_SHOW)
For $i = 0 to UBound($aGuiCtrlsMatrix) - 1
    $aGuiCtrlsMatrix[$i] = GUICtrlGetHandle($aGuiCtrlsMatrix[$i])
Next

; now spawn some "external" processes that should updete the labels
Local $Parameters, $hProcesses[Ceiling(UBound($aGuiCtrlsMatrix) / $Step)], $ii
For $i = 0 To UBound($aGuiCtrlsMatrix) - 1 Step $Step
    ; generates the string containing the group of label's IDs to be passed as parameter to the spawn process
    $Parameters = StringStripWS(_ArrayToString($aGuiCtrlsMatrix, " ", $i, $i + $Step - 1), 7)
    $Parameters = $hGui & ' ' & $Parameters ; insert the handle of the Main window as a further parameter
    ConsoleWrite($Parameters & @CRLF) ; Debug: show the $parameters on console
    ;
    $hProcesses[$ii] = Run('.\TX.exe ' & $Parameters) ; ,"",@SW_MINIMIZE) ; Spawn processes and pass parameters
    $ii += 1
Next
Sleep(1000)
WinActivate($hGui)
MsgBox(0, "Pause", "Waiting for Godot...") ; just stay in pause and idle
For $i = 0 to UBound($hProcesses) - 1
    ProcessClose($hProcesses[$i]) ; quit all spawned processes
Next
GUIDelete($hGui)
Exit
;
Func _GUICtrlsMatrix_Create($xPanelPos, $yPanelPos, $nrPerLine, $nrOfLines, $Width, $Height, $xSpace = 1, $ySpace = 1)
    Local $aGuiControls[$nrPerLine * $nrOfLines];,$aPanelParams[]
    For $i = 1 To $nrPerLine * $nrOfLines
        $row = Int($i / $nrPerLine) + Not(Not(Mod($i, $nrPerLine)))
        $col = $i - ($row * $nrPerLine - $nrPerLine)
        $left = $xPanelPos + (($Width + $xSpace) * $col) - ($Width + $xSpace)
        $top = $yPanelPos + (($Height + $ySpace) * $row) - ($Height + $ySpace)
        $aGuiControls[$i - 1] = GUICtrlCreateLabel("", $left, $top, $Width, $Height, 0x01) ; 0x01 -> center text in the label
        GUICtrlSetBkColor(-1, "0xFFFFFF") ; "0x757575")
        ; GUICtrlSetTip(-1, "Control " & $i & @LF & "Row: " & $row & "  Col: " & $col)
    Next
    Return $aGuiControls
EndFunc   ;==>_GUICtrlsMatrix_Create

TX.au3 (compile this to TX.exe before running the main script)

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Change2CUI=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <WinAPI.au3>
; -----------------------------------------------------------------------
; riceves parameter (IDs references to labels on Main process)
If Not $CmdLine[0] Then
    MsgBox(0, "Error", "Missing parameters" & @CRLF & "Exit in 5 seconds", 5)
    Exit
EndIf
; -----------------------------------------------------------------------
; _ArrayDisplay($CmdLine) ; Debug: Check received parameters
SRandom(@MSEC)
While 1 ; infinite loop to continuously update labels on Main process with random colors
    For $i = 2 To $CmdLine[0] ; start from 2 to skip HWnd
        _ControlSetBkColor( HWnd($CmdLine[$i]), "0x" & Hex(Random(0, 255, 1), 2) & Hex(Random(0, 255, 1), 2) & Hex(Random(0, 255, 1), 2))
    Next
WEnd

Func _ControlSetBkColor($hID, $iColor)
    ;
    Local $tRECT = DllStructCreate($tagRECT)
    DllStructSetData($tRECT, 'Left', 1)
    DllStructSetData($tRECT, 'Top', 1)
    DllStructSetData($tRECT, 'Right', 14)
    DllStructSetData($tRECT, 'Bottom', 14)
    Local $pRECT = DllStructGetPtr($tRECT)
    ;
    Local $hDC = _WinAPI_GetDC($hID)
    Local $hBrush = _WinAPI_CreateSolidBrush($iColor)
    _WinAPI_FillRect($hDC, $pRECT, $hBrush)
    _WinAPI_SetBkColor($hDC, $iColor)
    ; _WinAPI_DrawText( $hDC, $i, $tRECT, $DT_CENTER)
    _WinAPI_ReleaseDC($hID, $hDC)
    _WinAPI_DeleteObject($hBrush)
EndFunc   ;==>_ControlSetBkColor

 

Edited by Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

I have been playing a little with performance. This is the fastest I have come to. I have not tried to split it into multiple processes. Run tst07.au3.

tst07.au3

Local $hGui = GUICreate('Test', 810, 330)
GUISetBkColor("0x9A9A9A", $hGui)

Local $sGuiCtrlsMatrix = _GUICtrlsMatrix_Create(5, 5, 50, 20, 15, 15)

Local $hFile = FileOpen( "Labels.txt", 2 ) ; 2 =  $FO_OVERWRITE
FileWriteLine( $hFile, $sGuiCtrlsMatrix )
FileClose( $hFile )

GUISetState(@SW_SHOW)
Local $iPID = ShellExecute( "tst08.au3" )
MsgBox(0, "Pause", "Waiting for Godot...")
FileDelete( "Labels.txt" )
ProcessClose( $iPID )

Func _GUICtrlsMatrix_Create($xPanelPos, $yPanelPos, $nrPerLine, $nrOfLines, $Width, $Height, $xSpace = 1, $ySpace = 1)
  Local $sGuiControls = ""
  For $i = 1 To $nrPerLine * $nrOfLines
    $row = Int($i / $nrPerLine) + Not(Not(Mod($i, $nrPerLine)))
    $col = $i - ($row * $nrPerLine - $nrPerLine)
    $left = $xPanelPos + (($Width + $xSpace) * $col) - ($Width + $xSpace)
    $top = $yPanelPos + (($Height + $ySpace) * $row) - ($Height + $ySpace)
    $sGuiControls &= "|" & GUICtrlGetHandle(GUICtrlCreateLabel("", $left, $top, $Width, $Height))
    GUICtrlSetBkColor(-1, "0xFFFFFF")
  Next
  Return $sGuiControls
EndFunc

tst08.au3

#include <WinAPI.au3>

While Not FileExists( "Labels.txt" )
  Sleep( 50 )
WEnd

Local $sLabels = FileReadLine( "Labels.txt" )
Local $aLabels = StringSplit( $sLabels, "|", 2 ) ; 2 = $STR_NOCOUNT

Local $aPos = WinGetPos( $aLabels[1] )
Local $tRECT = DllStructCreate($tagRECT)
DllStructSetData($tRECT, 'Left', 1)
DllStructSetData($tRECT, 'Top', 1)
DllStructSetData($tRECT, 'Right', $aPos[2]-1)
DllStructSetData($tRECT, 'Bottom', $aPos[3]-1)
Local $pRECT = DllStructGetPtr($tRECT)

Local $aDC[1001]
For $i = 1 To 1000
  $aDC[$i] = _WinAPI_GetDC($aLabels[$i])
Next

Local $hBrush
While 1
  For $i = 1 To 1000
    $hBrush = DllCall("gdi32.dll", "handle", "CreateSolidBrush", "INT", "0x" & Hex(Random(0, 255, 1), 2) & Hex(Random(0, 255, 1), 2) & Hex(Random(0, 255, 1), 2))[0]
    DllCall("user32.dll", "int", "FillRect", "handle", $aDC[$i], "struct*", $pRECT, "handle", $hBrush)
    DllCall("gdi32.dll", "bool", "DeleteObject", "handle", $hBrush)
  Next
WEnd

For $i = 1 To 1000
  _WinAPI_ReleaseDC($aLabels[$i], $aDC[$i])
Next

 

1 person likes this

Share this post


Link to post
Share on other sites

You can simple create a Dummy Button.

Program1

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Program1", 260, 109, 192, 124)
$Button1 = GUICtrlCreateButton("Change Color", 88, 48, 73, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
Case $Button1

Local $hWin=WinGetHandle("[TITLE:Program2]")
ControlClick($hWin,"","Button1")
    EndSwitch
WEnd

Program2

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Program2", 285, 116, 192, 124)
$Label1 = GUICtrlCreateLabel("Danyfirex", 88, 32, 95, 27)
GUICtrlSetFont(-1, 14, 400, 0, "Lucida Sans Unicode")
GUICtrlSetColor(-1, 0x000000)
$btn=GUICtrlCreateButton("Dummy",100,70,80,30)
GUICtrlSetState(-1,$GUI_HIDE)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $btn
            GUICtrlSetBkColor($Label1,ColorConvert( Random(0,255,1)+256*Random(0,255,1)+256*256*Random(0,255,1) ))
    EndSwitch
WEnd

Func ColorConvert($iColor)
  Return BitOR(BitAND($iColor, 0x00FF00), BitShift(BitAND($iColor, 0x0000FF), -16), BitShift(BitAND($iColor, 0xFF0000), 16))
EndFunc

Saludos

2 people like this

Share this post


Link to post
Share on other sites

Danyfirex,

What a clever idea - I love lateral thinking!

You could also pass a required colour by using another label:

Program 1:

#include <GUIConstantsEx.au3>

Global $aColours[] = [0xFF0000, 0x00FF00, 0x0000FF], $iColour



$hGUI = GUICreate("Program 1", 200, 200, 100, 100)

$cButton = GUICtrlCreateButton("Change colour", 10, 10, 80, 30)

GUIStartGroup()

$cRadio_Red = GUICtrlCreateRadio("Red", 10, 50, 100, 20)
$cRadio_Grn = GUICtrlCreateRadio("Green", 10, 70, 100, 20)
$cRadio_Blue = GUICtrlCreateRadio("Blue", 10, 90, 100, 20)

GUIStartgroup()

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cButton

            For $i = 0 To 2
                If GUICtrlRead($cRadio_Red + $i) = $GUI_CHECKED Then
                    $iColour = $aColours[$i]
                    ExitLoop

                EndIf

            Next
            Local $hWin=WinGetHandle("[TITLE:Program 2]")
            ControlSetText($hWin, "", "Static2", String($iColour))
            ControlClick($hWin,"","Button1")
        EndSwitch



WEnd

Program 2:

#include <GUIConstantsEx.au3>

$hGUI = GUICreate("Program 2", 200, 200, 400, 200)

$cLabel = GUICtrlCreateLabel("", 10, 10, 180, 80)

$cColour = GUICtrlCreateLabel("", 10, 100, 180, 20)

$cButton = GUICtrlCreateButton("", 10, 150, 80, 30)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cButton

            $iColour = Number(GUICtrlRead($cColour))
            GUICtrlSetBkColor($cLabel, $iColour)
            GUICtrlSetData($cColour, "Done")
    EndSwitch

WEnd

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

Exactly @Melba23 or even Create a Dummy Edit/Iput to set a long structured date that you can interpret acording your needs.

 

Saludos

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