EnumChildWindows

This is a discussion on EnumChildWindows within the Windows Programming forums, part of the Platform Specific Boards category; I have this function, which i use with EnumWindows to put window titles in a list box and it works ...

  1. #1
    JJ.
    Guest

    EnumChildWindows

    I have this function, which i use with EnumWindows to put window titles in a list box and it works fine.
    Code:
    BOOL CALLBACK WindowsToListBox( HWND hwnd, LPARAM lParam )
    {
    	char buff[500];
    
    	GetWindowText( hwnd, buff, sizeof( buff ) );
    	
    	if( strlen( buff ) )
    		SendMessage( ( HWND ) lParam, LB_ADDSTRING, 0, (LPARAM) buff );
    
    	return TRUE;
    }
    
    It is called with:
    EnumWindows( WindowsToListBox, ( LPARAM ) ListBox );
    Where ListBox is a handle to the list box
    However when I try to use EnumChildWindows it dosent work. I call it like this
    Code:
    EnumChildWindows( NULL, WindowsToListBox, ( LPARAM ) ListBox );
    MSDN says that "when the first parameter is NULL EnumChildWindows behaves the same as EnumWindows". So how come it don't work?

  2. #2
    JJ.
    Guest
    Further investigating reveals that it is producing the system error "Invalid parameter", when I change the NULL to a window handle it works fine. Is there a function to set a handle to the desktop?

  3. #3
    JJ.
    Guest
    Eureaka!!!!
    All you need to do is use GetDesktopWindow()
    Code:
    HWND hwnd = GetDesktopWindow();
    
    EnumChildWindows( hwnd, WindowsToListBox, ( LPARAM ) ListBox );
    The only thing is it seems to get just about every window there is, including the time. Oh well at least it works now

  4. #4
    Registered User Penguin of Oz's Avatar
    Join Date
    Dec 2002
    Posts
    16

    Addition

    If you only want to check for programs with visible windows open, the next step would be to use the function IsWindowVisible(...);

    Example:
    Code:
    if(IsWindowVisible(hWnd)) AddToList(hWnd);
    Where AddToList is your own function to add the window to the list you're constructing.

    This, in theory, should stop you picking up the clock, etc.
    "I don't think there's anything else I can do... my shoes are tied"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. EnumChildWindows and a SysListView32
    By pobri19 in forum Windows Programming
    Replies: 3
    Last Post: 02-02-2009, 05:40 AM
  2. EnumChildWindows Problem
    By cgod in forum Windows Programming
    Replies: 3
    Last Post: 08-16-2005, 12:24 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21