Solved

covert HWND to string.

Posted on 2007-11-28
6
2,603 Views
Last Modified: 2012-06-27
I am looking for.

string1 = tostring( hwnd hwnd)


0
Comment
Question by:Troudeloup
6 Comments
 
LVL 30

Assisted Solution

by:Axter
Axter earned 170 total points
ID: 20370221
Convert it to a number string.
0
 
LVL 22

Assisted Solution

by:grg99
grg99 earned 100 total points
ID: 20370223
A window handle is just an integer, so use sprintf or itoa or equivalent.

0
 
LVL 30

Assisted Solution

by:Axter
Axter earned 170 total points
ID: 20370227
char buf[99] = "";

sprintf(buf, "%p", hwnd);
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 30

Assisted Solution

by:Axter
Axter earned 170 total points
ID: 20370232
FYI:
I recommend using sprintf over itoa, because it supports %p, which is the type that should be used for pointers.
0
 
LVL 55

Assisted Solution

by:Jaime Olivares
Jaime Olivares earned 50 total points
ID: 20370264
in case of handlers, I suggest to use hex values, them are easier to read and compare:

char buf[9];
sprintf(buf, "%08X", hwnd);
0
 
LVL 4

Accepted Solution

by:
Ichijo earned 180 total points
ID: 20370279
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

0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question