Jump to content

Can't set focus to newly created child gui.


Recommended Posts

I have a button that creates a new child gui and when i push it it creates the new child gui behind an already existing child gui.

I would like the newly created child gui to be on top.

Here is my code:

CODE
#include <GUIConstants.au3>

;#include <database.au3>

#include <A3LToolbar.au3>

Global Enum $idNew=1000, $idOpen, $idSave, $idHelp

Dim $mainGui, $viewSpell

; Script Start - Add your code below here

$windowWidth = 800

$windowHeight = 500

$parentGui = GUICreate("Spell Inventory", $windowWidth, $windowHeight, -1,-1, $WS_OVERLAPPEDWINDOW)

GUISetState ()

$dbname = "C:\Documents and Settings\sjraisbe\Desktop\SI\database.mdb"

$tblname = "Spells"

$fldname = "Spell"

;MI = menu item

;-----File Menu-----

$fileMenu = GuiCtrlCreateMenu ("File")

$importMI = GuiCtrlCreateMenuitem ("Import File",$filemenu)

$separator = GuiCtrlCreateMenuitem ("",$filemenu)

$ppOptionsMenu = GuiCtrlCreateMenu ("Print Preview Options",$filemenu)

$separator = GuiCtrlCreateMenuitem ("",$filemenu)

$exitMI = GuiCtrlCreateMenuitem ("Exit",$filemenu)

;-----Tools Menu-----

$toolsMenu = GuiCtrlCreateMenu ("Tools")

$manageSpellbooksMI = GuiCtrlCreateMenuitem ("Manage Spellbooks",$toolsMenu)

$manageSchoolsMI = GuiCtrlCreateMenuitem ("Manage Schools",$toolsMenu)

$manageSpellsMI = GuiCtrlCreateMenuitem ("Manage Spells",$toolsMenu)

$separator = GuiCtrlCreateMenuitem ("",$toolsMenu)

$manageScrollsMI = GuiCtrlCreateMenuitem ("Manage Scrolls",$toolsMenu)

$separator = GuiCtrlCreateMenuitem ("",$toolsMenu)

$searchMI = GuiCtrlCreateMenuitem ("Search",$toolsMenu)

;-----Window Menu-----

$windowMenu = GuiCtrlCreateMenu ("Window")

$tileMI = GuiCtrlCreateMenuitem ("Tile",$windowMenu)

$separator = GuiCtrlCreateMenuitem ("",$windowMenu)

$cascadeMI = GuiCtrlCreateMenuitem ("Cascade",$windowMenu)

;-----About Menu-----

$aboutMenu = GuiCtrlCreateMenu ("About")

$helpTopicsMI = GuiCtrlCreateMenuitem ("Help Topics",$aboutMenu)

$separator = GuiCtrlCreateMenuitem ("",$aboutMenu)

$aboutMI = GuiCtrlCreateMenuitem ("About SI",$aboutMenu)

$toolbar = _CreateMyToolbar($parentGui, $mainGui, $viewSpell)

;WinMove($test2, '', 0, 30, 300, 300)

$width = 200

$height = 200

$child = GUICreate("View Spells", 200, 200, 100, 0, BitOR($WS_OVERLAPPEDWINDOW, $WS_CHILD), Default, $mainGui)

;GUISetBkColor (0x00FF00)

;Opt("GUICoordMode", 2)

$nOk = GUICtrlCreateButton ("OK",$width-48,$height-48,50,50) ; add the button that will close the GUI

GUICtrlSetResizing ($nOk,$GUI_DOCKBOTTOM+$GUI_DOCKSIZE)

GUISetState ()

do

$msg = GUIGetMsg(1)

Select

Case $msg[0] = $GUI_EVENT_CLOSE Or $msg = $exitMI

;Check if user clicked on the close button of the child window

If $msg[1] = $child Then

;Switch to the child window

GUISwitch($child)

;Destroy the child GUI including the controls

GUIDelete()

;$flag = 1

;Check if user clicked on the close button of the parent window

ElseIf $msg[1] = $parentGui Then

;Switch to the parent window

GUISwitch($parentGui)

;Destroy the parent GUI including the controls

GUIDelete()

;Exit the script

Exit

EndIf

Case $msg[0] = $aboutMI

Msgbox(0,"About","Spell Inventory")

Case $msg[0] = $viewSpell

$child2 = GUICreate("View Spell", 200, 200, 150, 50, BitOR($WS_OVERLAPPEDWINDOW, $WS_CHILD), Default, $mainGui)

GUISetState ()

ControlFocus("Spell Inventory", "", "View Spell")

GUISwitch(-1)

Case $msg[0] = $GUI_EVENT_RESIZED or $GUI_EVENT_MAXIMIZE or $GUI_EVENT_RESTORE

_UpdateChildGui($parentGui, $mainGui, $child)

EndSelect

until $msg = $GUI_EVENT_CLOSE

GUIDelete()

Exit

Func _UpdateChildGui($parentGui, $childGui, $childsChild)

$state = WinGetState($childsChild)

$array = WinGetPos($parentGui)

WinMove($childGui, '', 0, 30, ($array[2]-8), ($array[3]-84))

If BitAnd($state, 32) Then

; x, y, width, heighth

WinMove($childsChild, '', -4, -4, $array[2], ($array[3]-76))

EndIf

EndFunc

Func _CreateMyToolbar($parentGui, ByRef $mainGui, ByRef $viewSpell)

$toolbar=GUICreate("toolbar", 800, 30, 0, 0, $WS_CHILD, Default, $parentGui)

GUISetState ()

;~ $hToolbar = _Toolbar_Create($toolbar)

;~ ; Add standard system bitmaps

;~ ;_Toolbar_SetButtonSize($hToolbar, 20, 50)

;~ _Toolbar_AddBitmap($hToolbar, 1, -1, $IDB_STD_LARGE_COLOR)

;~ ; Add buttons

;~ ;_Toolbar_AddButton ($hToolbar, $idNew , $STD_FILENEW )

;~ ;_Toolbar_AddButton ($hToolbar, $idOpen, $STD_FILEOPEN)

;~ _Toolbar_AddButton ($hToolbar, $idSave, $STD_FILENEW)

;~ _Toolbar_AddButtonSep($hToolbar)

;~ _Toolbar_AddButton ($hToolbar, $idHelp, $STD_FILEOPEN)

$viewSpell = GUICtrlCreateButton ("Test", 0,0,50,20)

$width = $windowWidth

$height = $windowHeight - 50

$mainGui=GUICreate("mainGui", $width, $height, 0, 30, $WS_CHILD, Default, $parentGui)

;GUISetBkColor (0x0FFFF)

;GUICtrlCreateButton ("OK",$width-50,$height-50,50,50)

;GUICtrlSetResizing (-1,$GUI_DOCKBOTTOM+$GUI_DOCKSIZE)

GUISetState ()

Return $toolbar

EndFunc

Link to comment
Share on other sites

You'll also notice that the focus doesn't change when you click on the main part of the opposite child window, it only changes when you click on the title bar.

If anyone knows how to fix this that would also be great!

Link to comment
Share on other sites

You'll also notice that the focus doesn't change when you click on the main part of the opposite child window, it only changes when you click on the title bar.

If anyone knows how to fix this that would also be great!

Try this

#include <GUIConstants.au3>
;#include <database.au3>
#include <A3LToolbar.au3>

Global Enum $idNew=1000, $idOpen, $idSave, $idHelp
Dim $mainGui, $viewSpell

; Script Start - Add your code below here
$windowWidth = 800
$windowHeight = 500
$parentGui = GUICreate("Spell Inventory", $windowWidth, $windowHeight, -1,-1, $WS_OVERLAPPEDWINDOW)

GUISetState ()

$dbname = "C:\Documents and Settings\sjraisbe\Desktop\SI\database.mdb"
$tblname = "Spells"
$fldname = "Spell"

;MI = menu item
;-----File Menu-----
$fileMenu = GuiCtrlCreateMenu ("File")
$importMI = GuiCtrlCreateMenuitem ("Import File",$filemenu)
$separator = GuiCtrlCreateMenuitem ("",$filemenu)
$ppOptionsMenu = GuiCtrlCreateMenu ("Print Preview Options",$filemenu)
$separator = GuiCtrlCreateMenuitem ("",$filemenu)
$exitMI = GuiCtrlCreateMenuitem ("Exit",$filemenu)

;-----Tools Menu-----
$toolsMenu = GuiCtrlCreateMenu ("Tools")
$manageSpellbooksMI = GuiCtrlCreateMenuitem ("Manage Spellbooks",$toolsMenu)
$manageSchoolsMI = GuiCtrlCreateMenuitem ("Manage Schools",$toolsMenu)
$manageSpellsMI = GuiCtrlCreateMenuitem ("Manage Spells",$toolsMenu)
$separator = GuiCtrlCreateMenuitem ("",$toolsMenu)
$manageScrollsMI = GuiCtrlCreateMenuitem ("Manage Scrolls",$toolsMenu)
$separator = GuiCtrlCreateMenuitem ("",$toolsMenu)
$searchMI = GuiCtrlCreateMenuitem ("Search",$toolsMenu)

;-----Window Menu-----
$windowMenu = GuiCtrlCreateMenu ("Window")
$tileMI = GuiCtrlCreateMenuitem ("Tile",$windowMenu)
$separator = GuiCtrlCreateMenuitem ("",$windowMenu)
$cascadeMI = GuiCtrlCreateMenuitem ("Cascade",$windowMenu)

;-----About Menu-----
$aboutMenu = GuiCtrlCreateMenu ("About")
$helpTopicsMI = GuiCtrlCreateMenuitem ("Help Topics",$aboutMenu)
$separator = GuiCtrlCreateMenuitem ("",$aboutMenu)
$aboutMI = GuiCtrlCreateMenuitem ("About SI",$aboutMenu)

$toolbar = _CreateMyToolbar($parentGui, $mainGui, $viewSpell)

;WinMove($test2, '', 0, 30, 300, 300)
$width = 200
$height = 200
$child = GUICreate("View Spells", 200, 200, 100, 20, $WS_CAPTION); BitOR($WS_OVERLAPPEDWINDOW, $WS_CHILD,$WS_CLIPSIBLINGS),Default, $mainGui);BitOR($WS_OVERLAPPEDWINDOW, $WS_CHILD), Default, $mainGui)
;GUISetBkColor (0x00FF00)
;Opt("GUICoordMode", 2)
$nOk = GUICtrlCreateButton ("OK",$width-48,$height-48,50,50) ; add the button that will close the GUI
GUICtrlSetResizing ($nOk,$GUI_DOCKBOTTOM+$GUI_DOCKSIZE)
GUISetState ()
DllCall("user32.dll", "int", "SetParent", "hwnd", WinGetHandle($child), "hwnd", WinGetHandle($parentGui))


do
$msg = GUIGetMsg(1)

Select
Case $msg[0] = $GUI_EVENT_CLOSE Or $msg = $exitMI
;Check if user clicked on the close button of the child window
If $msg[1] = $child Then
;Switch to the child window
GUISwitch($child)
;Destroy the child GUI including the controls
GUIDelete()
;$flag = 1
;Check if user clicked on the close button of the parent window
ElseIf $msg[1] = $parentGui Then
;Switch to the parent window
GUISwitch($parentGui)
;Destroy the parent GUI including the controls
GUIDelete()
;Exit the script
Exit
EndIf

Case $msg[0] = $aboutMI
Msgbox(0,"About","Spell Inventory")

Case $msg[0] = $viewSpell
$child2 = GUICreate("View Spell 2", 200, 200, 150, 50, $WS_CAPTION) ;BitOR($WS_OVERLAPPEDWINDOW, $WS_CHILD), Default, $mainGui)
GUISetState ()
DllCall("user32.dll", "int", "SetParent", "hwnd", WinGetHandle($child2), "hwnd", WinGetHandle($parentGui))
WinActivate("View Spell 2","")
GUISwitch(-1)

Case $msg[0] = $GUI_EVENT_RESIZED or $GUI_EVENT_MAXIMIZE or $GUI_EVENT_RESTORE
_UpdateChildGui($parentGui, $mainGui, $child)
EndSelect

until $msg = $GUI_EVENT_CLOSE

GUIDelete()

Exit

Func _UpdateChildGui($parentGui, $childGui, $childsChild)
$state = WinGetState($childsChild)
$array = WinGetPos($parentGui)
WinMove($childGui, '', 0, 30, ($array[2]-8), ($array[3]-84))
If BitAnd($state, 32) Then
; x, y, width, heighth
WinMove($childsChild, '', -4, -4, $array[2], ($array[3]-76))
EndIf
EndFunc

Func _CreateMyToolbar($parentGui, ByRef $mainGui, ByRef $viewSpell)
$toolbar=GUICreate("toolbar", 800, 30, 0, 0, $WS_CHILD, Default, $parentGui)
GUISetState ()

;~ $hToolbar = _Toolbar_Create($toolbar)

;~ ; Add standard system bitmaps
;~ ;_Toolbar_SetButtonSize($hToolbar, 20, 50)
;~ _Toolbar_AddBitmap($hToolbar, 1, -1, $IDB_STD_LARGE_COLOR)

;~ ; Add buttons
;~ ;_Toolbar_AddButton ($hToolbar, $idNew , $STD_FILENEW )
;~ ;_Toolbar_AddButton ($hToolbar, $idOpen, $STD_FILEOPEN)
;~ _Toolbar_AddButton ($hToolbar, $idSave, $STD_FILENEW)
;~ _Toolbar_AddButtonSep($hToolbar)
;~ _Toolbar_AddButton ($hToolbar, $idHelp, $STD_FILEOPEN)
$viewSpell = GUICtrlCreateButton ("Test", 0,0,50,20)

$width = $windowWidth
$height = $windowHeight - 50
$mainGui=GUICreate("mainGui", $width, $height, 0, 30, $WS_CHILD, Default, $parentGui)
;GUISetBkColor (0x0FFFF)
;GUICtrlCreateButton ("OK",$width-50,$height-50,50,50)
;GUICtrlSetResizing (-1,$GUI_DOCKBOTTOM+$GUI_DOCKSIZE)
GUISetState ()
Return $toolbar
EndFunc
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

Ok, i got it to create the window i want on top of the old window using this for the buttons code:

$child = GUICreate("View Spell 2", 200, 200, 150, 50, BitOR($WS_OVERLAPPEDWINDOW, $WS_CHILD), Default, $mainGui)
DllCall("user32.dll", "int", "SetParent", "hwnd", WinGetHandle($child), "hwnd", WinGetHandle($mainGui))
GUISetState ()
GUISwitch(-1)

Now i just need to be able to get focus to change when i click on the main part of another child window.

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