Window list

This is a discussion on Window list within the Windows Programming forums, part of the Platform Specific Boards category; Hi im trying to enumerate through opened windows(20 in this case) and dump their names in a listbox. Though i ...

  1. #1
    Android
    Join Date
    Mar 2004
    Location
    Kurunegala Colony, Sri Lanka, Sri Lanka
    Posts
    365

    Window list

    Hi im trying to enumerate through opened windows(20 in this case) and dump their names in a listbox. Though i get a blank str always. How to fix it? Thanx.

    Code:
        for(int i=0; i<20; i++)
        {
            CWnd *cwnd = GetNextWindow();
            CString str;
            cwnd->GetWindowText(str);
            m_clbWndList.AddString(str);
        }
    Some useless programs i've wrote : slprogrammersheaven
    Youtube: http://www.youtube.com/user/geekyzine
    My amature IT Blog: http://everything-geeky.blogspot.com/
    My Flash games: http://flashweed.blogspot.com/

    (and, sorry for my amature english)

  2. #2
    Registered User
    Join Date
    Mar 2005
    Location
    Juneda
    Posts
    287
    'GetWindowText' wears 3 arguments (in order): handle to the window to work with, buffer, and buffer size, can do something like that:

    Code:
    char bff[512];
    GetWindowText(chwnd,bff,sizeof(bff));
    Hope that helps
    Niara

  3. #3
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,673
    >> 'GetWindowText' wears 3 arguments
    And CWnd::GetWindowText wears 2 or 1.

    http://msdn.microsoft.com/en-us/library/ms633520.aspx
    See Remarks. You may have to send WM_GETTEXT directly.

    gg

  4. #4
    Android
    Join Date
    Mar 2004
    Location
    Kurunegala Colony, Sri Lanka, Sri Lanka
    Posts
    365
    i did above both, still i get the empty string.
    Code:
    CWnd *cwnd = GetNextWindow();
    char str[512]="\0";
    ::SendMessage(cwnd->m_hWnd,WM_GETTEXT,0, (LPARAM)str);
    ??
    Some useless programs i've wrote : slprogrammersheaven
    Youtube: http://www.youtube.com/user/geekyzine
    My amature IT Blog: http://everything-geeky.blogspot.com/
    My Flash games: http://flashweed.blogspot.com/

    (and, sorry for my amature english)

  5. #5
    Registered User
    Join Date
    Mar 2005
    Location
    Juneda
    Posts
    287
    Codeplug: thank's to notice the error

    geek@02: now yes, WM_GETTEXT wears 2 args in order the buffer size and the buffer, so maybe the trick will be:

    Code:
    CWnd *cwnd = GetNextWindow();
    char str[512]="\0";
    ::SendMessage(cwnd->m_hWnd,WM_GETTEXT,(WPARAM)512, (LPARAM)str);
    Hope that helps
    Niara

  6. #6
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    Check the return, which should be the length of the string returned. If zero call GetLastError().

    That should tell you if the window has no title, is a another windows control or an error occured [ERROR_SUCCESS == 0].
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Following CTools
    By EstateMatt in forum C Programming
    Replies: 5
    Last Post: 06-26-2008, 10:10 AM
  2. C or C++
    By AcerN30 in forum Game Programming
    Replies: 41
    Last Post: 05-30-2008, 06:57 PM
  3. help! Placement of nodes in a Linked List
    By lostmyshadow in forum C Programming
    Replies: 6
    Last Post: 12-17-2007, 12:21 PM
  4. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 10:06 AM
  5. Adding colour & bmps to a Win 32 Window??
    By carey_sizer in forum Windows Programming
    Replies: 4
    Last Post: 09-04-2004, 05:55 PM

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