Solved

HWND of an other application !

Posted on 1998-02-13
5
299 Views
Last Modified: 2013-11-20
How is it possible to retrieve the HWND of an other application
when I don't know his title.
The title of the other application is changing.

I wan't to use SendMessage in one application to send messages to
the second application.

APPLICATION 1  <---> (WM_USER + x) <---> APPLICATION 2

The title of both application are changing.
I can't use (FindWindow).

Can some one give me an example to do this ?

Thanks.
0
Comment
Question by:mike_marquet
5 Comments
 
LVL 8

Expert Comment

by:MikeP090797
ID: 1316152
You must have some information on the app - it's proccess id or something. If you don't know anything, you can use EnumWindows to get all existing windows and pick the one you need.
0
 
LVL 15

Expert Comment

by:Tommy Hui
ID: 1316153
You can use FindWindow if the classname of the window remains the same. It is highly unlikely that the classname of the window to change constantly.

If the classname is not unique, then you will have to use EnumWindows to find it.
0
 

Author Comment

by:mike_marquet
ID: 1316154
Ok but I have a problem with the FindWindow function. This function takes 2 parameters :
 ::FindWindow(<Class name>, <Title name>)
When I use this syntax : FindWindow(NULL,"TITLE") OK
but I don't know how to use the 'Class name'. What is it.
Is the first parameter the name of the class of the other application from which I wan't to have the HWND ?

class MyDlg : public CDialog
 {
  ...
 }

Must I write this : FindWindow("MyDlg", NULL); ?
0
 
LVL 4

Expert Comment

by:jtwine100697
ID: 1316155
If you have control over both applications, then you can set the WNDCLASS of the applications window(s).  

The "ClassName" is the "Class" of the window.  For example, the common Edit Control has a classname of "Edit".  You can set the classname when you register a new window class. (Take a look at AfxRegisterClass(...).)

Another thing you can do, although not the most effecient, is to enumerate all windows, and send them each (or only specific ones) a custom window message, expecting a magic nunber as a return.  When you get the proper reply, you have found your window.  This does, however, require that you can add code to the application(s) that you are looking for.

-=- James.
0
 
LVL 7

Accepted Solution

by:
galkin earned 20 total points
ID: 1316156
To retreive class name of specific window use GetClassName(Ex). If you are programming with MFC remember MFC generates unique class name for each mainframe window( if you have dialog application your dialog window class will have also unique name). This name is generated from MFC class AfxFrameOrView42 and handle of cursor and icon since they are actually class and not window attributes. So you cannot rely on specific class name to use in FindWindow. Other way, inpite of it being rahter not trivial and complicated is to register your own class with your predefined name but which would have the same attribute as if it were MFC class. Then knowing class name you can use it in Findwindow
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

Suggested Solutions

Title # Comments Views Activity
mixString challenge 36 111
fizzArray  challenge 1 58
firstChar challenge 13 107
x-bar in Google Sheets 2 25
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

911 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

25 Experts available now in Live!

Get 1:1 Help Now