|
-
Jun 6th, 2000, 03:23 AM
#1
Thread Starter
New Member
I have been successful in subclassing a form and creating a custom Message Handler (WndProc Function).
What I would like to do is handle WM_SIZE or WM_WINDOWPOSCHANGING messages by verifying that the new form size is in fact within the acceptable range. However, the data I require in order to complete this is located in a memory block pointed to by lParam.
My question is this: How can I extract this data, change it as required, then put it back where Windows can then use it?
In the case of the WM_WINDOWPOSCHANGING Message, lParam is a pointer to a WINDOWPOS struct. I have been unsuccessful at even extracting this data correctly let alone modifying it or putting it back.
In the case of WM_SIZE, the lo-word of lParam is the new width and the hi-word is the new height. I am able to extract this information, but how do I modify it so that Windows knows that I modified it?
Any assistance would be appreciated.
[Edited by MGervais77 on 06-06-2000 at 04:26 PM]
Regards,
Marc Gervais, MCP
Systems Analyst
-
Jun 6th, 2000, 02:06 PM
#2
New Member
I think you should write a hook!
I think you should write a hook using vc.
-
Jun 6th, 2000, 06:11 PM
#3
Frenzied Member
You don't need a hook, you need the CopyMemoryApi
Code:
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
you can copy the memory from the block using
CopyMemory uSize,ByVal lParam, LenB(uSize)
where Size is a user defined type to hold the data
copymemory copies memory from one location to another, in VB you usually put the variables straight in and ignore the pointers, but you can put a pointer in by preceeding it with the word ByVal. To copy It Back after you changed it use
CopyMemory ByVal lParam, uSize, LenB(uSize)
hope this helps
-
Jun 6th, 2000, 08:48 PM
#4
Thread Starter
New Member
Thanks, but...
myrabit... I appreciate you taking the time to respond to my request, but your response does not help in solving this problem.
Sam... I have tried your suggestion, but when I copy the data back into the memory location pointed to by lParam, I receive an Exception Unhandled Error (glorified GPF).
Here is the code I am using:
Code:
'...snip...
Dim tMinMaxInfo As MINMAXINFO
'...snip...
Case WM_GETMINMAXINFO
Call CopyMemory(tMinMaxInfo, ByVal lParam, LenB(tMinMaxInfo))
' Verify that the form is not being resized
' smaller than allowed
If ((tMinMaxInfo.ptMinTrackSize.x * Screen.TwipsPerPixelX) < frm.MinWindowWidth) Then
tMinMaxInfo.ptMinTrackSize.x = frm.MinWindowWidth
End If
If ((tMinMaxInfo.ptMinTrackSize.y * Screen.TwipsPerPixelY) < frm.MinWindowHeight) Then
tMinMaxInfo.ptMinTrackSize.y = frm.MinWindowHeight
End If
Call CopyMemory(lParam, tMinMaxInfo, LenB(tMinMaxInfo))
' Call default message handler
WndProc = CallWindowProc(frm.OldProc, hwnd, wMsg, wParam, lParam)
'...snip...
Any suggestions?
[Edited by MGervais77 on 06-07-2000 at 09:55 AM]
Regards,
Marc Gervais, MCP
Systems Analyst
-
Jun 6th, 2000, 09:20 PM
#5
Frenzied Member
you missed out a ByVal
Code:
Call CopyMemory(lParam, tMinMaxInfo, LenB(tMinMaxInfo))
should be
Code:
Call CopyMemory(ByVal lParam, tMinMaxInfo, LenB(tMinMaxInfo))
so what the code was dooing was trying to copy the whole min max info structure into the long value lParam, with the new byval you'll be sorted.
-
Jun 6th, 2000, 11:07 PM
#6
Thread Starter
New Member
Finally!
Thanks, Sam!
I actually to switch to another message to trap. I am now trapping the WM_WINDOWPOSCHANGING message and checking to see what the window is being resized to. For some reason the WM_GETMINMAXINFO message was not working. Oh well. I have the desired result.
Regards,
Marc Gervais, MCP
Systems Analyst
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
|