Jump to content

Recommended Posts

Posted

When i have another window in front of my program and i click on the child window in my program, my program doesn't get focus.

It does get focus when i click on any other part of the parent window.

Here is my code:

CODE
#cs ----------------------------------------------------------------------------

AutoIt Version: 3.2.4.9

Author: myName

Script Function:

Template AutoIt script.

#ce ----------------------------------------------------------------------------

#include <GUIConstants.au3>

;#include <database.au3>

#include <A3LToolbar.au3>

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

Dim $child, $flag = 0

; Script Start - Add your code below here

$main = GUICreate("Spell Inventory", 800, 500, -1,-1, $WS_OVERLAPPEDWINDOW)

GUISetState ()

$dbname = "C:\Documents and Settings\Shawn\Desktop\SI\DB Info\spelldb.mdb"

$tblname = "Spells"

$fldname = "ID" ;"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)

;$hToolbar = _Toolbar_Create($main)

; Add standard system bitmaps

;_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_FILESAVE)

;_Toolbar_AddButtonSep($hToolbar)

;_Toolbar_AddButton ($hToolbar, $idHelp, $STD_HELP )

$viewSpell = GUICtrlCreateButton ("1", 0,0,30,30,$BS_ICON)

GUICtrlSetImage (-1, "shell32.dll",134)

do

$msg = GUIGetMsg(1)

if $flag = 0 then

$msg[0] = $viewSpell

Endif

Select

Case $msg[0] = $viewSpell

if $flag = 0 then

;~ $query = "SELECT * FROM " & $tblname & " WHERE (((Spells.ID)=1 Or (Spells.ID)=2));"

;~ $record = _RecordSearch($dbname, $query)

;~ ;$strData = _ReadOneFld($query, $dbname, $fldname)

$child = GUICreate("View Spells", 400, 340, 40, 0, $WS_OVERLAPPEDWINDOW)

DllCall("user32.dll", "int", "SetParent", "hwnd", WinGetHandle($child), "hwnd", WinGetHandle($main))

GUISetState ()

;~ $spellLabel = GUICtrlCreateLabel ("Spell:", 10, 35, 40, 20)

;~ GUICtrlSetFont (-1,9, 800, "")

;~ GUICtrlSetResizing (-1,$GUI_DOCKALL)

;~ $spellData = GUICtrlCreateLabel ("", 45, 35, 200, 20)

;~ GUICtrlSetFont (-1,9, 400)

;~ GUICtrlSetResizing (-1,$GUI_DOCKALL)

;~ GUICtrlSetData(-1, $record[0][10])

;~ $AOELabel = GUICtrlCreateLabel ("Area Of Effect:", 10, 35, 40, 20)

;~ GUICtrlSetFont (-1,9, 800, "")

;~ GUICtrlSetResizing (-1,$GUI_DOCKALL)

;~ $AOEData = GUICtrlCreateLabel ("", 45, 35, 200, 20)

;~ GUICtrlSetFont (-1,9, 400)

;~ GUICtrlSetResizing (-1,$GUI_DOCKALL)

;$query = "SELECT " & $tblname & "." & $fldname & " FROM " & $tblname & " WHERE " & $tblname & ".ID=1"

;$query = "SELECT First(Spells.Name) AS FirstOfName FROM Spells;"

;$query = "SELECT * FROM " & $tblname & " WHERE " & $fldname & " = 1"

$flag = 1

Else

GUISwitch($child)

EndIf

Case $msg[0] = $aboutMI

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

Case $msg[0] = $GUI_EVENT_CLOSE

;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] = $main Then

;Switch to the parent window

GUISwitch($main)

;Destroy the parent GUI including the controls

GUIDelete()

;Exit the script

Exit

EndIf

EndSelect

until $msg = $GUI_EVENT_CLOSE

GUIDelete()

Exit

Posted

Try this.

Comment you setparent DllCall. Looks unneeded.

Then change this line

$child = GUICreate("View Spells", 400, 340, 40, 0, $WS_OVERLAPPEDWINDOW)

My testing shows correction of behaviour with child window activation when clicked on.

:rolleyes:

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
×
×
  • Create New...