Link to home
Start Free TrialLog in
Avatar of dwcronin
dwcroninFlag for United States of America

asked on

how do I raise an event?

I use VB 6.0   I see that there are multiple places that I have to put code to handle events and
I keep getting it wrong.  I want to do I have a form that has a button.  When that button is clicked,
another program that is running at the same time as the first program catches a "p1_button_in"
event and turns a light on.
Avatar of unknown_routine
unknown_routine
Flag of United States of America image

You can not raise an event that happens in the 1st program in the second program.


However you can use Message API functions, so when that event happen in the 1st program

they send it to the second and second program turns the light on.
Another easier ways is that when event happens in the 1st program it writes a flag variable to  a textfile and

seconds program check that files to do some action.
if still unclear,
please explain more clearly.
Avatar of dwcronin

ASKER

I was trying to avoid something like writing to a file.  That is going to use disk access and I know that is slow.
I am trying to get the second program to respond immediately to the first programs button click.
ASKER CERTIFIED SOLUTION
Avatar of Erick37
Erick37
Flag of United States of America 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
Then Consider writing and readiing from the registry which is very fast.

if you need the code I can supply it here.

Avatar of aParser
aParser

What you're talking about -- I think -- is interprocess communication.  There are many ways to do it, one of the most common is the textfile approach that unknown_routine gave you.

The approach that I used under NT 4.0 is to use mailslots.  The more modern approach is to use Microsoft Messaging.

You could also use callbacks.  It is a slightly more sophisticated approach, but one that requires a fair amount of coding.
http://msdn.microsoft.com/library/en-us/vb98/html/vbsmpCallback.asp?frame=true

You could also do something like store the hWnd of your "lightbulb" program, then when your "click" application starts, you read the hWnd (or title) from whereever you've stored it.  When the user clicks the button in the "click" application, you make the "lightbulb" application the foreground application and use SendKeys to send a key sequence that activates your lightbulb.

You could also look at the SendMessage and PostMessage APIs.  This would be a very low-level approach.