Trying to get the win32 window title with the following code, and then try to change the same window title using wostringstream. Here is the code to get the name
std::wstring Window::getTitle()const
{
int length = SendMessage(hwnd,WM_GETTEXTLENGTH,0,0);
if(length == -1)
return L"";
wchar_t* buffer = new wchar_t[length+1];
SendMessage(hwnd,WM_GETTEXT,length+1,(LPARAM)buffer);
std::wstring str(buffer);
delete[] buffer;
return str;
}
Here is the code that is trying to use this:
std::wostringstream oss;
while(window->isRunning)
{
oss.str(L"");
oss<<window->getTitle()<<" FPS : "<<100<<" Frame Time"<<100;
window->setText(oss.str());
}
Instead of displaying the window title plus the frs time and frame time that ends, it displays the window title and then repeats the repeating text FPS and Frame. I tried adding '\ 0' to the end of the buffer with:
buffer[length] = '\0';
This did not solve the problem. If I return L "some header" from getTitle, everything works correctly, so I think the problem is inside the getTitle function.
source
share