-
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);
}
-
'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
-
>> '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
-
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);
??
-
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
-
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].