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
Solved

sample code for MsgHook32?

Posted on 1998-05-15
4
286 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
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

Suggested Solutions

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…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…

856 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