Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7801123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:51:04+00:00 2026-06-02T00:51:04+00:00

Trying to get the title of a win32 window with the following code and

  • 0

Trying to get the title of a win32 window with the following code and then trying to change the same windows title using wostringstream. Here is the code to get the title

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 tries 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 and the frame time what ends up happening is it displays the window title and then repeats the FPS and Frame time text multiple times. I tried adding a ‘\0’ at the end of buffer with :

buffer[length] = '\0';

Which didn’t fix the problem. If I return L”some title” from getTitle everything works correctly, so I am thinking the problem is inside the getTitle function.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T00:51:05+00:00Added an answer on June 2, 2026 at 12:51 am

    Of course the string is going to be repeated. You’re getting the window text, adding the FPS and Frame Time, and then setting the window text to the modified string. The next time you call getTitle, it’s going to return the modified string.

    So I would expect that if you start with a window title of foo, the first two iterations of your loop will result in:

    foo FPS : 100 Frame Time100
    foo FPS : 100 Frame Time100 FPS : 100 Frame Time100
    

    You’ll have to strip the FPS and Frame Time values from the title when you get it from getTitle. Otherwise you’ll have an infinitely growing title.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the following code to get the title of a string. Everything
Im trying to get the corresponding title to the given ID using the code
I am trying to get the results of this code this way: title: Ben
As the title says, I am trying to get the following Javascript working in
I am trying to get this to work I am using this code and
I am trying to get a url structure like this. http://example.com/blog/1/title-name-goes-here My main urls
I am trying to get page title on every page using new Firefox add-on
I'm trying to get the title of the active window. The application is a
I'm trying to get title of simple html document to build sitemap. But always
I'm trying to get the title of a page in an iFrame. I did

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.