Sign in to follow this  
Followers 0
charvi

Current GUI Handle

6 posts in this topic

Hi,

I have written a program with several windows [handles created by GUICreate()].

One among them is a window with a simple List (GUICtrlCrateList) where I display miscellaneous information, including the content of variables, you may consider it being a clone of ConsoleWrite() :)

Before I focus to the window containing the List, I need to know the current focus. How do I do that ?

Thanks in advance!

Share this post


Link to post
Share on other sites



WinGetTitle("[active]")

Share this post


Link to post
Share on other sites

WinGetHandle("","")


[quote name='dbzfanatic' post='609696' date='Nov 26 2008, 08:46 AM']This is a help forum not a "write this for me" forum.[/quote](Sorry for bad English) :)

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Thanks oMBra and n3nE for your reply.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiEdit.au3>
#include <GuiMenu.au3>
#include <GuiToolBar.au3>
#include <GuiComboBoxEx.au3>
#include <Array.au3>
#include <Constants.au3>

Global $winCount

$hWin1 = guicreate("",800,400,10,10)
$winCount = $winCount + 1
GUISetBkColor(0x838b83,$hWin1)
$qubutton = guictrlcreatebutton("Quit",200, 50, 60)
GUISetState()

$hWin2 = GUICreate("You",300,300,260,200, $ws_popup, $ws_ex_dlgmodalframe)
$winCount = $winCount + 1
GUISetBkColor(0xeecbad,$hWin2)
$q2button = guictrlcreatebutton("Quit",200, 50, 60)
GUISetState()

GUICtrlSetState($q2button,$gui_focus)

ConsoleWrite("$hWin2="& number($hWin2) & @crlf)
debug("$hWin2="& number($hWin2) & @crlf)

While 1
  $event = GUIGetMsg()

  Select
    Case $event = $q2button
    GUIDelete($hWin2)
    $winCount = $winCount - 1
      
    Case $event = $GUI_EVENT_CLOSE or ($winCount=1 and $event=$qubutton)
      ExitLoop
  EndSelect
WEnd 

Func Debug($var)
    Global $debug, $hDebug, $hDebugList
    
    $hCf = WinGetHandle("","")
        ConsoleWrite("$hCf="& number($hCf) & @crlf)
        
    if $debug = 0 Then
        $hDebug = GUICreate("Debug window",300,600,630,30,$ws_sysmenu,$ws_ex_topmost)
        $hDebugList = GUICtrlCreateList("", 0,0, 300,550)
        GUISetState()
        $debug = 1
    EndIf   
    GUICtrlSetState($hDebug,$gui_focus)
    GUICtrlSetData($hDebugList, $var)
    GUICtrlSetState($hCf,$gui_focus)
EndFunc

The answer of n3nE was the correct answer for my problem.

But now, why is the last line of the Function Debug() not working? [GUICtrlSetState($hCf,$gui_focus)] The Quit button of the salmon window was prefocused, so hitting the [Enter] key is the same as clicking it. When the Debug window showed up, hitting [Enter] should have closed the salmon window, but it does not. What am I missing here?

Edited by charvi

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

change

GUICtrlSetState($hCf, $gui_focus)

to

WinActivate($hCf)

because $hCf is the handle of a WINDOW not of a CONTROL

Edited by oMBra

Share this post


Link to post
Share on other sites

You are right oMBra! Your change is working perfectly. Thank you!

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