?
Solved

Getting messages from other controls.

Posted on 2002-07-04
12
Medium Priority
?
147 Views
Last Modified: 2010-05-02
I want to create a control which has some other controls name and their some events name. when that event occur on that control, our control automatically calls its own particular function.
Thanks.  
0
Comment
Question by:AhmadKhan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 2
  • +2
12 Comments
 
LVL 2

Expert Comment

by:priya_pbk
ID: 7131075
kindly elaborate!!

-priya
0
 

Author Comment

by:AhmadKhan
ID: 7131447
An ActiveX Control such as Mess1 placed on a Form, where
two more controls Text1 and Command1 placed:
when we write this code.
Mess1.controlName="Text1"
Mess1.controlEvent="change"
And when the change event of Text1 occurs a function of Mess1 say show() will be invoked.

Is it possible that any ActiveX control gets the messages of another control.
0
 
LVL 15

Expert Comment

by:ameba
ID: 7132390
Yes, that's possible.

For ActiveX controls which are not VB intrinsic controls, it's easy - using VBControlExtender object.

Dim WithEvents x As VBControlExtender

Private Sub x_ObjectEvent(Info As EventInfo)
    If Info.Name = yourEventname Then
        Beep ' do something
    End If
End Sub


For intrinsic VB controls (TextBox, PicturBox,...) there isn't such late bound mechanism to catch events.  You'll have to create helper classes for each type of such control.
Helper class will have a variable declared "WithEvents" and a bunch of delegation code for each type of event you want to handle.

There is a limitation - that won't work if control is in control array.  So, you'll have to check that and notify user that events are not supported.
0
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!

 
LVL 6

Expert Comment

by:pierrecampe
ID: 7133002
ping
0
 

Author Comment

by:AhmadKhan
ID: 7133240
Thanks ameba
but can I use any Windows API function such as GetMessage()
b/c I want to capture any event of any control.
You can see "Spy" which comes with Visual Studio. I like this software.
0
 
LVL 15

Expert Comment

by:ameba
ID: 7133636
That is different - windows messages are not the same thing as events.
The technique to do that is Subclassing, and I do not like it - too hardcore and there is a problem with debugging such application.

Basically, you subclass your form:
Private Sub Form_Load()
     oldWndProc = SetWindowLong(Me.Hwnd, GWL_WNDPROC, AddressOf MyWndProc)
End Sub

and then catch all messages in a module, in MyWndProc() function.
http://coolvb.cooltech.org/subclass.shtml
0
 

Author Comment

by:AhmadKhan
ID: 7137230
Ya that is a good solution and I've find it on MSDN.
under this topic "Passing Function Pointers to DLL Procedures and Type Libraries"
it's a hook concept. but how can I hook multiple windows handles. plz first see the above topic on MSDN where u'll see this line Me.hook to hook form window.
Now I'm trying to solve this problem using this technique.
I'm very thankful to u.

0
 
LVL 15

Expert Comment

by:ameba
ID: 7137423
Sorry, I stopped answering EE questions because of some issues...  Do NOT accept my comment as answer.
0
 

Author Comment

by:AhmadKhan
ID: 7137518
Ok
0
 
LVL 6

Expert Comment

by:pierrecampe
ID: 7137620
ameba
Please do not leave us because some j...k thinks he does not have to follow ee guidelines
you have always been a great help to me in the past
and i only hope i can count on your help in the future
Thanks
Pierre
0
 
LVL 15

Expert Comment

by:ameba
ID: 8981459
AhmadKhan,
No comment has been added lately (380 days), so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area for this question:

RECOMMENDATION: PAQ and Refund

-- Please DO NOT accept this comment as an answer ! --

Moderator will finalize this question in 7 days.

Thanks,
ameba
acting as EE Cleanup Volunteer


--
Sorry for not returning here, I hope you found some component which does what you want.
Regards,
ameba
0
 

Accepted Solution

by:
YensidMod earned 0 total points
ID: 9056087
Question is PAQ'd and points refunded.

YensidMod
Community Support Moderator @Experts Exchange
0

Featured Post

Industry Leaders: 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 (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…
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…
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…
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…
Suggested Courses
Course of the Month11 days, 7 hours left to enroll

752 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