Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

sample code for MsgHook32?

Posted on 1998-05-15
4
Medium Priority
?
300 Views
Last Modified: 2008-02-01
Hi,

  Has anybody used MsgHook32 control from Mabry before? If so, can you show me some sample codes? I can't seem to get it working. My codes are here:

Option Explicit

Private Sub Form_Load()
Msghook1.HwndHook = &HBDC
Msghook1.Message(&H3) = True
Msghook1.Message(&H5) = True
End Sub

Private Sub Form_Unload(Cancel As Integer)
Msghook1.HwndHook = 0
End Sub

Private Sub Msghook1_Message(ByVal msg As Long, ByVal wp As Long, ByVal lp As Long, result As Long)
Label1.Caption = "i got it"
InvokeWindowProc &HBDC, msg, wp, lp
End Sub


Nothing is being printed out after I run the program...

wyldsj
0
Comment
Question by:wyldsj
[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
  • 2
  • 2
4 Comments
 
LVL 5

Accepted Solution

by:
bin_huwairib earned 40 total points
ID: 1451332
wyldsj,

Try the following example.

Example
=======
1 - Add form1 to project1.
2 - Add Msghook1,text1 and command1 to form1.
3 - Create a top level menu named mnuPopupMain and a sub menu named mnuPopup.
4 - Paste this code:

Private Const WM_CONTEXTMENU& = &H7B

Private Sub Command1_Click()
 Msghook1.Message(WM_CONTEXTMENU) = Not Msghook1.Message(WM_CONTEXTMENU)
End Sub

Private Sub Form_Load()
 Msghook1.HwndHook = Text1.hWnd
 Msghook1.Message(WM_CONTEXTMENU) = True
End Sub

Private Sub mnuPopup_Click()
 MsgBox "Hi there"
End Sub

Private Sub Msghook1_Message(ByVal msg As Long, ByVal wp As Long, ByVal lp As Long, result As Long)
 If Msghook1.Message(WM_CONTEXTMENU) Then PopupMenu mnuPopupMain
End Sub


Best regards
Bin Huwairib
0
 

Author Comment

by:wyldsj
ID: 1451333
Hi huwairib:

 Thanks for your answer. Actually I need to hook some other window(not part of my application)'s message. Do you know whether that is possible? If you are sure that it is not possible by using MsgHook, let me know and I will give u a full credit :) Thanks again.

wyldsj
0
 
LVL 5

Expert Comment

by:bin_huwairib
ID: 1451334
wyldsj,

I don't think this is possible with this control because every window has it own WindowProc call back which will handle the window messages, so this control is replacing this procedure and handle messages for the window which contain this control.

Bin Huwairib
0
 

Author Comment

by:wyldsj
ID: 1451335
Okay... Thanks.

Regards,
wyldsj
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 (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…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
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

650 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