AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

GuiControl, Delete
Goto page 1, 2  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Wish List
View previous topic :: View next topic  
Author Message
mAdDoG



Joined: 29 Dec 2004
Posts: 65

PostPosted: Fri Feb 10, 2006 2:16 am    Post subject: GuiControl, Delete Reply with quote

Is "GuiControl, Delete" coming out anywhere in the near future?

I've created a drawing app for plotting blueprint-dimensions, and man, I could really use this feature. (hiding does not work out well here)
_________________
-buttons, buttons,...
I like to push all the buttons!!!
Back to top
View user's profile Send private message
PhiLho



Joined: 27 Dec 2005
Posts: 6721
Location: France (near Paris)

PostPosted: Fri Feb 10, 2006 9:01 am    Post subject: Reply with quote

[EDIT] Executive summary Smile
(thanks to JSLover for the information and the link to the relevant topic)
  1. In most cases, this is not a good idea.
    See a similar topic for more informations, but in short:
    1. For regular GUIs, it is more efficient to deactivate and hide the controls.
    2. For other special cases (abusing somehow the purpose of AHK), like games or drawing, it can be problematic as AHK maintains an internal list of controls, so asking Windows to destroy them can have side effects.

  2. If really you need that, a simple
    PostMessage WM_CLOSE, , , %toRemove% ; WM_CLOSE=0x10
    is enough for destroy the control.

  3. Perhaps calling GDI functions for games/drawing would be more efficient than playing with a bunch of controls.

I leave the remainder of this message for historical record and comprehension of the thread, for whoever is interested...


---
Two ways of doing this: using DllCall for the DestroyWindow function, or simulating it using PostMessage.

I did the later:
Code:
WM_DESTROY = 0x0002
WM_NCDESTROY = 0x0082
WM_PARENTNOTIFY = 0x0210
WM_PAINT = 0x000F

Gui, Add, Button, gRemove, &Button remover
Gui, Add, Button, gBoo, &Ugly button, to be removed
Gui, Show
return

Remove:
   toRemove = Button2
;~    WinGet parentHandle, ID, ahk_class AutoHotkeyGUI
;~    buttonHandle := GetChildHWND(parentHandle, toRemove)
   PostMessage WM_DESTROY, , , %toRemove%
   PostMessage WM_NCDESTROY, , , %toRemove%
   PostMessage WM_PAINT
;~    PostMessage WM_PARENTNOTIFY, WM_DESTROY, buttonHandle, ahk_class AutoHotkeyGUI
Return

Boo:
   MsgBox Boo!
Return

GuiClose:
Escape::
ExitApp

I have not resolved the problem of refreshing/updating the window after removing the control. I tried WM_PAINT and WM_PARENTNOTIFY.
Perhaps I made a mistake using these, or I overlooked something.
If somebody has a solution... I have no time right now to search further.
_________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")


Last edited by PhiLho on Mon Feb 13, 2006 10:08 am; edited 5 times in total
Back to top
View user's profile Send private message Visit poster's website
Serenity



Joined: 07 Nov 2004
Posts: 1270

PostPosted: Fri Feb 10, 2006 9:08 am    Post subject: Reply with quote

Winset, Redraw works, but for some reason it sends the CPU to 100%:

Code:
Remove:
   toRemove = Button2
;~    WinGet parentHandle, ID, ahk_class AutoHotkeyGUI
;~    buttonHandle := GetChildHWND(parentHandle, toRemove)
   PostMessage WM_DESTROY, , , %toRemove%
   PostMessage WM_NCDESTROY, , , %toRemove%
   PostMessage WM_PAINT
;~    PostMessage WM_PARENTNOTIFY, WM_DESTROY, buttonHandle, ahk_class AutoHotkeyGUI
WinSet, Redraw
Return

_________________
"Anything worth doing is worth doing slowly." - Mae West
Back to top
View user's profile Send private message Visit poster's website
PhiLho



Joined: 27 Dec 2005
Posts: 6721
Location: France (near Paris)

PostPosted: Fri Feb 10, 2006 11:37 am    Post subject: Reply with quote

Cool, I didn't saw or forgot this one. Very useful.
Just remove the PostMessage WM_PAINT, it is no longer needed.

So basicially, we just have to do:
Code:
   PostMessage WM_DESTROY, , , %toRemove%
   PostMessage WM_NCDESTROY, , , %toRemove%
   WinSet Redraw

where toRemove is the classNN name of the control.
All AutoHotkey native, simple and nice...
Would have been easier using only the variable name of the control...

What about a GuiControlGet class, ID, controlVarName?
A bit like WinGet.
Or is it already there, hidden in the depths of the extensive documentation?
_________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")
Back to top
View user's profile Send private message Visit poster's website
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10471

PostPosted: Fri Feb 10, 2006 12:08 pm    Post subject: Reply with quote

Nice solution for deleting controls. However, I don't think this will stop you from hitting the 11,000-controls-per-window limit (assuming the script eventually creates that many controls).

PhiLho wrote:
What about a GuiControlGet class, ID, controlVarName?
There's no built-in way, though you could use MouseMove with MouseGetPos to do it (messy of course). There may be other ways.

I'll put your idea with related ones on the to-do list.
Back to top
View user's profile Send private message Send e-mail
JSLover



Joined: 20 Dec 2004
Posts: 542
Location: LooseChange911.com... the WTC attacks were done by the US Gov't... the official story is a lie...

PostPosted: Sun Feb 12, 2006 10:19 am    Post subject: Reply with quote

PhiLho wrote:
So basicially, we just have to do:
Code:
   PostMessage WM_DESTROY, , , %toRemove%
   PostMessage WM_NCDESTROY, , , %toRemove%
   WinSet Redraw

...why do you send so many messages? Ain't it gone after WM_DESTROY?...not able to receive WM_NCDESTROY...a long time ago I wrote this & I remember it working/redrawing...I haven't tested your script yet...but my old script worked then (might need rewritten a little...AHK has changed alot since then {PostMessage don't need %'s on most of its params...& might not work with them...but at that time it was the only way})...
_________________

Home • Click image! • Blog
Back to top
View user's profile Send private message Visit poster's website
PhiLho



Joined: 27 Dec 2005
Posts: 6721
Location: France (near Paris)

PostPosted: Sun Feb 12, 2006 11:00 am    Post subject: Reply with quote

Good remark, JSLover, I thought about it, but chose to leave as is.
I followed blindly the DestroyWindow way of doing things, it sends both messages...
It is probably more useful for complex windows like dialog boxes with non-client parts (title bar, borders...), and less useful for simple controls.
But it doesn't hurt to do that.
Note that a window isn't necessarily gone after WM_DESTROY. The application has to explicitely call the PostQuitMessage(0); function to exit, but it can just ignore the command (not a good idea...).
The WM_NCDESTROY is probably a hint for Windows to free resources:
MSDN wrote:
The WM_NCDESTROY message is sent after the child windows have been destroyed. In contrast, WM_DESTROY is sent before the child windows are destroyed.
This message frees any memory internally allocated for the window.
Seeing the last line, I don't know if omitting the WM_NCDESTROY may end in leaking memory. Again, this may no apply to simple controls. I am not sure if Tabs or ListView are "simple" controls, though.
_________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")
Back to top
View user's profile Send private message Visit poster's website
JSLover



Joined: 20 Dec 2004
Posts: 542
Location: LooseChange911.com... the WTC attacks were done by the US Gov't... the official story is a lie...

PostPosted: Sun Feb 12, 2006 11:19 am    Post subject: Reply with quote

PhiLho wrote:
...I thought about it, but chose to leave as is.

...thought about what?...chose to leave what as is?

PhiLho wrote:
I followed blindly the DestroyWindow way of doing things, it sends both messages...

...I just go the "nicest" route...I send a nice WM_CLOSE, then if that don't work I try more drastic measures...like WM_DESTROY...etc...you don't need to start with "Destroy! Twisted Evil", if a nice "Please close yourself honey" will do...

PhiLho wrote:
It is probably more useful for complex windows like dialog boxes with non-client parts...

...a dialog box can't be a control inside a dialog box...we are talking about "Button" controls.

PhiLho wrote:
But it doesn't hurt to do that.

...your versions don't remove the control at all...check window spy "Button2"/"Delete Me" (in my script, but with your PostMessage's) still exists & isn't even repainted, when you move a window over it, it gets repainted as if it's gone, but hover over while window spy is watching & you still see "Button2"/"Delete Me".

PhiLho wrote:
Note that a window isn't necessarily gone after WM_DESTROY.

...I didn't know that, but after I posted I tried your versions in my script (that I linked to) & noticed window spy showed it still there...WM_CLOSE makes it go really far away (but not as far as AHK is concerned).

PhiLho wrote:
...I don't know if omitting the WM_NCDESTROY may end in leaking memory.

...I can't test memory leaks, but I can see window spy not see the control after WM_CLOSE, but you can send your messages, then my WM_CLOSE & it works...kill it in 3 shots instead of 1...(WM_CLOSE might already send those other messages tho).

PhiLho wrote:
I am not sure if Tabs or ListView are "simple" controls, though.

...I only tested with a button...so I don't know if a ListView will go away like that, but ListView isn't really a "disposable" control...you make one & keep using it, a button is more disposable (for the Tetris script mentioned in the linked post).

Test Script...

DeleteControl.ahk wrote:
Code:
A_GuiMargin=7
Gui, Margin, %A_GuiMargin%, %A_GuiMargin%
Gui, Add, Text, w300, Use Window Spy && hover over each button, see Button1 2 && 3, press Delete Me, then hover again...Delete Me was really deleted.
Gui, Add, Button, section xm+30 w75, Test
Gui, Add, Button, ys w75 gDeleteButton, Delete Me
Gui, Add, Button, ys w75, Keep Me
Gui, Show ;, w300 h100 ;, AutoSize

WM_DESTROY=0x02
WM_PAINT=0x0F
WM_CLOSE=0x10
WM_NCDESTROY=0x82
WM_PARENTNOTIFY=0x210
return

DeleteButton:
PostMessage, WM_CLOSE, , , %A_GuiControl%
;PostMessage, WM_DESTROY, , , %A_GuiControl%
;PostMessage, WM_NCDESTROY, , , %A_GuiControl%
;PostMessage, WM_PARENTNOTIFY, , , %A_GuiControl%
;PostMessage, WM_PAINT, , , %A_GuiControl%
return

GuiEscape:
GuiClose:
ExitApp

_________________

Home • Click image! • Blog
Back to top
View user's profile Send private message Visit poster's website
PhiLho



Joined: 27 Dec 2005
Posts: 6721
Location: France (near Paris)

PostPosted: Sun Feb 12, 2006 12:47 pm    Post subject: Reply with quote

JSLover wrote:
PhiLho wrote:
...I thought about it, but chose to leave as is.

...thought about what?...chose to leave what as is?

Please, don't cut my sentences and wonder about the result. Maybe my wording wasn't perfect, but I tried to express "I thought about [your good remark]", or, actually, about removing the WM_NCDESTROY.

JSLover wrote:
PhiLho wrote:
I followed blindly the DestroyWindow way of doing things, it sends both messages...

...I just go the "nicest" route...I send a nice WM_CLOSE, then if that don't work I try more drastic measures...like WM_DESTROY...etc...you don't need to start with "Destroy! Twisted Evil", if a nice "Please close yourself honey" will do...

AFAIK, using DestroyWindow is the "classical" way of removing a control, but I can be wrong. Your way may allow the target window to do more clean up or to chose to ignore the message. I don't know if it makes a difference for Windows standard controls.

JSLover wrote:
PhiLho wrote:
It is probably more useful for complex windows like dialog boxes with non-client parts...

...a dialog box can't be a control inside a dialog box...we are talking about "Button" controls.

I wrote (or tried to) that the WM_NCDESTROY message has its use for other cases that the discussed one, that's all.

JSLover wrote:
PhiLho wrote:
But it doesn't hurt to do that.

...your versions don't remove the control at all...check window spy "Button2"/"Delete Me" (in my script, but with your PostMessage's) still exists & isn't even repainted, when you move a window over it, it gets repainted as if it's gone, but hover over while window spy is watching & you still see "Button2"/"Delete Me".

Oh, good remark, so my solution isn't good. You could have stated that in less words Smile

JSLover wrote:
PhiLho wrote:
Note that a window isn't necessarily gone after WM_DESTROY.

...I didn't know that, but after I posted I tried your versions in my script (that I linked to) & noticed window spy showed it still there...WM_CLOSE makes it go really far away (but not as far as AHK is concerned).

What do you mean by "really far away"? And "not as far as AHK is concerned"?

JSLover wrote:
PhiLho wrote:
...I don't know if omitting the WM_NCDESTROY may end in leaking memory.

...I can't test memory leaks, but I can see window spy not see the control after WM_CLOSE, but you can send your messages, then my WM_CLOSE & it works...kill it in 3 shots instead of 1...(WM_CLOSE might already send those other messages tho).

You are perfectly right.
Actually, in classical Windows programming, we handle the WM_CLOSE by generating a DestroyWindow() call, which will generate a WM_DESTROY message, which we receive and answer with a PostQuitMessage(0).
Somehow, I thought of this in "while Windows application", but it seems it apply to simple controls as well (they probably don't do PostQuitMessage, but something similar.
So, sending the WM_CLOSE not only send the necessary messages (WM_DESTROY & WM_NCDESTROY) in one shot, but probably allow some other clean-up that is missing from the raw calls.

JSLover wrote:
PhiLho wrote:
I am not sure if Tabs or ListView are "simple" controls, though.

...I only tested with a button...so I don't know if a ListView will go away like that, but ListView isn't really a "disposable" control...you make one & keep using it, a button is more disposable (for the Tetris script mentioned in the linked post).

Which linked post?
_________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")


Last edited by PhiLho on Wed Sep 13, 2006 3:23 pm; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
JSLover



Joined: 20 Dec 2004
Posts: 542
Location: LooseChange911.com... the WTC attacks were done by the US Gov't... the official story is a lie...

PostPosted: Sun Feb 12, 2006 2:19 pm    Post subject: Reply with quote

PhiLho wrote:
Please, don't cut my sentences and wonder about the result.

..."remark" didn't tell me which part you meant...plus I didn't get what "it" was referring too...

PhiLho wrote:
...DestroyWindow is the "classical" way of removing a control...

...I don't know the "classical" way I just come up with a way whenever I want to do something.

PhiLho wrote:
Your way may allow the target window to do more clean up or to chose to ignore the message.

...no, I test, I said I play nice...if the window does what I want when I play nice...if it don't, then I get mean.

PhiLho wrote:
...the discuted one...

...discuted is not a word...I've seen it in alot of your posts so I thought I'd mention it here: you are trying to say discussed

PhiLho wrote:
You could have stated that in less words Smile

...I explain things, I never know how much/little I can say to get my point across.

PhiLho wrote:
What do you mean by "really far away"?

...did you run the test script? If you hover over the buttons it says "Delete Me" is "Button2"...click it, hover again, nothing...hover over "Keep Me" it is now "Button2"..."Delete Me" is gone...farther than just being hidden or quasi-deleted, since "Keep Me" becomes "Button2"...farther away than I know how to check to see if it's "really there".

PhiLho wrote:
And "not as far as AHK is concerned"?

...if you read that linked post...Chris says that AHK isn't prepared for controls to go away like that & AHK still has an array of controls & that reference doesn't get deleted with this method.

PhiLho wrote:
Which linked post?

...the words "wrote this" in an above post are a link...that is the "linked post".

Double quoting takes up more space than just quoting the part you are replying too..."Double quoting" is my term for you quoting me AND yourself in your reply...I only quote the person I'm quoting, not that person & myself...
_________________

Home • Click image! • Blog
Back to top
View user's profile Send private message Visit poster's website
mAdDoG



Joined: 29 Dec 2004
Posts: 65

PostPosted: Mon Feb 13, 2006 2:25 am    Post subject: Reply with quote

To PhiLho & JSLover:


_________________
-buttons, buttons,...
I like to push all the buttons!!!
Back to top
View user's profile Send private message
JSLover



Joined: 20 Dec 2004
Posts: 542
Location: LooseChange911.com... the WTC attacks were done by the US Gov't... the official story is a lie...

PostPosted: Mon Feb 13, 2006 5:19 am    Post subject: Reply with quote

mAdDoG wrote:
To PhiLho & JSLover:

...I post my old solution...THAT WORKS!...& you respond that way? Well F U too!
_________________

Home • Click image! • Blog
Back to top
View user's profile Send private message Visit poster's website
BoBo
Guest





PostPosted: Mon Feb 13, 2006 6:37 am    Post subject: Reply with quote

GodDam
mGodDa
maGodD
maDGod
maDdGo
maDdoG
Wink
Back to top
Serenity



Joined: 07 Nov 2004
Posts: 1270

PostPosted: Mon Feb 13, 2006 6:59 am    Post subject: Reply with quote

I wasn't aware that a thread could have a sexual orientation. ;)
_________________
"Anything worth doing is worth doing slowly." - Mae West
Back to top
View user's profile Send private message Visit poster's website
BoBo
Guest





PostPosted: Mon Feb 13, 2006 7:26 am    Post subject: Reply with quote

@ Serenity
you've obviously missed AHK 1.0.42.00 !
Code:
Thread, Output [,gay,notgay,nonsense,obsolete,superb,*,shimanoved]


In case it comes to encryption you can replace shimanoved with Laszlodized (additionaly GUI related topics should, by any means use the secret param toralfonic to enhance the speed to get a response < 5min!) Very Happy
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Wish List All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group