August 1, 2011

Monkey666 Monkey666
Lab Rat
33 posts

get window title

 

I have the window process handle and id, how would I get the window title?

6 replies

August 1, 2011

Vass Vass
Hobby Entomologist
738 posts

For Windows?
See getWindowText function in WinAPI reference

 Signature 


Vasiliy

August 1, 2011

Monkey666 Monkey666
Lab Rat
33 posts

Ok I have and I’ve found this and added in to my code so like:

  1. char buffer[65536];
  2. ProcInfo *p = new ProcInfo();
  3. HANDLE hProc = OpenProcess(PROCESS_ALL_ACCESS,FALSE,entry.th32ProcessID);
  4. int txtlen=GetWindowTextLengthW(hProc);
  5. GetWindowText(hProc, buffer, txtlen);

Error is on line 4:

invalid conversion from ‘void*’ to ‘HWND__*’

Someone told me I would find it easy learning C++ already knowing C# pretty well, but most of this just doesn’t seem to make any sense :/

August 1, 2011

Vass Vass
Hobby Entomologist
738 posts

Try

  1. int txtlen=GetWindowTextLengthW((HWND__*)hProc);

Hehe, It almost not touch c++ and c# differences.

Just Welcome to world without GC and safe-type conversions. :D
Welcome to world of WinAPI :)

 Signature 


Vasiliy

August 1, 2011

Monkey666 Monkey666
Lab Rat
33 posts

Hey bro, I added what you explained above to what I posted but it just returns a single random letter each time, any ideas why it’s not getting the window title?

August 1, 2011

Vass Vass
Hobby Entomologist
738 posts

Oh… I’m was mistake too. I hate winapi :)

I did google very long and…
NOT simple ways get HWND from HANDLE

But I find difficult way, may be you can repeat this for your program.
http://www.codeguru.com/forum/showpost.php?p=1213838&postcount=3

It’s really stupid crazy method. But I’m not found anymore.

So, now I understand why Win developer hate C++ – winapi is unbelievable crap.

Hey, go to Linux – go to dark side – we still have cookies. :D

 Signature 


Vasiliy

August 1, 2011

Monkey666 Monkey666
Lab Rat
33 posts

I’ll check it out bro, thanks for the help :) And Linux {No Thanks!} lol, my applications are designed for windows users which I generally develop in C#, however I am trying to ‘up my game’ with C++, but I fear I have let myself in for a world of hurt.

 
  ‹‹ Confused about stricmp      [SOLVED] QVector3D normalization not working in Qt Creator debug mode? ››

You must log in to post a reply. Not a member yet? Register here!