covert HWND to string.

I am looking for.

string1 = tostring( hwnd hwnd)

Who is Participating?
IchijoConnect With a Mentor Commented:
Perhaps you want to get the text or title of the window:
#include <string>
using namespace std;
void HwndToString(HWND hWnd, wstring& sText)
    int nLength = GetWindowTextLength( hWnd );
    sText.reserve( nLength );
    GetWindowText( hWnd, &sText[0], nLength + 1 );

Open in new window

AxterConnect With a Mentor Commented:
Convert it to a number string.
grg99Connect With a Mentor Commented:
A window handle is just an integer, so use sprintf or itoa or equivalent.

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

AxterConnect With a Mentor Commented:
char buf[99] = "";

sprintf(buf, "%p", hwnd);
AxterConnect With a Mentor Commented:
I recommend using sprintf over itoa, because it supports %p, which is the type that should be used for pointers.
Jaime OlivaresConnect With a Mentor Software ArchitectCommented:
in case of handlers, I suggest to use hex values, them are easier to read and compare:

char buf[9];
sprintf(buf, "%08X", hwnd);
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.