Get Window Name

I have hwnd of the windows on Desktop.Which API function Get name of the window.I have ONLY HWND.
hlavaAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
nietodConnect With a Mentor Commented:
>> 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
 
vbk_bgmCommented:
Try the foll to get the window caption/title,
CString strTitle;
::GetWindowText(hWnd,strTitle);
0
 
pkknCommented:
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
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
pkknCommented:
pkkn changed the proposed answer to a comment
0
 
pkknCommented:
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
 
nietodCommented:
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
 
hlavaAuthor Commented:
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
 
vbk_bgmCommented:
Hi hlava,
Try ,
TCHAR strTitle[_MAX_PATH];
::GetWindowText(hWnd,strTitle,_MAX_PATH);

0
 
nietodCommented:
>> it return error sometimes
What sort of error?
0
 
hlavaAuthor Commented:
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
 
hlavaAuthor Commented:
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
 
hlavaAuthor Commented:
Comment accepted as answer
0
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.