Solved

sample code for MsgHook32?

Posted on 1998-05-15
4
277 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
  • 2
  • 2
4 Comments
 
LVL 5

Accepted Solution

by:
bin_huwairib earned 10 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Okay... Thanks.

Regards,
wyldsj
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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…

772 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now