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 596661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:11:44+00:00 2026-05-13T16:11:44+00:00

So the GetWindowText is declared on MSDN as follows: int GetWindowText( HWND hWnd, LPTSTR

  • 0

So the GetWindowText is declared on MSDN as follows:

int GetWindowText(      
    HWND hWnd,
    LPTSTR lpString,
    int nMaxCount
);

However for the code to work we have to declare the second parameter as

TCHAR[255] WTitle;

and then call the function GetWindowText(hWnd,Wtitle,255);
The LPTSTR is a pointer to an array of tchar, so declaring LPTSTR is similar to declaring TCHAR[]? It doesn’t work this way though.
When using TCHAR[] the program returns valid GetWindowText result (it is an integer equal to the number of symbols in the title). The question is : how can I get the exact title out of TCHAR[] ? Code like

TCHAR[255] WTitle;
cout<< WTitle;

or

cout<< *Wtitle;

returns numbers. How can I compare this with a given string?

TCHAR[4] Test= __T("TEST")
if (WTitle == Test) do smth

doesn’t work also.

  • 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-05-13T16:11:45+00:00Added an answer on May 13, 2026 at 4:11 pm

    OK, a few definitions first.

    The ‘T’ types are definitions that will evaluate to either CHAR (single byte) or WCHAR (double-byte), depending upon whether you’ve got the _UNICODE symbol defined in your build settings. The intent is to let you target both ANSI and UNICODE with a single set of source code.

    The definitions:

    TCHAR title[100];
    TCHAR * pszTitle;
    

    …are not equivalent. The first defines a buffer of 100 TCHARs. The second defines a pointer to one or more TCHARs, but doesn’t point it at a buffer. Further,

    sizeof(title) == 100   (or 200, if _UNICODE symbol is defined)
    sizeof(pszTitle) == 4  (size of a pointer in Win32)
    

    If you have a function like this:

    void foo(LPCTSTR str);
    

    …you can pass either of the above two variables in:

    foo(title);    // passes in the address of title[0]
    foo(pszTitle); // passes in a copy of the pointer value
    

    OK, so the reason you’re getting numbers is probably because you do have UNICODE defined (so characters are wide), and you’re using cout, which is specific to single-byte characters. Use wcout instead:

    wcout << title;
    

    Finally, these won’t work:

    TCHAR[4] Test == __T("TEST")   ("==" is equality comparison, not assignment)
    if (WTitle == Test) do smth    (you're comparing pointers, use wcscmp or similar)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an EditBox HWND tbLog , and the following function (which doesn't work):
I don't quite understand how GetWindowText can work for a window on the same
I have code like this: IntPtr hwndGetValue = new IntPtr(67904); List<IntPtr> windows = GetChildWindows(hwndGetValue);
//window is an HWND LPWSTR path = new WCHAR[1024]; DWORD size = 1024; GetWindowText(window,
Following the tutorial at http://www.codersource.net/mfc/mfc-tutorials/ctabctrl.aspx , I have declared the function ActivateTabDialogs() in my
Declare: LPWSTR** lines= new LPWSTR*[totalLines]; then i set using: lines[totalLines]=&totalText; SetWindowText(totalChat,(LPWSTR)lines[totalLines]); totalLines++; Now I
Having the window handle for an open application, I'm able to use the GetWindowText
const char* title = old title; HWND hwnd = FindWindow(title, title); SetWindowText(hwnd, new title);
this code works fine: procedure TForm2.Timer1Timer(Sender: TObject); var Text: string; begin SetLength (Text,555); GetWindowText
I'm looking at handling longer file paths in my windows application. Currently, I have

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.