|
-
Nov 15th, 2006, 05:04 PM
#1
Thread Starter
Hyperactive Member
CallWindowProc Issue
I am in the middle of reading Steve Romans "Win32 API Programming with Visual Basic 6" and i am on to chapter 18 "Windows Subclassing", at the moment i am reading up on the CalWindowProc. I have come with this so far and it does not seem to be working, it is supposed to be a classic example of restricting the size of the form.
VB Code:
' Module Code
Option Explicit
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
' Allows us to set the window style
' Returns the Procedure address which will
' be stored in 'OldWindowProc'
Declare Function SetWindowLong _
Lib "user32" _
Alias "SetWindowLongA" ( _
ByVal hwnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) _
As Long
' Returns the cordinates for the
' mouse
Public Type POINTAPI
X As Long
Y As Long
End Type
' Holds the sizing information for
' the form
Private Type MINMAXINFO
ptReserved As POINTAPI
ptMaxSize As POINTAPI
ptMaxPosition As POINTAPI
ptMinTrackSize As POINTAPI
ptMaxTrackSize As POINTAPI
End Type
Const GWL_WNDPROC = (-4) ' Sets a new procdure address
Const WM_GETMINMAXINFO = &H24 ' Gets the window size information
Public OldWindowProc As Long ' Holds thw Old Window Address
Public Function NewWindowProc(hwnd As Long, Msg As Long, wParam As Long, lParam As MINMAXINFO) As Long
Dim Point As POINTAPI
' Check for any messages
Select Case Msg
' If the message is a sizeing message
Case WM_GETMINMAXINFO
' Limit the form size to the cursor co-ordinates
With lParam
.ptMaxTrackSize.X = Point.X
.ptMaxTrackSize.Y = Point.Y
.ptMinTrackSize.X = Point.X
.ptMinTrackSize.Y = Point.Y
End With
NewWindowProc = 0
Case Else
' Call the new Window Procedure
NewWindowProc = CallWindowProc(OldWindowProc, hwnd, Msg, wParam, lParam)
End Select
End Function
' Form Code
Option Explicit
Private Sub Form_Load()
OldWindowProc = SetWindowLong(Form1.hwnd, GWL_WNDPROC, AddressOf NewWindowProc)
End Sub
Private Sub Form_Unload(Cancel As Integer)
OldWindowProc = SetWindowLong(Form1.hwnd, GWL_WNDPROC, OldWindowProc)
End Sub
However, when i run the code it does not seem to work, i have tried other methods such as setting the form size to a specific height and width but it still does not seem to work. From what i have made out so far it it looks as though my application can not process the message and i am quite confident that this is the issue. Can you guys give me any hints as to where the problem lies and how i might be able to fix it?
Regards,
Jenova
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|