Sign in to follow this  
Followers 0
momar33

Child window not gaining focus on click.

2 posts in this topic

When i have more than one child an i click on the child that is not in front, it does not change focus to the child in back unless i click the title bar.

Here is my 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 2", 200, 200, 150, 50, BitOR($WS_OVERLAPPEDWINDOW, $WS_CHILD), Default, $mainGui)
DllCall("user32.dll", "int", "SetParent", "hwnd", WinGetHandle($child2), "hwnd", WinGetHandle($mainGui))
GUISetState ()

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

Share this post


Link to post
Share on other sites



I quite have the same problem!

I wanted to make lo3n's Script embedded on the Desktop and put some custom controls to them.

But when i make the GUI to a Child of the Desktop, the buttons and labels hide behind the background and dont come back.

I tried a lot with Styles but nothing seems to work. There has to be a soultion.

#NoTrayIcon
#include <A3LGDIPlus.au3> ; this is where the magic happens, people
#include <GuiCombo.au3>
#Include <File.au3>
#include <Array.au3>
Opt("MustDeclareVars", 0)

Global Const $AC_SRC_ALPHA      = 1
Global Const $ULW_ALPHA         = 2
Global $old_string = "", $runthis = ""
Global $launchDir = @DesktopDir

; Load PNG file as GDI bitmap
_GDIP_Startup()
$pngSrc = @scriptdir&"\LaunchySkin.png"
$hImage = _GDIP_ImageLoadFromFile($pngSrc)

; Extract image width and height from PNG
$width =  _GDIP_ImageGetWidth ($hImage)
$height = _GDIP_ImageGetHeight($hImage)

; Create layered window
$GUI = GUICreate("lod3n launcher", $width, $height, -1, -1, $WS_POPUP, $WS_EX_LAYERED)
SetBitMap($GUI, $hImage, 0)
Opt("WinTitleMatchMode", 4);                                                                             NEW
DllCall("user32.dll", "int", "SetParent", "hwnd", $GUI, "hwnd", WinGetHandle("classname=Progman"));                     NEW
; Register notification messages
GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST")
GUISetState()
;~ WinSetOnTop($gui,"",1)
;fade in png background
for $i = 0 to 255 step 10
    SetBitMap($GUI, $hImage, $i)
next


; create child MDI gui window to hold controls
; this part could use some work - there is some flicker sometimes...
$controlGui = GUICreate("ControlGUI", $width, $height, 0,0,$WS_POPUP,BitOR($WS_EX_LAYERED,$WS_EX_MDICHILD),$gui)
DllCall("user32.dll", "int", "SetParent", "hwnd", $controlGui, "hwnd", WinGetHandle("classname=Progman"));                    NEW
; child window transparency is required to accomplish the full effect, so $WS_EX_LAYERED above, and
; I think the way this works is the transparent window color is based on the image you set here:
GUICtrlCreatePic(@ScriptDir & "\grey.gif",0,0,$width,$height)
GuiCtrlSetState(-1,$GUI_DISABLE)

; just a text label
GUICtrlCreateLabel("Type the name of a file on your desktop and press Enter",50,12,140,50)
GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetColor(-1,0xFFFFFF)

; combo box listing all items on desktop
$Combo = GuiCtrlCreateCombo("", 210, 12,250,-1)
GUICtrlSetFont ($Combo, 12)


; set default button for Enter key activation - renders outside GUI window
$goButton = GUICtrlCreateButton ( "Go",$width,$height,10,10,$BS_DEFPUSHBUTTON)

GUISetState()

; get list of files on desktop, show in combobox
$aFileList=_FileListToArray($launchDir)
_ArraySort($aFileList,0,1)
$FileList = _ArrayToString ( $aFileList, "|", 1)
GUICtrlSetData($Combo,$FileList)

AdlibEnable ( "GoAutoComplete", 1000 ) ; combo autocomplete every message loop = often incorrect
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $goButton
            $runthis = GUICtrlRead($Combo)
            ExitLoop
    EndSelect
WEnd
AdlibDisable ()



if $runthis <> "" then 
    if fileexists($launchDir & "\" & $runthis) then 
        beep(1000,50)
        beep(2000,50)
        _ShellExecute($runthis, "", $launchDir)
    EndIf
EndIf

GUIDelete($controlGui)
;fade out png background
for $i = 255 to 0 step -10
    SetBitMap($GUI, $hImage, $i)
next

; Release resources
_API_DeleteObject($hImage)
_GDIP_Shutdown()



func GoAutoComplete()
    _GUICtrlComboAutoComplete ($Combo, $old_string)
EndFunc

; ===============================================================================================================================
; Handle the WM_NCHITTEST for the layered window so it can be dragged by clicking anywhere on the image.
; ===============================================================================================================================
Func WM_NCHITTEST($hWnd, $iMsg, $iwParam, $ilParam)
  if ($hWnd = $GUI) and ($iMsg = $WM_NCHITTEST) then Return $HTCAPTION
EndFunc

; ===============================================================================================================================
; SetBitMap
; ===============================================================================================================================
Func SetBitmap($hGUI, $hImage, $iOpacity)
  Local $hScrDC, $hMemDC, $hBitmap, $hOld, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend

  $hScrDC  = _API_GetDC(0)
  $hMemDC  = _API_CreateCompatibleDC($hScrDC)
  $hBitmap = _GDIP_BitmapCreateHBITMAPFromBitmap($hImage)
  $hOld    = _API_SelectObject($hMemDC, $hBitmap)
  $tSize   = DllStructCreate($tagSIZE)
  $pSize   = DllStructGetPtr($tSize  )
  DllStructSetData($tSize, "X", _GDIP_ImageGetWidth ($hImage))
  DllStructSetData($tSize, "Y", _GDIP_ImageGetHeight($hImage))
  $tSource = DllStructCreate($tagPOINT)
  $pSource = DllStructGetPtr($tSource)
  $tBlend  = DllStructCreate($tagBLENDFUNCTION)
  $pBlend  = DllStructGetPtr($tBlend)
  DllStructSetData($tBlend, "Alpha" , $iOpacity    )
  DllStructSetData($tBlend, "Format", $AC_SRC_ALPHA)
  _API_UpdateLayeredWindow($hGUI, $hScrDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, $ULW_ALPHA)
  _API_ReleaseDC   (0, $hScrDC)
  _API_SelectObject($hMemDC, $hOld)
  _API_DeleteObject($hBitmap)
  _API_DeleteDC    ($hMemDC)
EndFunc


; I don't like AutoIt's built in ShellExec. I'd rather do the DLL call myself.
Func _ShellExecute($sCmd, $sArg="", $sFolder = "", $rState = @SW_SHOWNORMAL)
   $aRet = DllCall("shell32.dll", "long", "ShellExecute", _
      "hwnd",   0, _
      "string", "", _
      "string", $sCmd, _
      "string", $sArg, _
      "string", $sFolder, _
      "int",    $rState)
   If @error Then Return 0
       
   $RetVal = $aRet[0]
   If $RetVal > 32 Then
       Return 1
   else  
    Return 0
   EndIf
EndFunc

Teamspeak 3 User Viewer - Quick and functional TS3 Query script, which shows online users.Cached Screenshot Deleter - Deletes older Fraps Screenshots if they exceed a specified limit.Unresolved Topics:Intercept and modify dragdrop text behaviour in scite

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
Sign in to follow this  
Followers 0