|
-
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
-
Nov 15th, 2006, 05:20 PM
#2
Hyperactive Member
Re: CallWindowProc Issue
your lparam isn't of proper type I believe. it expects a long, but you give it MAXMININFO which totals 8 longs see if it works if you declare SetWindowLong with MINMAXINFO for lparam..
-
Nov 15th, 2006, 05:33 PM
#3
Thread Starter
Hyperactive Member
Re: CallWindowProc Issue
I did that before but it did not seem to work.
Regards,
Jenova
-
Nov 15th, 2006, 05:37 PM
#4
Hyperactive Member
Re: CallWindowProc Issue
You should put types and constants above function declarations.. I doubt it sees your types..
-
Nov 15th, 2006, 05:54 PM
#5
Thread Starter
Hyperactive Member
Re: CallWindowProc Issue
I don't think that would cause the issue
-
Nov 16th, 2006, 05:45 AM
#6
Thread Starter
Hyperactive Member
Re: CallWindowProc Issue
Can anyone point in the right direction at all?
-
Nov 16th, 2006, 06:07 AM
#7
Re: CallWindowProc Issue
the lParam needs to be a Long.
you then use the CopyMemory API to get the MINMAXINFO structure that you can work with - then copy it back when you're done.
Check the example in the API FAQs
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
|