Declare Function SetWindowLong Lib "user32.dll" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
SetWindowLong sets a 32-bit value constituting the information about a window. This function can also set a 32-bit value within the block of extra memory given to the window, if such a block exists.
If an error occured, the function returns 0 (use GetLastError to get the error code). If successful, the function returns the previous setting of whatever 32-bit value was replaced.
None.
Const GWL_EXSTYLE = -20
Const GWL_HINSTANCE = -6
Const GWL_HWNDPARENT = -8
Const GWL_ID = -12
Const GWL_STYLE = -16
Const GWL_USERDATA = -21
Const GWL_WNDPROC = -4
Const DWL_DLGPROC = 4
Const DWL_MSGRESULT = 0
Const DWL_USER = 8
' Have window Form1 play the SystemAsterisk sound whenever it gets
' or loses the focus. Do this by specifying a new window procedure which
' plays the sound whenever the WM_ACTIVATE message is received. To
' process all other messages (and do whatever else WM_ACTIVATE should
' do), the procedure then calls the previous window procedure.
' *** Place this code in a module. ***
Const WM_ACTIVATE = &H6 ' identifier of the message
' The following variable is accessible to all code in this example.
Public pOldProc As Long ' pointer to the previous window function
' Define the new window procedure.
Public Function WindowProc (ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim retval As Long
' If the message is WM_ACTIVATE (we don't care about the parameters),
' play the SystemAsterisk sound.
If uMsg = WM_ACTIVATE Then
retval = PlaySound("SystemAsterisk", 0, SND_ALIAS Or SND_ASYNC)
End If
' No matter what happened, use the old window procedure to
' finish processing the message.
retval = CallWindowProc(pOldProc, hWnd, uMsg, wParam, lParam)
' Have this function return whatever the function above returned.
WindowProc = retval
End Function
' *** Place the following code wherever you wish. ***
Dim retval As Long ' return value
' Set the new window procedure for Form1, saving a pointer to the old one.
pOldProc = SetWindowLong(Form1.hWnd, GWL_WNDPROC, AddressOf WindowProc)
' Now WindowProc processes Form1's messages, playing the sound
' whenever Form1 is activated or loses activated status.
Last Modified: August 28, 1999
This page is copyright © 1999 Paul Kuliniewicz. Copyright Information