Solved

Get Window Name

Posted on 2000-05-16
12
603 Views
Last Modified: 2010-05-18
I have hwnd of the windows on Desktop.Which API function Get name of the window.I have ONLY HWND.
0
Comment
Question by:hlava
  • 4
  • 3
  • 3
  • +1
12 Comments
 
LVL 2

Expert Comment

by:vbk_bgm
ID: 2813496
Try the foll to get the window caption/title,
CString strTitle;
::GetWindowText(hWnd,strTitle);
0
 

Expert Comment

by:pkkn
ID: 2813584
Hai vbk,

if you have the HWND, try the following lines of code to get the text from that window ...
 
CString strWindowText;
char szText[255];
::SendMessage(HWND, WM_GETTEXT, 255, (LPARAM)szText);
strWindowText = szText;

Hope It will help you.


0
 

Expert Comment

by:pkkn
ID: 2813596
pkkn changed the proposed answer to a comment
0
 

Expert Comment

by:pkkn
ID: 2813599
Hai hlava,

if you have the HWND, try the following lines of code to get the text from that window ...
   
CString strWindowText;
char szText[255];
::SendMessage(HWND, WM_GETTEXT, 255, (LPARAM)szText);
strWindowText = szText;

Hope It will help you.




0
 
LVL 22

Expert Comment

by:nietod
ID: 2813860
GetWindowText() would be better than SendMessage().  It will be much faster and far simpler.  (SendMessage() will require a thread context switch among other things.)
0
 

Author Comment

by:hlava
ID: 2816070
But syntaxe of GetWindowText is
int GetWindowText(

    HWND hWnd,      // handle of window or control with text
    LPTSTR lpString,      // address of buffer for text
    int nMaxCount       // maximum number of characters to copy
   );

it return error sometimes
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 2

Expert Comment

by:vbk_bgm
ID: 2816214
Hi hlava,
Try ,
TCHAR strTitle[_MAX_PATH];
::GetWindowText(hWnd,strTitle,_MAX_PATH);

0
 
LVL 22

Expert Comment

by:nietod
ID: 2816618
>> it return error sometimes
What sort of error?
0
 

Author Comment

by:hlava
ID: 2816880
When I try to view it(ShowMessage(WindowName);)
or return length is Zero(all finded windows)
or sometimes are cutted forexample(winpopup is winpo":{)
0
 

Author Comment

by:hlava
ID: 2816887
I do it on C++Bulder 3 Profesional.But it is API function and it is same like on Visual C++.isn't it?
0
 
LVL 22

Accepted Solution

by:
nietod earned 100 total points
ID: 2817503
>> sometimes are cutted forexample(winpopup is winpo":{)
The last parameter is the size of the buffer that the name is to be placed in.  If this size is too small, the name will be truncated to fit the buffer.  Just create a longer buffer and specify a longer length in the last parameter.

>> it is same like on Visual C++.isn't it?
API functions are part of windows.  They don't have anything to do with a particular compiler manufacturer or a particular language.  i.e. GetWindowText() works the same in assembly, C, basic, Pascal etc.  Its not part of any language.
0
 

Author Comment

by:hlava
ID: 2872973
Comment accepted as answer
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
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.

864 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now