Hey! Currently trying to read the Value / Caption from a button or Label. The only Problem: It just returns the first Character :-S Any idears to resolve?
What happens when you set "length" to some large number like 256, just for diagnostic purposes? Are you sure your handles in your 'mapObjectHandler[]' array are valid?
Hey! if i set it to 256 its still just the first Character :-(. If i Use GetWindowTextA it returns the full string. But i need to handle it as wstring not as string :-S
My guess is that it is because you are trying to create an std::wstring by passing it a pointer to an array, then you are returning a single std::wstring.
I'd say verify that the values in your hwnd array are valid, or that you are not trying to access an element outside of the range of that array. Here's what I did since getting hwnd values for Windows can be a PITA, I hard coded the value from a valid Thread ID in Process Explorer:
#include <iostream>
#include <string>
#define UNICODE
#include <windows.h>
void pause()
{
std::cin.sync();
std::cin.ignore();
}
BOOL CALLBACK WindowsProc(HWND hwnd, LPARAM lParam)
{
int length = 256; //SendMessage(hwnd,WM_GETTEXTLENGTH,0,0);
wchar_t* buffer = newwchar_t[length+1];
GetWindowTextW(hwnd, buffer, length);
std::wstring str(buffer);
delete[] buffer;
std::wcout << str << std::endl;
return TRUE;
}
int main()
{
EnumDesktopWindows(GetThreadDesktop(5524), WindowsProc, NULL); //HERE IS THE HARD CODED THREAD ID VALUE THAT YOU MAY NEED TO CHANGE
pause();
return 0;
}
This seems to work for me.
EDIT: I may be using the term "worked" too loosely. This will give the titles of threads that have open Windows along with a bunch of white space from threads that don't.
Hey! I'am not trying to get the Window catption, i want to get the buttonlabels text. the problem i don't understand:
if i use GetWindowTextA for an CreateWindowExW button... it will give me the full caption. But also if i try to convert the result into wstring it just gives me the first character :-(
i can't get more then the first Char with GetWindowTextW and with GetWindowTextA it works. But if you convert from ascii to wide then the new var also just owns the first character :-S. So there seems to be a problem between ascii and widestring -.-. Don't got a clue what could be wrong :-(
Have you updated mingw lately? I've about given up on trying to use it with the WinAPI the default installation is just missing too much. There are off shoot mingw's that I hear work pretty well but I just run MSVC 2010 in Code::Blocks.