Jump to content

Input Controls in Child Windows


fett8802
 Share

Recommended Posts

Hello,

I'm running into a problem with a program I'm writing for my workplace. The main program operates as a sort of 'hub'. It has many Menu based windows that open as child windows within the 'hub' of the main program. Think of it like Photoshop's child windows, only the windows are restricted to the area inside of the 'hub'.

All of my child windows have several controls, input boxes, combo boxes, date and time pickers, buttons, etc. When I click the child window, first of all it doesn't activate, and secondly, all of the controls work just fine except for the input boxes.

I can minimize or close each child window. I can change the combo box selection, select a date and time,and press a button (which activates it's OnEvent function), however, I can not input anything in the input controls. The controls won't take a mouse click. However, if I tab over from a button, I can input text.

If I remove the $WM_CHILD from the window's style, all controls work perfectly fine. As I've searched over the forum, it seems like one can not active both windows at once (although other Windows based programs can and do). I'm truly hoping there is a work around because otherwise, what is the point of child windows?

Any help?

Thanks!

- Fett

Edited by fett8802
[sub]My UDF[/sub][sub] - Basics and Time extensions. Great for those new at AutoIt, also contains some powerful time extensions for pros.[/sub][sub]ScrabbleIt[/sub][sub] - Scrabble done in pure AutoIt. (In Progress)[/sub][sub]Nerd Party Extreme | My Portfolio | [email="fett8802@gmail.com"]Contact Me[/email][/sub]
Link to comment
Share on other sites

  • Moderators

fett8802,

it seems like one can not active both windows at once (although other Windows based programs can and do)

No they do not - only a single window can be active within Windows at any one time. But you can keep several windows responsive at the same time - see the Managing Multiple GUIs tutorial in the Wiki to see how. ;)

Can you post a simple reproducer script to show the problem with the inputs? That is something I do not understand. :graduated:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

Melba,

I had read over that Wiki, but it mostly talks about MessageLoop mode, whereas I use OnEvent. Anyway, I removed most of the functionality and all of the proprietary stuff, but this code will replicate the issue. To see the issue, navigate to Program Commands -> Test and observe the child window that opens. Notice that all controls in the window are responsive except for the input control. If you press 'Create Command String' you'll see that the Input control will accept input from other sources (GuiCtrlSetData).

Here's the code:

#include <Array.au3>
#include <Date.au3>                   ;For use with the Time of Day gui
#include <GUIConstantsEx.au3>
#include <GuiDateTimePicker.au3>                  ;For use with the Time of Day gui
#include <GuiEdit.au3>                   ;For use with the Input Controls
#include <GuiStatusBar.au3>                 ;For use with the Status Bar
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
; #MAIN GUI# ====================================================================================================================
#Region
$gMain = GUICreate("Test Command Builder", 651, 451, 232, 191, BitOR($WS_MAXIMIZEBOX,$WS_MINIMIZEBOX,$WS_SIZEBOX,$WS_THICKFRAME,$WS_SYSMENU,$WS_CAPTION,$WS_OVERLAPPEDWINDOW,$WS_TILEDWINDOW,$WS_POPUP,$WS_POPUPWINDOW,$WS_GROUP,$WS_TABSTOP,$WS_BORDER,$WS_CLIPSIBLINGS))
GUISetOnEvent($GUI_EVENT_CLOSE, "wClose")
$mFile = GUICtrlCreateMenu("&File")
$mFileExit = GUICtrlCreateMenuItem("&Exit" & @TAB & "         Esc", $mFile)
GUICtrlSetOnEvent(-1, "wClose")
$mOptions = GUICtrlCreateMenu("&Options")
$mProgram = GUICtrlCreateMenu("&Program Commands")
$mProgramAccess = GUICtrlCreateMenuItem("Test" & @TAB & "         Ctrl+Alt+X", $mProgram)
GUICtrlSetOnEvent(-1, "mProgram")
$mWindow = GUICtrlCreateMenu("&Window")
$mWindowCascade = GUICtrlCreateMenuItem("&Cascade" & @TAB & "         F3", $mWindow)
GUICtrlSetOnEvent(-1, "mWindow")
        GUICtrlSetState(-1, $GUI_DISABLE)
$mWindowCloseAll = GUICtrlCreateMenuItem("Close All" & @TAB & "       F4", $mWindow)
GUICtrlSetOnEvent(-1, "mWindow")
        GUICtrlSetState(-1, $GUI_DISABLE)
$mHelp = GUICtrlCreateMenu("&Help")
$mHelpAbout = GUICtrlCreateMenuItem("About" & @TAB & "        F2", $mHelp)
GUICtrlSetOnEvent(-1, "mHelp")
        GUICtrlSetState(-1, $GUI_DISABLE)
$mHelpHelp = GUICtrlCreateMenuItem("Help" & @TAB & "          F1", $mHelp)
GUICtrlSetOnEvent(-1, "mHelp")
        GUICtrlSetState(-1, $GUI_DISABLE)
Dim $gMain_AccelTable[47][2] = [["!+{BS}", $mFileExit],["^!x", $mProgramAccess]]
GUISetAccelerators($gMain_AccelTable)
$sbMain = _GUICtrlStatusBar_Create($gMain, -1, "", $SBARS_SIZEGRIP)
Dim $sbMain_PartsWidth[3] = [120, 240, -1]
_GUICtrlStatusBar_SetParts($sbMain, $sbMain_PartsWidth)
_GUICtrlStatusBar_SetText($sbMain, @TAB & "9/15/2011 1:39 PM", 0)
  _GUICtrlStatusBar_SetText($sbMain, @TAB & "Current Window", 1)
   _GUICtrlStatusBar_SetText($sbMain, "Not Connected", 2)
GUIRegisterMsg($WM_SIZE, "wSize")                 ;Set the windows message "WM_SIZE" to trigger the function "WM_SIZE"
GUISetState(@SW_SHOW)
#EndRegion
; ===============================================================================================================================
; #TIME OF DAY GUI# =============================================================================================================
#Region
$gTime = GUICreate("Time of Day", 385, 170, 2, 2, BitOR($WS_CAPTION,$WS_CHILD,$WS_MINIMIZEBOX,$WS_SYSMENU), "", $gMain)
GUISetOnEvent($GUI_EVENT_CLOSE, "wClose")
$gTimeString = GUICtrlCreateGroup("Command String", 8, 8, 137, 41)
$Label1 = GUICtrlCreateLabel("'proprietary'", 23, 25, 109, 17)
$gTimeTime = GUICtrlCreateGroup("Date and Time", 152, 8, 225, 89)
$dtDateTime = _GUICtrlDTP_Create($gTime, 168, 32, 193, 21)
  _GUICtrlDTP_SetFormat($dtDateTime, "ddd MMM dd, yyyy hh:mm:ss ttt")
$lTimeGMT = GUICtrlCreateLabel("Hours after GMT:", 168, 64, 86, 17)
$cbTimeGMT = GUICtrlCreateCombo("00", 320, 61, 41, 25)
GUICtrlSetData(-1, "01|02|03|04|05|06|07|08|09|10|11|12|13|14|15|16|17|18|19|20|21|22|23")
$bTimeGetTime = GUICtrlCreateButton("Create Command String", 8, 64, 137, 25, $WS_GROUP)
GUICtrlSetOnEvent(-1, "bCmd")
$iTimeCmd = GUICtrlCreateInput("", 8, 104, 369, 21)
$bTimeCmd = GUICtrlCreateButton("Send Command", 8, 136, 369, 25)
GUICtrlSetOnEvent(-1, "bCmd")
#EndRegion
; ===============================================================================================================================
While 1
Sleep(1000)
WEnd

Func bCmd()
If @GUI_CtrlId = $bTimeGetTime Then
  GUICtrlSetData($iTimeCmd, "Proprietary String Goes Here")
EndIf
EndFunc
Func mHelp()
EndFunc
Func mOptions()
EndFunc
Func mPanel()
EndFunc
Func mProgram()
If @GUI_CtrlId = $mProgramAccess Then GUISetState(@SW_SHOW, $gTime)
EndFunc
Func mWindow()
EndFunc
Func wClose()
Switch @GUI_WINHANDLE ; See which GUI sent the CLOSE message
        Case $gTime
            GUISetState(@SW_HIDE, $gTime)
  Case $gMain
   _GUICtrlDTP_Destroy($dtDateTime)
   Exit
    EndSwitch
EndFunc
Func wSize($hWnd, $iMsg, $iwParam, $ilParam)
$aSizes = WinGetPos("Test Command Builder","")            ;Get the size of the program window
If $aSizes[2] < 659 Then $aSizes[2] = 659              ;If just the width is smaller than allowed, then set the minimum size for width
If $aSizes[3] < 485 Then $aSizes[3] = 485              ;If just the height is smaller than allowed, then set the minimum size for height
WinMove("Test Command Builder","", $aSizes[0], $aSizes[1], $aSizes[2], $aSizes[3])   ;Move the window to the new settings
  _GUICtrlStatusBar_Resize($sbMain)              ;Resize the Status Bar
    Return $GUI_RUNDEFMSG                   ;Returns $GUI_RUNDEFMSG
EndFunc   ;==>wSize

Edit: Sorry it's not very organized or pretty, I haven't commented or optimized it yet.

Thanks very much!

-Fett

Edited by fett8802
[sub]My UDF[/sub][sub] - Basics and Time extensions. Great for those new at AutoIt, also contains some powerful time extensions for pros.[/sub][sub]ScrabbleIt[/sub][sub] - Scrabble done in pure AutoIt. (In Progress)[/sub][sub]Nerd Party Extreme | My Portfolio | [email="fett8802@gmail.com"]Contact Me[/email][/sub]
Link to comment
Share on other sites

  • Moderators

fett8802,

I have never really liked using $WS_CHILD - I find it gives too many problems, as you have discovered. ;)

So I tend to use _WinAPI_SetParent to get the correct parent/child relationship. Take a look at this modified version of your script - the input works and you can test it by pressing the "Send Command" button:

#include <GUIConstantsEx.au3>
#include <Date.au3>                   ;For use with the Time of Day gui
#include <GUIConstantsEx.au3>
#include <GuiDateTimePicker.au3>                  ;For use with the Time of Day gui
#include <GuiEdit.au3>                   ;For use with the Input Controls
#include <GuiStatusBar.au3>                 ;For use with the Status Bar
#include <WindowsConstants.au3>
#include <WinAPI.au3>

Opt("GUIOnEventMode", 1)

Global $gTime

$gMain = GUICreate("Test", 500, 500)
GUISetOnEvent($GUI_EVENT_CLOSE, "wClose")
$mFile = GUICtrlCreateMenu("&File")
$mFileExit = GUICtrlCreateMenuItem("&Exit" & @TAB & "         Esc", $mFile)
GUICtrlSetOnEvent(-1, "wClose")
$mOptions = GUICtrlCreateMenu("&Options")
$mProgram = GUICtrlCreateMenu("&Program Commands")
$mProgramAccess = GUICtrlCreateMenuItem("Test" & @TAB & "         Ctrl+Alt+X", $mProgram)
GUICtrlSetOnEvent(-1, "mProgram")
$mWindow = GUICtrlCreateMenu("&Window")
$mWindowCascade = GUICtrlCreateMenuItem("&Cascade" & @TAB & "         F3", $mWindow)
GUICtrlSetOnEvent(-1, "mWindow")
GUICtrlSetState(-1, $GUI_DISABLE)
$mWindowCloseAll = GUICtrlCreateMenuItem("Close All" & @TAB & "       F4", $mWindow)
GUICtrlSetOnEvent(-1, "mWindow")
GUICtrlSetState(-1, $GUI_DISABLE)
$mHelp = GUICtrlCreateMenu("&Help")
$mHelpAbout = GUICtrlCreateMenuItem("About" & @TAB & "        F2", $mHelp)
GUICtrlSetOnEvent(-1, "mHelp")
GUICtrlSetState(-1, $GUI_DISABLE)
$mHelpHelp = GUICtrlCreateMenuItem("Help" & @TAB & "          F1", $mHelp)
GUICtrlSetOnEvent(-1, "mHelp")
GUICtrlSetState(-1, $GUI_DISABLE)
Dim $gMain_AccelTable[47][2] = [["!+{BS}", $mFileExit],["^!x", $mProgramAccess]]
GUISetAccelerators($gMain_AccelTable)
$sbMain = _GUICtrlStatusBar_Create($gMain, -1, "", $SBARS_SIZEGRIP)
Dim $sbMain_PartsWidth[3] = [120, 240, -1]
_GUICtrlStatusBar_SetParts($sbMain, $sbMain_PartsWidth)
_GUICtrlStatusBar_SetText($sbMain, @TAB & "9/15/2011 1:39 PM", 0)
_GUICtrlStatusBar_SetText($sbMain, @TAB & "Current Window", 1)
_GUICtrlStatusBar_SetText($sbMain, "Not Connected", 2)
GUIRegisterMsg($WM_SIZE, "wSize") ;Set the windows message "WM_SIZE" to trigger the function "WM_SIZE"
GUISetState(@SW_SHOW)

While 1
    Sleep(10)
WEnd

Func mProgram()
    If @GUI_CtrlId = $mProgramAccess Then
        $gTime = GUICreate("Time of Day", 385, 170, 2, 2)
        GUISetOnEvent($GUI_EVENT_CLOSE, "wClose")

        ; Set parent
        _WinAPI_SetParent($gTime, $gMain) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

        $gTimeString = GUICtrlCreateGroup("Command String", 8, 8, 137, 41)
        $Label1 = GUICtrlCreateLabel("'proprietary'", 23, 25, 109, 17)
        GUICtrlSetBkColor(-1, 0xFF0000)
        $gTimeTime = GUICtrlCreateGroup("Date and Time", 152, 8, 225, 89)
        $dtDateTime = _GUICtrlDTP_Create($gTime, 168, 32, 193, 21)
        _GUICtrlDTP_SetFormat($dtDateTime, "ddd MMM dd, yyyy hh:mm:ss ttt")
        $lTimeGMT = GUICtrlCreateLabel("Hours after GMT:", 168, 64, 86, 17)
        GUICtrlSetBkColor(-1, 0x00FF00)
        $cbTimeGMT = GUICtrlCreateCombo("00", 320, 61, 41, 25)
        GUICtrlSetData(-1, "01|02|03|04|05|06|07|08|09|10|11|12|13|14|15|16|17|18|19|20|21|22|23")
        Global $bTimeGetTime = GUICtrlCreateButton("Create Command String", 8, 64, 137, 25, $WS_GROUP)
        GUICtrlSetOnEvent(-1, "bCmd")
        Global $iTimeCmd = GUICtrlCreateInput("", 8, 104, 369, 21)
        Global $bTimeCmd = GUICtrlCreateButton("Send Command", 8, 136, 369, 25)
        GUICtrlSetOnEvent(-1, "bCmd")
        GUISetState()
    EndIf

EndFunc   ;==>mProgram

Func wClose()
    Switch @GUI_WinHandle ; See which GUI sent the CLOSE message
        Case $gTime
            GUIDelete($gTime)
            WinActivate($gMain)
        Case $gMain
            Exit
    EndSwitch
EndFunc   ;==>wClose

Func bCmd()
    Switch @GUI_CtrlId
        Case $bTimeGetTime
            GUICtrlSetData($iTimeCmd, "Proprietary String Goes Here")
        Case $bTimeCmd
            ConsoleWrite(GUICtrlRead($iTimeCmd) & @CRLF)
    EndSwitch
EndFunc   ;==>bCmd
Func mHelp()
EndFunc   ;==>mHelp
Func mOptions()
EndFunc   ;==>mOptions
Func mPanel()
EndFunc   ;==>mPanel
Func mWindow()
EndFunc   ;==>mWindow
Func wSize($hWnd, $iMsg, $iwParam, $ilParam)
    $aSizes = WinGetPos("Test Command Builder", "") ;Get the size of the program window
    If $aSizes[2] < 659 Then $aSizes[2] = 659 ;If just the width is smaller than allowed, then set the minimum size for width
    If $aSizes[3] < 485 Then $aSizes[3] = 485 ;If just the height is smaller than allowed, then set the minimum size for height
    WinMove("Test Command Builder", "", $aSizes[0], $aSizes[1], $aSizes[2], $aSizes[3]) ;Move the window to the new settings
    _GUICtrlStatusBar_Resize($sbMain) ;Resize the Status Bar
    Return $GUI_RUNDEFMSG ;Returns $GUI_RUNDEFMSG
EndFunc   ;==>wSize

Any help? :graduated:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

Melba,

That will do what I want functionally! Thanks a lot! I guess while I have you here, is there any way to force the parent window's toolbar to still show active? I use several programs here at work that have setups like this and the child window is shown "Active" as is the parent window. Functionally, this works great and I have no problems with it. It would just really add to the aesthetic of the program to keep the parents window looking active.

Anyway, thanks for your help on this, Melba!

-Fett

[sub]My UDF[/sub][sub] - Basics and Time extensions. Great for those new at AutoIt, also contains some powerful time extensions for pros.[/sub][sub]ScrabbleIt[/sub][sub] - Scrabble done in pure AutoIt. (In Progress)[/sub][sub]Nerd Party Extreme | My Portfolio | [email="fett8802@gmail.com"]Contact Me[/email][/sub]
Link to comment
Share on other sites

  • Moderators

fett8802,

Those apps must be using custom controls. As I explained earlier there is no way I (or anyone else on the forum - it has been discussed a couple of times since I have been here) know of keeping 2 standard Windows GUIs active at the same time. I am pretty sure that it cannot be done - certainly not in AutoIt. :graduated:

My only suggestion is to try and detect which GUI is under the mouse and use WinActivate to make it the active one. I will have a look at what I can produce along those lines. ;)

M23

Edit: Easier than I thought - does this help (look for the <<<<<<< lines):

#include <GUIConstantsEx.au3>
#include <Date.au3>                   ;For use with the Time of Day gui
#include <GUIConstantsEx.au3>
#include <GuiDateTimePicker.au3>                  ;For use with the Time of Day gui
#include <GuiEdit.au3>                   ;For use with the Input Controls
#include <GuiStatusBar.au3>                 ;For use with the Status Bar
#include <WindowsConstants.au3>
#include <WinAPI.au3>

Opt("GUIOnEventMode", 1)

Global $gTime

$gMain = GUICreate("Test", 500, 500)
GUISetOnEvent($GUI_EVENT_CLOSE, "wClose")
ConsoleWrite("Main: " & $gMain & @CRLF)
$mFile = GUICtrlCreateMenu("&File")
$mFileExit = GUICtrlCreateMenuItem("&Exit" & @TAB & "         Esc", $mFile)
GUICtrlSetOnEvent(-1, "wClose")
$mOptions = GUICtrlCreateMenu("&Options")
$mProgram = GUICtrlCreateMenu("&Program Commands")
$mProgramAccess = GUICtrlCreateMenuItem("Test" & @TAB & "         Ctrl+Alt+X", $mProgram)
GUICtrlSetOnEvent(-1, "mProgram")
$mWindow = GUICtrlCreateMenu("&Window")
$mWindowCascade = GUICtrlCreateMenuItem("&Cascade" & @TAB & "         F3", $mWindow)
GUICtrlSetOnEvent(-1, "mWindow")
GUICtrlSetState(-1, $GUI_DISABLE)
$mWindowCloseAll = GUICtrlCreateMenuItem("Close All" & @TAB & "       F4", $mWindow)
GUICtrlSetOnEvent(-1, "mWindow")
GUICtrlSetState(-1, $GUI_DISABLE)
$mHelp = GUICtrlCreateMenu("&Help")
$mHelpAbout = GUICtrlCreateMenuItem("About" & @TAB & "        F2", $mHelp)
GUICtrlSetOnEvent(-1, "mHelp")
GUICtrlSetState(-1, $GUI_DISABLE)
$mHelpHelp = GUICtrlCreateMenuItem("Help" & @TAB & "          F1", $mHelp)
GUICtrlSetOnEvent(-1, "mHelp")
GUICtrlSetState(-1, $GUI_DISABLE)
Dim $gMain_AccelTable[47][2] = [["!+{BS}", $mFileExit],["^!x", $mProgramAccess]]
GUISetAccelerators($gMain_AccelTable)
$sbMain = _GUICtrlStatusBar_Create($gMain, -1, "", $SBARS_SIZEGRIP)
Dim $sbMain_PartsWidth[3] = [120, 240, -1]
_GUICtrlStatusBar_SetParts($sbMain, $sbMain_PartsWidth)
_GUICtrlStatusBar_SetText($sbMain, @TAB & "9/15/2011 1:39 PM", 0)
_GUICtrlStatusBar_SetText($sbMain, @TAB & "Current Window", 1)
_GUICtrlStatusBar_SetText($sbMain, "Not Connected", 2)
GUIRegisterMsg($WM_SIZE, "wSize") ;Set the windows message "WM_SIZE" to trigger the function "WM_SIZE"
GUISetState(@SW_SHOW)

AdlibRegister("_Focus"); <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

While 1
    Sleep(10)
WEnd

Func mProgram()
    If @GUI_CtrlId = $mProgramAccess Then
        $gTime = GUICreate("Time of Day", 385, 170, 2, 2)
        GUISetOnEvent($GUI_EVENT_CLOSE, "wClose")

        ConsoleWrite("Child: " & $gTime & @CRLF)

        ; Set parent
        _WinAPI_SetParent($gTime, $gMain) 

        $gTimeString = GUICtrlCreateGroup("Command String", 8, 8, 137, 41)
        $Label1 = GUICtrlCreateLabel("'proprietary'", 23, 25, 109, 17)
        GUICtrlSetBkColor(-1, 0xFF0000)
        $gTimeTime = GUICtrlCreateGroup("Date and Time", 152, 8, 225, 89)
        $dtDateTime = _GUICtrlDTP_Create($gTime, 168, 32, 193, 21)
        _GUICtrlDTP_SetFormat($dtDateTime, "ddd MMM dd, yyyy hh:mm:ss ttt")
        $lTimeGMT = GUICtrlCreateLabel("Hours after GMT:", 168, 64, 86, 17)
        GUICtrlSetBkColor(-1, 0x00FF00)
        $cbTimeGMT = GUICtrlCreateCombo("00", 320, 61, 41, 25)
        GUICtrlSetData(-1, "01|02|03|04|05|06|07|08|09|10|11|12|13|14|15|16|17|18|19|20|21|22|23")
        Global $bTimeGetTime = GUICtrlCreateButton("Create Command String", 8, 64, 137, 25, $WS_GROUP)
        GUICtrlSetOnEvent(-1, "bCmd")
        Global $iTimeCmd = GUICtrlCreateInput("", 8, 104, 369, 21)
        Global $bTimeCmd = GUICtrlCreateButton("Send Command", 8, 136, 369, 25)
        GUICtrlSetOnEvent(-1, "bCmd")
        GUISetState()
    EndIf

EndFunc   ;==>mProgram

Func wClose()
    Switch @GUI_WinHandle ; See which GUI sent the CLOSE message
        Case $gTime
            GUIDelete($gTime)
            WinActivate($gMain)
        Case $gMain
            Exit
    EndSwitch
EndFunc   ;==>wClose

Func bCmd()
    Switch @GUI_CtrlId
        Case $bTimeGetTime
            GUICtrlSetData($iTimeCmd, "Proprietary String Goes Here")
        Case $bTimeCmd
            ConsoleWrite(GUICtrlRead($iTimeCmd) & @CRLF)
    EndSwitch
EndFunc   ;==>bCmd
Func mHelp()
EndFunc   ;==>mHelp
Func mOptions()
EndFunc   ;==>mOptions
Func mPanel()
EndFunc   ;==>mPanel
Func mWindow()
EndFunc   ;==>mWindow
Func wSize($hWnd, $iMsg, $iwParam, $ilParam)
    $aSizes = WinGetPos("Test Command Builder", "") ;Get the size of the program window
    If $aSizes[2] < 659 Then $aSizes[2] = 659 ;If just the width is smaller than allowed, then set the minimum size for width
    If $aSizes[3] < 485 Then $aSizes[3] = 485 ;If just the height is smaller than allowed, then set the minimum size for height
    WinMove("Test Command Builder", "", $aSizes[0], $aSizes[1], $aSizes[2], $aSizes[3]) ;Move the window to the new settings
    _GUICtrlStatusBar_Resize($sbMain) ;Resize the Status Bar
    Return $GUI_RUNDEFMSG ;Returns $GUI_RUNDEFMSG
EndFunc   ;==>wSize

Func _Focus(); <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    If @AutoItX64 Then
        Local $tPoint = DllStructCreate("int X;int Y")
        DllStructSetData ( $tPoint, "X", MouseGetPos(0))
        DllStructSetData ( $tPoint, "Y", MouseGetPos(1))
        Local $tPoint64 = DllStructCreate("int64", DllStructGetPtr($tPoint))
        Local $aHwnd = DllCall("user32.dll", "hwnd", "WindowFromPoint", "int64", DllStructGetData($tPoint64, 1))
    Else
        Local $aHwnd = DllCall("user32.dll", "hwnd", "WindowFromPoint", "uint", MouseGetPos(0), "uint", MouseGetPos(1))
    EndIf
    Switch $aHwnd[0]
        Case $gMain, $gTime
            WinActivate($aHwnd[0])
    EndSwitch
EndFunc

Edit: Small change to WinActivate code to keep it to just our GUIs! :)

Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

... It would just really add to the aesthetic of the program to keep the parents window looking active.

..

-Fett

I would like to kno whow to do that as well. I am sure (but maybe wrong) that I saw some code in the forums within the last 2 or 3 years years that showed how to do that but I have never been able to find it. I find it a bit annoying that activating a child window sets the parent border as inactive so if you find out, and remember this post, please let me know.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

I knew this was done with a non-client area message.

finally found it in old Auto3Lib code by PaulIA

requires additional msg handling for setting active/inactive state when app window loses/gains focus (WM_ACTIVATEAPP)

GUIRegisterMsg($WM_NCACTIVATE, "_WM_NCACTIVATE")
Func _WM_NCACTIVATE($hWnd, $Msg, $wParam, $lParam)
#forceref $hWnd, $Msg, $wParam, $lParam
Return 1
EndFunc   ;==>_WM_NCACTIVATE

I see fascists...

Link to comment
Share on other sites

  • Moderators

rover,

Bravo! :graduated:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

I'm probably missing the obvious/correct/best practice way of doing this,

but here is a kludged version of the OPs script, with additional message handling to set window state.

The code has an issue with the main gui occasionally not being painted active on restore from a minimize to taskbar using the main gui minimize button.

#include <GUIConstantsEx.au3>
#include <Date.au3>                ;For use with the Time of Day gui
#include <GUIConstantsEx.au3>
#include <GuiDateTimePicker.au3>                  ;For use with the Time of Day gui
#include <GuiEdit.au3>                 ;For use with the Input Controls
#include <GuiStatusBar.au3>              ;For use with the Status Bar
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <Constants.au3>
Opt("GUIOnEventMode", 1)
;Opt('MustDeclareVars', 1)
Global $fActive = True
Global $gTime
$gMain = GUICreate("Test", 500, 500)
GUISetOnEvent($GUI_EVENT_CLOSE, "wClose", $gMain)
GUISetOnEvent($GUI_EVENT_RESTORE, "Restore", $gMain)
$mFile = GUICtrlCreateMenu("&File")
$mFileExit = GUICtrlCreateMenuItem("&Exit" & @TAB & "        Esc", $mFile)
GUICtrlSetOnEvent(-1, "wClose")
$mOptions = GUICtrlCreateMenu("&Options")
$mProgram = GUICtrlCreateMenu("&Program Commands")
$mProgramAccess = GUICtrlCreateMenuItem("Test" & @TAB & "        Ctrl+Alt+X", $mProgram)
GUICtrlSetOnEvent(-1, "mProgram")
$mWindow = GUICtrlCreateMenu("&Window")
$mWindowCascade = GUICtrlCreateMenuItem("&Cascade" & @TAB & "        F3", $mWindow)
GUICtrlSetOnEvent(-1, "mWindow")
GUICtrlSetState(-1, $GUI_DISABLE)
$mWindowCloseAll = GUICtrlCreateMenuItem("Close All" & @TAB & "    F4", $mWindow)
GUICtrlSetOnEvent(-1, "mWindow")
GUICtrlSetState(-1, $GUI_DISABLE)
$mHelp = GUICtrlCreateMenu("&Help")
$mHelpAbout = GUICtrlCreateMenuItem("About" & @TAB & "      F2", $mHelp)
GUICtrlSetOnEvent(-1, "mHelp")
GUICtrlSetState(-1, $GUI_DISABLE)
$mHelpHelp = GUICtrlCreateMenuItem("Help" & @TAB & "          F1", $mHelp)
GUICtrlSetOnEvent(-1, "mHelp")
GUICtrlSetState(-1, $GUI_DISABLE)
Dim $gMain_AccelTable[47][2] = [["!+{BS}", $mFileExit],["^!x", $mProgramAccess]]
GUISetAccelerators($gMain_AccelTable)
$sbMain = _GUICtrlStatusBar_Create($gMain, -1, "", $SBARS_SIZEGRIP)
Dim $sbMain_PartsWidth[3] = [120, 240, -1]
_GUICtrlStatusBar_SetParts($sbMain, $sbMain_PartsWidth)
_GUICtrlStatusBar_SetText($sbMain, @TAB & "9/15/2011 1:39 PM", 0)
_GUICtrlStatusBar_SetText($sbMain, @TAB & "Current Window", 1)
_GUICtrlStatusBar_SetText($sbMain, "Not Connected", 2)
;GUIRegisterMsg($WM_SIZE, "wSize") ;Set the windows message "WM_SIZE" to trigger the function "WM_SIZE"
GUIRegisterMsg($WM_NCACTIVATE, "_WM_NCACTIVATE")
GUIRegisterMsg($WM_ACTIVATEAPP, "_WM_ACTIVATEAPP")
GUISetState(@SW_SHOW)
While 1
    Sleep(10)
WEnd
Func mProgram()
    If @GUI_CtrlId = $mProgramAccess Then
  If IsHWnd($gTime) Then Return
        $gTime = GUICreate("Time of Day", 385, 170, 2, 2)
        GUISetOnEvent($GUI_EVENT_CLOSE, "wClose", $gTime)
  GUISetOnEvent($GUI_EVENT_RESTORE, "Restore", $gTime)
        ; Set parent
        _WinAPI_SetParent($gTime, $gMain) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
        $gTimeString = GUICtrlCreateGroup("Command String", 8, 8, 137, 41)
        $Label1 = GUICtrlCreateLabel("'proprietary'", 23, 25, 109, 17)
        GUICtrlSetBkColor(-1, 0xFF0000)
        $gTimeTime = GUICtrlCreateGroup("Date and Time", 152, 8, 225, 89)
        $dtDateTime = _GUICtrlDTP_Create($gTime, 168, 32, 193, 21)
        _GUICtrlDTP_SetFormat($dtDateTime, "ddd MMM dd, yyyy hh:mm:ss ttt")
        $lTimeGMT = GUICtrlCreateLabel("Hours after GMT:", 168, 64, 86, 17)
        GUICtrlSetBkColor(-1, 0x00FF00)
        $cbTimeGMT = GUICtrlCreateCombo("00", 320, 61, 41, 25)
        GUICtrlSetData(-1, "01|02|03|04|05|06|07|08|09|10|11|12|13|14|15|16|17|18|19|20|21|22|23")
        Global $bTimeGetTime = GUICtrlCreateButton("Create Command String", 8, 64, 137, 25, $WS_GROUP)
        GUICtrlSetOnEvent(-1, "bCmd")
        Global $iTimeCmd = GUICtrlCreateInput("", 8, 104, 369, 21)
        Global $bTimeCmd = GUICtrlCreateButton("Send Command", 8, 136, 369, 25)
        GUICtrlSetOnEvent(-1, "bCmd")
        GUISetState()
    EndIf
EndFunc   ;==>mProgram
Func wClose()
    Switch @GUI_WinHandle ; See which GUI sent the CLOSE message
        Case $gTime
            GUIDelete($gTime)
            WinActivate($gMain)
        Case $gMain
            Exit
    EndSwitch
EndFunc   ;==>wClose
Func bCmd()
    Switch @GUI_CtrlId
        Case $bTimeGetTime
            GUICtrlSetData($iTimeCmd, "Proprietary String Goes Here")
        Case $bTimeCmd
            ConsoleWrite(GUICtrlRead($iTimeCmd) & @CRLF)
    EndSwitch
EndFunc   ;==>bCmd
Func mHelp()
EndFunc   ;==>mHelp
Func mOptions()
EndFunc   ;==>mOptions
Func mPanel()
EndFunc   ;==>mPanel
Func mWindow()
EndFunc   ;==>mWindow
Func wSize($hWnd, $iMsg, $iwParam, $ilParam)
    $aSizes = WinGetPos("Test Command Builder", "") ;Get the size of the program window
    If $aSizes[2] < 659 Then $aSizes[2] = 659 ;If just the width is smaller than allowed, then set the minimum size for width
    If $aSizes[3] < 485 Then $aSizes[3] = 485 ;If just the height is smaller than allowed, then set the minimum size for height
    WinMove("Test Command Builder", "", $aSizes[0], $aSizes[1], $aSizes[2], $aSizes[3]) ;Move the window to the new settings
    _GUICtrlStatusBar_Resize($sbMain) ;Resize the Status Bar
    Return $GUI_RUNDEFMSG ;Returns $GUI_RUNDEFMSG
EndFunc   ;==>wSize
Func Restore()
Local $iFlags = BitOR($SWP_NOMOVE, $SWP_NOSIZE, $SWP_FRAMECHANGED)
If IsHWnd($gTime) Then _WinAPI_SetWindowPos($gTime, $HWND_TOP, 0, 0, 0, 0, $iFlags)
_WinAPI_SetWindowPos($gMain, $HWND_TOP, 0, 0, 0, 0, $iFlags)
EndFunc

Func _WM_NCACTIVATE($hWnd, $Msg, $wParam, $lParam)
;ConsoleWrite('-WM_NCACTIVATE $wParam(' & $wParam & ') : $lParam = ' & $lParam & @CRLF)
#forceref $hWnd, $Msg, $wParam, $lParam
If $fActive Then Return 1
Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_NCACTIVATE
Func _WM_ACTIVATEAPP($hWnd, $Msg, $wParam, $lParam)
#forceref $hWnd, $Msg, $wParam, $lParam
;ConsoleWrite('+WM_ACTIVATEAPP $wParam(' & $wParam & ') : $lParam = ' & $lParam & @CRLF)
$fActive = $wParam
If $wParam Then
  Local $iFlags = BitOR($SWP_NOMOVE, $SWP_NOSIZE, $SWP_FRAMECHANGED)
  _WinAPI_SetWindowPos($hWnd, $HWND_TOP, 0, 0, 0, 0, $iFlags)
  If IsHWnd($gTime) Then _WinAPI_SetWindowPos($gTime, $HWND_TOP, 0, 0, 0, 0, $iFlags)
Else
  If IsHWnd($gTime) Then _WinAPI_PostMessage($gTime, $WM_NCACTIVATE, 0, 0)
  _WinAPI_PostMessage($hWnd, $WM_NCACTIVATE, 0, 0)
EndIf
Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_NCACTIVATE

I see fascists...

Link to comment
Share on other sites

I'm probably missing the obvious/correct/best practice way of doing this,

but here is a kludged version of the OPs script, with additional message handling to set window state.

The code has an issue with the main gui occasionally not being painted active on restore from a minimize to taskbar using the main gui minimize button.

Thanks Rover. :graduated:

I'll play with this but it will take me some time. The application I want to use it for has a parent window which I want to be painted as active when any child windows are active or when it has focus. The child windows are all stand-alone AutoIt exes which are set by the parent to be it's children when they are run so it is a bit long winded changing it all.

Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
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...