Solved

Is Subclassing Required In Order To Do This?

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

828 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