General information
Category:
Windows API functions
Looking for VB gurus. Hope I am not asking too much. Here is VB code I need to be turned in VFP.
MODULE1 - 1
Option Explicit
Public Const HC_ACTION = 0
Public Const WH_CALLWNDPROC = 4
Public Const DOCUMENTEVENT_STARTDOCPRE = 5 ' before StartDoc is handled
Public Const DOCUMENTEVENT_STARTDOCPOST = 13 ' after StartDoc is handled
Public Const DOCUMENTEVENT_STARTPAGE = 6 ' StartPage handled
Public Const DOCUMENTEVENT_ENDPAGE = 7 ' EndPage handled
Public Const DOCUMENTEVENT_ENDDOCPRE = 8 ' before EndDoc is handled
Public Const DOCUMENTEVENT_ENDDOCPOST = 12 ' after EndDoc is handled
Type CWPSTRUCT
lParam As Long
wParam As Long
message As Long
hwnd As Long
End Type
Declare Function RegisterWindowMessage Lib 'user32'Alias 'RegisterWindowMessageA' (ByVal lpString As String) As Long
Declare Function SetWindowsHookEx Lib 'user32' Alias 'SetWindowsHookExA' (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
Declare Function UnhookWindowsHookEx Lib 'user32' (ByVal hHook As Long) As Long
Declare Function CallNextHookEx Lib 'user32' (ByVal hHook As Long, ByVal nCode As Long, ByVal wParam As Long, lParam As Any) As Long
Declare Function GetCurrentThreadId Lib 'kernel32' () As Long
Global nPDFEvent As Long
Global Hook As Long
Function PdfWndProc(ByVal nCode As Long, ByVal wParam As Long, lParam As CWPSTRUCT) As Long
'
' all messages will arrive here
' check if this is a PDF message and do some action depending on message type
'
Dim eventId As Integer
If (nCode = HC_ACTION) Then
If (lParam.message = nPDFEvent) Then
eventId = CInt(lParam.wParam And 65535)
Select Case eventId
Case DOCUMENTEVENT_STARTDOCPOST
Form1.List1.AddItem 'Document Started'
Case DOCUMENTEVENT_ENDDOCPOST
Form1.List1.AddItem 'Document Ended'
Case DOCUMENTEVENT_STARTPAGE
Form1.List1.AddItem 'Page Started'
Case DOCUMENTEVENT_ENDPAGE
Form1.List1.AddItem 'Page Ended'
End Select
End If
End If
PdfWndProc = CallNextHookEx(Hook, nCode, wParam, lParam)
End Function
Form1 - 1
Option Explicit
Private Sub ClearButton_Click()
' clear the messages list box
List1.Clear
End Sub
Private Sub StartButton_Click()
If Hook = 0 Then
' get the PDF driver event ID
nPDFEvent = RegisterWindowMessage('PDF Driver Event')
' hook all windows messages
Hook = SetWindowsHookEx(WH_CALLWNDPROC, AddressOf PdfWndProc, 0, GetCurrentThreadId)
End If
End Sub
Private Sub StopButton_Click()
If Hook <> 0 Then
' free message hook
UnhookWindowsHookEx Hook
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
If Hook <> 0 Then
' free message hook
' should also be done before exiting
UnhookWindowsHookEx Hook
End If
End Sub
Thanks
Mark
Next
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only