Solved

Is Subclassing Required In Order To Do This?

Posted on 1998-06-01
5
162 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

708 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

13 Experts available now in Live!

Get 1:1 Help Now