Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 635
  • Last Modified:

Get Window Name

I have hwnd of the windows on Desktop.Which API function Get name of the window.I have ONLY HWND.
0
hlava
Asked:
hlava
  • 4
  • 3
  • 3
  • +1
1 Solution
 
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
 
pkknCommented:
pkkn changed the proposed answer to a comment
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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
 
nietodCommented:
>> 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
 
hlavaAuthor Commented:
Comment accepted as answer
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 4
  • 3
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now