Solved

Get Window Name

Posted on 2000-05-16
12
593 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
Comment Utility
Try the foll to get the window caption/title,
CString strTitle;
::GetWindowText(hWnd,strTitle);
0
 

Expert Comment

by:pkkn
Comment Utility
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
Comment Utility
pkkn changed the proposed answer to a comment
0
 

Expert Comment

by:pkkn
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 2

Expert Comment

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

0
 
LVL 22

Expert Comment

by:nietod
Comment Utility
>> it return error sometimes
What sort of error?
0
 

Author Comment

by:hlava
Comment Utility
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
Comment Utility
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
Comment Utility
>> 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
Comment Utility
Comment accepted as answer
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
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…
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 learn how to clear a vector as well as how to detect empty vectors in C++.

772 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

14 Experts available now in Live!

Get 1:1 Help Now