Jump to content
Sign in to follow this  
Zaxon

Bypassing the need for GuiSwithch

Recommended Posts

I'm wanting to place alot of my code into libraries. However, I'm finding that certain functionality, like closing or minimizing a window, doesn't necessarily work this way.

Consider the following test example:

#include <GUIConstants.au3>
opt ("GUIOnEventMode", 1)

$parenth=GUICreate("parent")
GUISetOnEvent($GUI_EVENT_CLOSE, "minimize_me_generic")
GUISetState()

GUICreate("child",100,100)
GUISetOnEvent($gui_event_close, "minimize_me_specific")
GUISetState()

func minimize_me_generic()
    GUISetState(@SW_MINIMIZE)
endfunc

func minimize_me_specific()
    GUISetState(@SW_MINIMIZE)
    guiswitch($parenth)
endfunc

sleep(20000)

When you run the script, a parent and then a child window is created. Click on the close button of the child window, and then on the close button of the parent window. Both windows minimize, as is the intention of this script.

However, the child window has to also call make a specific guiswitch by name. It cannot call a generic "minimize me" routine.

To see this, comment out the guiswitch() to make both minimize functions identical. Run it again. Does it work now? What you'll find is the child window will minimize, but the parent window has lost the close event association.

How can I write a generic minimize window function that doesn't need to know by name who its parent is?

Share this post


Link to post
Share on other sites

To use a parent / child windows, you need to use the parameter that enables it.

GUICreate ( "title" [, width [, height [, left [, top [, style [, exStyle [, parent]]]]]]] )

parent -> [optional] The handle of another previously created window - this new window then becomes a child of that window.

Share this post


Link to post
Share on other sites

To use a parent / child windows, you need to use the parameter that enables it.

GUICreate ( "title" [, width [, height [, left [, top [, style [, exStyle [, parent]]]]]]] )

parent -> [optional] The handle of another previously created window - this new window then becomes a child of that window.

<{POST_SNAPBACK}>

I see. I've made that addition expectantly, but the result hasn't changed. The parent window still doesn't automatically become the current window.

#include <GUIConstants.au3>
opt ("GUIOnEventMode", 1)

$parenth=GUICreate("parent")
GUISetOnEvent($GUI_EVENT_CLOSE, "minimize_me_generic")
GUISetState()

GUICreate("child",100,100,-1,-1,-1,-1,$parenth)
GUISetOnEvent($gui_event_close, "minimize_me_specific")
GUISetState()

func minimize_me_generic()
    GUISetState(@SW_MINIMIZE)
endfunc

func minimize_me_specific()
    GUISetState(@SW_MINIMIZE)
   ;guiswitch($parenth)
endfunc

sleep(20000)

Share this post


Link to post
Share on other sites

GUISetState ( [flag [, winhandle]] )

in your minimize specific function, try including the winhandle in GuiSetState()

also:

$GUI_EVENT_CLOSE

$gui_event_close

why are these different?

Edited by quaizywabbit

[u]Do more with pre-existing apps![/u]ANYGUIv2.8

Share this post


Link to post
Share on other sites

GUISetState ( [flag [, winhandle]] )

in your minimize specific function, try including the winhandle in GuiSetState()

also:

$GUI_EVENT_CLOSE

$gui_event_close

why are these different?

<{POST_SNAPBACK}>

Gui constants aren't case specific, so $GUI_EVENT_CLOSE and $gui_event_close are both identical. If if they hadn't been, then the minimize_me_specific() wouldn't have been called. But it is, and it works if you include the GuiSwitch line.

But the winhandle parameter has done the trick! I've been able to use that technology to create a generic minimize function. Thanks for the help.

Share this post


Link to post
Share on other sites

I see.  I've made that addition expectantly, but the result hasn't changed.  The parent window still doesn't automatically become the current window.

#include <GUIConstants.au3>
opt ("GUIOnEventMode", 1)

$parenth=GUICreate("parent")
GUISetOnEvent($GUI_EVENT_CLOSE, "minimize_me_generic")
GUISetState()

GUICreate("child",100,100,-1,-1,-1,-1,$parenth)
GUISetOnEvent($gui_event_close, "minimize_me_specific")
GUISetState()

func minimize_me_generic()
    GUISetState(@SW_MINIMIZE)
endfunc

func minimize_me_specific()
    GUISetState(@SW_MINIMIZE)
  ;guiswitch($parenth)
endfunc

sleep(20000)

<{POST_SNAPBACK}>

if you want to do action on a specific window you need to define it

as i undertsnad your code you need

func minimize_me_generic()
    GUISetState(@SW_MINIMIZE,$parenth)
endfunc

@quaizywabbit

$GUI_EVENT_CLOSE = $gui_event_close

AutoIT3 is not case sensitive for variable names

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...