 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
mAdDoG
Joined: 29 Dec 2004 Posts: 65
|
Posted: Fri Feb 10, 2006 2:16 am Post subject: GuiControl, Delete |
|
|
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 |
|
 |
PhiLho
Joined: 27 Dec 2005 Posts: 6721 Location: France (near Paris)
|
Posted: Fri Feb 10, 2006 9:01 am Post subject: |
|
|
[EDIT] Executive summary
(thanks to JSLover for the information and the link to the relevant topic)
- In most cases, this is not a good idea.
See a similar topic for more informations, but in short:- For regular GUIs, it is more efficient to deactivate and hide the controls.
- 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.
- If really you need that, a simple
PostMessage WM_CLOSE, , , %toRemove% ; WM_CLOSE=0x10
is enough for destroy the control.
- 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 |
|
 |
Serenity
Joined: 07 Nov 2004 Posts: 1270
|
Posted: Fri Feb 10, 2006 9:08 am Post subject: |
|
|
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 |
|
 |
PhiLho
Joined: 27 Dec 2005 Posts: 6721 Location: France (near Paris)
|
Posted: Fri Feb 10, 2006 11:37 am Post subject: |
|
|
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 |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10471
|
Posted: Fri Feb 10, 2006 12:08 pm Post subject: |
|
|
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 |
|
 |
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...
|
Posted: Sun Feb 12, 2006 10:19 am Post subject: |
|
|
| 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 |
|
 |
PhiLho
Joined: 27 Dec 2005 Posts: 6721 Location: France (near Paris)
|
Posted: Sun Feb 12, 2006 11:00 am Post subject: |
|
|
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 |
|
 |
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...
|
Posted: Sun Feb 12, 2006 11:19 am Post subject: |
|
|
| 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! ", 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...
| 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 |
|
 |
PhiLho
Joined: 27 Dec 2005 Posts: 6721 Location: France (near Paris)
|
Posted: Sun Feb 12, 2006 12:47 pm Post subject: |
|
|
| 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! ", 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
| 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 |
|
 |
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...
|
Posted: Sun Feb 12, 2006 2:19 pm Post subject: |
|
|
| 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  |
...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 |
|
 |
mAdDoG
Joined: 29 Dec 2004 Posts: 65
|
Posted: Mon Feb 13, 2006 2:25 am Post subject: |
|
|
To PhiLho & JSLover:
 _________________ -buttons, buttons,...
I like to push all the buttons!!! |
|
| Back to top |
|
 |
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...
|
Posted: Mon Feb 13, 2006 5:19 am Post subject: |
|
|
| 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 |
|
 |
BoBo Guest
|
Posted: Mon Feb 13, 2006 6:37 am Post subject: |
|
|
GodDam
mGodDa
maGodD
maDGod
maDdGo
maDdoG
 |
|
| Back to top |
|
 |
Serenity
Joined: 07 Nov 2004 Posts: 1270
|
Posted: Mon Feb 13, 2006 6:59 am Post subject: |
|
|
I wasn't aware that a thread could have a sexual orientation. ;) _________________ "Anything worth doing is worth doing slowly." - Mae West
 |
|
| Back to top |
|
 |
BoBo Guest
|
Posted: Mon Feb 13, 2006 7:26 am Post subject: |
|
|
@ 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!)  |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|