Solved

sample code for MsgHook32?

Posted on 1998-05-15
4
290 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 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

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…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

749 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