March 28, 2024, 09:36:52 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


EnumChildWindows - help anyone?

Started by Andy, February 27, 2018, 07:00:54 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Andy

February 27, 2018, 07:00:54 AM Last Edit: February 27, 2018, 07:04:00 AM by Andy
A nice little feature I'd like to include in the custom menu library would be to detect all controls (child windows) of the current parent window.

Now I believe the EnumChildWindows function does that (or have I got that wrong?).

There are one or two examples on here, but can anyone provide a simple example of a window with say four controls (buttons / statics etc) using the EnumChildWindows function to list these control ID's for me.

It would be a big help!!

BTW:

The deleting of menu items in the custom menu is coming along nicely and I've simplified things (less commands) for use with a normal window (which most of you would use it with).

So any help with EnumChildWindows would be greatly appreciated!!

Thanks,
Andy.


 
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

LarryMc

February 27, 2018, 10:25:56 AM #1 Last Edit: February 27, 2018, 11:22:19 AM by LarryMc
I don't know exactly how you intend to use EnumChildWindows but some comments about it.
It doesn't discern between controls and other windows nesting etc.  A window is a window to this function.
So if the parent window w/controls has a child window w/controls ALL the controls will be enumerated plus the child window(with some bogus id (I think)

the results will be hwnds which can be used in

ID = GetDlgCtrlID(hwnd)

to get the controls id that was used when it was created.

$include "windowssdk.inc" ' sdk headers

$main
window w1
openwindow w1,0,0,465,293,0,0,"Caption",&w1_handler
CONTROL w1,@SYSBUTTON,"click me",14,14,93,21,0x50000000,1000
CONTROL w1,@CHECKBOX,"click me",14,44,70,20,0x50000003,1001
CONTROL w1,@RADIOBUTTON,"click me",14,73,70,20,0x50000009,1002
CONTROL w1,@COMBOBOX,"",14,102,70,80,0x50800603,1003
CONTROL w1,@LISTBOX,"",124,18,70,60,0x50800140,1004
CONTROL w1,@SCROLLBAR,"",122,84,70,20,0x50000000,1005
CONTROL w1,@SCROLLBAR,"",202,20,20,70,0x50000001,1006
CONTROL w1,@LISTVIEW,"",234,24,70,60,0x50000001,1007
CONTROL w1,@TREEVIEW,"",308,24,70,60,0x50800007,1008
CONTROL w1,@GROUPBOX,"Group",124,118,70,60,0x50000007,1009
CONTROL w1,@EDIT,"Edit1",218,106,70,20,0x50800000,1010
CONTROL w1,@STATIC,"Static",222,138,70,20,0x5000010B,1011

waituntil w1=0

end
'--------

SUB w1_handler(),int
SELECT @MESSAGE
CASE @IDCREATE
centerwindow w1
case @idcontrol
if @controlid=1000
EnumChildWindows(w1.hwnd, &ChildEnumProc, 0)
endif
CASE @IDCLOSEWINDOW
Closewindow w1
ENDSELECT
RETURN 0
ENDSUB

'--------------------------------------------------------
sub ChildEnumProc(int hwnd,int lParam),int
messagebox (0,str$(GetDlgCtrlID(hwnd)),"")
return true
endsub



Note: Between 1007 and 1008 it is enumerating a window with a ID of 0 so you need to add a test for 0 which means it is a window and not a control. That might be the parent???

LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Andy

Thanks Larry,

That's very helpful!

I changed the code slightly to this:

sub ChildEnumProc(int hwnd,int lParam),int

if controlexists(w1,GetDlgCtrlID(hwnd))
messagebox (WinBox,str$(GetDlgCtrlID(hwnd)),"")
return true
else
return true
endif

endsub


Using the CONTROLEXISTS command knocks out the 0.

As to whether it would also ignore an actual child window remains to be seen, but it's ineresting and something I will play around with.

Thanks again,
Andy.
:)
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

LarryMc

make it even simpler

sub ChildEnumProc(int hwnd,int lParam),int

if controlexists(w1,GetDlgCtrlID(hwnd))
messagebox (WinBox,str$(GetDlgCtrlID(hwnd)),"")
endif
         return true
endsub
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library