Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Is Subclassing Required In Order To Do This?

Posted on 1998-06-01
5
Medium Priority
?
177 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 200 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

971 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