getclassname and getwindowtext help

closed account (zwA4jE8b)
I am trying to get the open window class names and caption enumerated.
Right now (line 27) is outputting numbers. How do I get a string (the class name)? I am also having trouble with getwindow text function. What datatype do I use to store the text? I am using LPWSTR but I keep getting an uninitialized error.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <Windows.h>
#include <iostream>
#include <vector>
#include <string>
using namespace std;

void boolproc(vector<HWND>&);

int main()
{
	wchar_t* _classbuf = new wchar_t[255];
	LPWSTR _capbuf;

	vector<HWND> _Vhwnd;
	vector<HWND>::iterator iterH;
	vector<LPWSTR> _Vclass;
	vector<LPWSTR>::iterator iterC;
	vector<LPWSTR> _Vcaption;
	vector<LPWSTR>::iterator iterS;

	boolproc(_Vhwnd);
	for (iterH = _Vhwnd.begin(); iterH != _Vhwnd.end(); ++iterH)
	{
		GetClassName(*iterH, _classbuf, 255);
		_Vclass.push_back(_classbuf);
		cout << *_classbuf << " ";
		//GetWindowText(*iterH, _capbuf, 255);
		//_Vcaption.push_back(_capbuf);
		//cout << _capbuf << endl;
		//::SendMessage(*iterV, WM_CLOSE, 0, 0);
	}
	cin.get();
	return 0;
}

void boolproc(vector<HWND>& _hV)
{

	HWND hwnd;
	_hV.push_back(GetDesktopWindow());
	if ((hwnd = FindWindowA("IEFrame", 0)) != NULL)
		_hV.push_back(hwnd);
	if ((hwnd = FindWindowA(NULL, "Untitled - Notepad")) != NULL)
		_hV.push_back(hwnd);
	if ((hwnd = FindWindowA(NULL, "Steam")) != NULL)
		_hV.push_back(hwnd);
	if ((hwnd = FindWindowA(NULL, "Windows Task Manager")) != NULL)
		_hV.push_back(hwnd);

}

This is a windows specific question, so move it to windows section.

1
2
TCHAR tchWndText[128];
GetWindowText(hwndWnd, tchWndText, 128);


and you will the text of the window having handle hwndWnd in techWndText.
Topic archived. No new replies allowed.