[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

sample code for MsgHook32?

Posted on 1998-05-15
4
Medium Priority
?
301 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 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

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…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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

873 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