Link to home
Start Free TrialLog in
Avatar of debbyt
debbyt

asked on

Is Subclassing Required In Order To Do This?

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.
Avatar of clifABB
clifABB

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.
Avatar of debbyt

ASKER

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?
ASKER CERTIFIED SOLUTION
Avatar of Dr. Kamal Mehdi
Dr. Kamal Mehdi
Flag of Greece image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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...."
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.