JSlavin0828
Jun 21st, 2000, 03:26 PM
I have a message coming to a function, with about 5 different parts...
1. wnd - window handle
2. msg - message number
3. wp - wParam
4. lp - lParam
5. retval - long val to return to calling function
etc...
the lp (lParam) contains information, i want to see. How do i see this information? pick it apart? i think with c++ you use LOWORD etc.... but how with vb?
thanks
email: JSlavin0828@aol.com
smiffe
Jun 22nd, 2000, 01:09 PM
heres an example that tells you when a disk is inserted or
ejected from a cd disk drive. It uses lparam to tell the
drive letter of the drive affected. put this in a module
and add a form to the project Onform load call hook(me)
and on form_unload call unhook then play with the cd drive.Option Explicit
Dim lpPrevWndProc As Long
Dim gHW As Long
Const GWL_WNDPROC = -4
Const WM_DEVICECHANGE = 537
Const DBT_DEVICEARRIVAL = 32768
Const DBT_DEVICEREMOVECOMPLETE = 32772
Private Type DEV_BROADCAST_HDR
DBCH_Size As Long
DBCH_DeviceType As DBT_DEVTYPE
DBCH_Reserved As Long
End Type
Private Type DEV_BROADCAST_VOLUME
DBCV_Size As Long
DBCV_DeviceType As Long
DBCV_Reserved As Long
DBCV_UnitMask As Long
DBCV_Flags As Integer
End Type
Private Enum DEV_BROADCAST_FLAGS
DBTF_Media = 1 'media comings and goings
DBTF_NET = 2 'network volume
End Enum
Private Enum DBT_DEVTYPE
DBT_DEVTYP_OEM = &H0 ' oem-defined device type
DBT_DEVTYP_DEVNODE = &H1 ' devnode number
DBT_DEVTYP_VOLUME = &H2 ' logical volume
DBT_DEVTYP_PORT = &H3 ' serial, parallel
DBT_DEVTYP_NET = &H4 ' network resource
'#if(WINVER >= =&H040A)
DBT_DEVTYP_DEVICEINTERFACE = &H5 ' device interface class
DBT_DEVTYP_HANDLE = &H6 ' file system handle
'#endif /* WINVER >= =&H040A */
End Enum
Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" _
(ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, _
ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
(ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
(Destination As Any, Source As Any, ByVal Length As Long)
Public Sub Hook(frm As Form)
gHW = frm.hWnd
lpPrevWndProc = SetWindowLong(gHW, GWL_WNDPROC, AddressOf WindowProc)
End Sub
Public Sub UnHook()
Dim lngReturnValue As Long
lngReturnValue = SetWindowLong(gHW, GWL_WNDPROC, lpPrevWndProc)
End Sub
Public Function WindowProc(ByVal hWnd As Long, ByVal uMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
Dim Header As DEV_BROADCAST_HDR
Dim Volume As DEV_BROADCAST_VOLUME
Dim DriveLetter As String
Dim sOut As String
Dim I As Integer
On Error Resume Next
If uMsg = WM_DEVICECHANGE Then
If (wParam = DBT_DEVICEARRIVAL) Or (wParam = DBT_DEVICEREMOVECOMPLETE) Then
CopyMemory Header, ByVal lParam, Len(Header)
If Header.DBCH_DeviceType = DBT_DEVTYP_VOLUME Then
CopyMemory Volume, ByVal (lParam), Len(Volume)
If Volume.DBCV_Flags > 0 Then DriveLetter = Chr$(65 + (Log(Volume.DBCV_UnitMask) / Log(2)))
Select Case wParam
Case DBT_DEVICEARRIVAL
If Volume.DBCV_Flags = DBTF_Media Then
sOut = "Media inserted into drive " & DriveLetter
Else
sOut = "Drive attached as " & DriveLetter
End If
Case DBT_DEVICEREMOVECOMPLETE
If Volume.DBCV_Flags = DBTF_Media Then
sOut = "Media ejected from drive " & DriveLetter
Else
sOut = "Drive detached from " & DriveLetter
End If
Case Else
sOut = vbNullString
End Select
End If
If Len(sOut) > 0 Then MsgBox sOut, vbOKOnly + vbInformation
End If
End If
WindowProc = CallWindowProc(lpPrevWndProc, hWnd, uMsg, wParam, lParam)
End Function