Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

covert HWND to string.

Posted on 2007-11-28
6
2,619 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
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.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

809 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