You are doing a lot of error. I believe you don't understand the data types.
This is the first problem:
|
struct TWindowItem {
HWND Descriptor;
char Caption;
char ClassName;
};
|
|
Both Caption and ClassName should be strings (array of chars) not char. Should be something like this:
|
struct TWindowItem {
HWND Descriptor;
std::string Caption;
std::string ClassName;
};
|
|
Second, this is another big mistake:
|
LPWSTR Buff;
LPWSTR NameOfClass;
GetWindowText(WHandle, Buff, 254);
GetClassName(WHandle, NameOfClass, 254);
|
|
LPWSTR is a wchar_t*. What you do with Buff and NameOfClass is to declare to wchar_t pointers, but you never initialize memory for them. So of course, you get garbage and your application crashes.
I would do something like:
|
BOOL EnumWindowsProc(HWND WHandle, long lParam)
{
TCHAR Buff[255] = {0};
TCHAR NameOfClass[255] = {0};
GetWindowText(WHandle, Buff, 255);
GetClassName(WHandle, NameOfClass, 255);
TWindowItem tempitem;
tempitem.Descriptor = WHandle;
tempitem.Caption = std::string(Buff);
tempitem.ClassName = std::string(NameOfClass);
OoMetaPanel2::WindowList.push_back(tempitem);
return TRUE;
|
|
Of course, if you build for UNICODE, you have to use std::wstring instead of std::string.
|