Solved

Get Window Name

Posted on 2000-05-16
12
631 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
[X]
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
  • 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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 

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
 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
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 be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

623 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