9

I am quite new to Windows programming. I am trying to retrieve the name of a window.

char NewName[128];
GetWindowText(hwnd, NewName, 128);

I need to use a char[] but it gives me the error of wrong type.
From what I read, LPWSTR is a kind of char*.

How can I use a char[] with GetWindowText ?

Thanks a lot !

4

3 に答える 3

14

You are probably compiling a Unicode project, so you can either:

  • Explicitly call the ANSI version of the function (GetWindowTextA), or
  • Use wchar_t instead of char (LPWSTR is a pointer to wchar_t)
于 2012-12-19T09:25:12.403 に答える
1

For modern Windows programming (that means, after the year 2000 when Microsoft introduced the Layer for Unicode for Windows 9x), you're far better off using "Unicode", which in C++ in Windows means using wchar_t.

That is, use wchar_t instead of char, and use std::wstring instead of std::string.

Remember to define UNICODE before including <windows.h>. It's also a good idea to define NOMINMAX and STRICT. Although nowadays the latter is defined by default.

于 2012-12-19T09:41:41.933 に答える
1

When calling Windows APIs without specifying an explicit version by appending either A (ANSI) or W (wide char) you should always use TCHAR. TCHAR will map to the correct type depending on whether UNICODE is #defined or not.

于 2012-12-19T21:57:22.917 に答える