Solved

Is Subclassing Required In Order To Do This?

Posted on 1998-06-01
5
167 Views
Last Modified: 2010-05-03
I have two VB applications(call them A and B), and I want A to be notified when B gets focus(and A loses focus).  Is there a VB event within application A I can generate when this happens?  Do I have to use windows subclassing?  I would like to avoid subclassing if I can.  

Furthermore, if I have to subclass, what's the best way to do this? I know that the message I need to subclass is WM_ACTIVATEAPP or WM_ACTIVATE.  Do I need to purchase a third party OCX?  

Please Advise,

Thanks.
0
Comment
Question by:debbyt
  • 2
  • 2
5 Comments
 
LVL 6

Expert Comment

by:clifABB
ID: 1462249
Well, you don't *really* have to subclass.

You could let B write to an ini file when it changes focus and have A constantly poll (through a timer control) the ini file for a change in B's focus.

But subclassing is so much easier on the resources.
0
 

Author Comment

by:debbyt
ID: 1462250
I know I can use a timer to poll for the name of the foreground window with an API call, but this is very wasteful especially when there's no way to know when the focus will change.

So is subclassing the only reasonable way?
0
 
LVL 7

Accepted Solution

by:
kamall earned 100 total points
ID: 1462251
debbyt,
One way is to use DDE between the two applications. (I am not good in DDE), but you should find some examples in the VB samples directory.
The second way is to use a timer in application A, and check for its Title. In app. B, you can simply use the SetWindowText API  to change the title of the A application (for example, append a space to the end of the title). Now reading the title of A in its timer event, you get the notification, and reset its title.
Hope that helps.
Regards
0
 
LVL 7

Expert Comment

by:kamall
ID: 1462252
The
"In app. B, you can simply use the SetWindowText API  to change the title of the A application"
means
"When app B gets the focus (your form in app. B), you can simply...."
0
 
LVL 6

Expert Comment

by:clifABB
ID: 1462253
Yep.  That's why I said it was easier on the resources.

I did some tests and, apparently, you'll have to have a third-party control such as MessageBlaster (a shareware ocx available at various shareware sites) or Spyworks (available from Desaware - www.desaware.com)

Once you retrieve one of these, let us know if you need some help subclassing.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

813 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

17 Experts available now in Live!

Get 1:1 Help Now