Thread: Window list

  1. #1
    Android geek@02's Avatar
    Join Date
    Mar 2004
    Location
    Kurunegala Colony, Sri Lanka, Sri Lanka
    Posts
    470

    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);
        }
    GameJolt: https://gamejolt.com/@KasunL
    Game Development Youtube:
    https://is.gd/XyhYoP
    Amateur IT Blog: http://everything-geeky.blogspot.com/



    (and, sorry for my amateur English)

  2. #2
    Registered User
    Join Date
    Mar 2005
    Location
    Juneda
    Posts
    291
    '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,981
    >> '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 geek@02's Avatar
    Join Date
    Mar 2004
    Location
    Kurunegala Colony, Sri Lanka, Sri Lanka
    Posts
    470
    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);
    ??
    GameJolt: https://gamejolt.com/@KasunL
    Game Development Youtube:
    https://is.gd/XyhYoP
    Amateur IT Blog: http://everything-geeky.blogspot.com/



    (and, sorry for my amateur English)

  5. #5
    Registered User
    Join Date
    Mar 2005
    Location
    Juneda
    Posts
    291
    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,868
    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, 01:21 PM
  4. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 11: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