Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hypetia (Programmer) - Re: Code Library

Status
Not open for further replies.

RMS001

Programmer
Nov 12, 2002
45
CA
Hi Hypetia - I found your code for sub-classing to limit the size of a window fantastic!
In your message you mentioned that you found the solution in your code library. Is this a common access repository or just your personal stuff. I sure would like to see some of it. - Ron

Hypetia (Programmer) Mar 7, 2003
"Well, I found some ready-made code in my code library on this issue."
 
I think you'll find that Hypetia was referring to a personal code library. Many of us in the VB forums (and, I'm sure, in the other coding forums) have such libraries; it prevents reinventing the wheel...

As for seeing some of the code...well, just look back through the posts...
 
Thanks Ron, well this is not a common access repository but this library exists only on my hard disk.
(Ref. thread222-607885, thread222-494440.)

I wrote this code a long time ago and intercepted WM_SIZING message to achieve this function. This restriction in minimum size is usually achieved by intercepting the WM_GETMINMAXINFO message and tampering the information in MINMAXINFO structure as strongm does in his solution. But I decided to go the other way and used WM_SIZING to do the same.

If you are using my code, I would advise you to do some modifications to it. To simplify the code to just fit my needs, I used some crazy shortcuts like the use of RECT in declarations of CallWindowProc and WindowProc functions and some really weird use of InStr function.

I think I should correct the bad bits in that code and change the declarations to their original form so that the callback procedure may be used for other purposes as well.

I want you to modify the code in the module as follows. I have underlined the portions of code which are modified/added.

1. Change the declaration of CallWindowProc to its original form.
___
Private 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
___

2. Add the declaration of CopyMemory function in the module.
___
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
___

3. Modify the callback procedure WindowProc as below.
___
Private Function WindowProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Const WM_SIZING = 532
Const WM_DESTROY = &H2
If uMsg = WM_SIZING Then
Dim R As RECT
CopyMemory R, ByVal lParam, Len(R)
If InStr(36, wParam) = 0 And R.Right - R.Left < Min_Width Then
If InStr(147, wParam) Then
R.Left = R.Right - Min_Width
Else
R.Right = R.Left + Min_Width
End If
End If
If InStr(12, wParam) = 0 And R.Bottom - R.Top < Min_Height Then
If InStr(345, wParam) Then
R.Top = R.Bottom - Min_Height
Else
R.Bottom = R.Top + Min_Height
End If
End If
CopyMemory ByVal lParam, R, Len(R)
ElseIf uMsg = WM_DESTROY Then
Unhook
End If
WindowProc = CallWindowProc(lpPrevWndProc, hwnd, uMsg, wParam, lParam)
End Function
___
Although the code was functional in its original form but now it looks better than the original as some of the shortcuts are removed from the code.
 
Hi Hypetia – that certainly is a more generic procedure call, thankyou for making the modifications - and it makes a little more sense to me now, but I still like the way you used the RECT type to call the function instead of ‘Long’. As someone who is still trying to understand API’s, how can that not affect the way the CallWindowProc receives the information in the DLL itself. Doesn’t the data passed have to match the pre-defined function definition? I have been using API calls for over a year, but thought the only modification you could make was to change a data-type to ‘Any’ or whether it was ByVal or ByRef.

Thanks to you and strongm for the time and effort you put into helping all of us.

- And Confucius turned and pinned me with a glare. He replied, “Well… Who’s Murphy?”
 
could i ask RMS001 to explain the &quot;murphy&quot; bit? way more cryptic than any API call...
 
Confucious says: &quot;...&quot; and Murphy's Law



Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
i still don't understand what it was that prompts this from confucious ...
 
Well, CajunCenturion sort of said it all - but since you asked, I will explain:
Confucius was one of the first world-renowned logical thinkers (thus programming) and rarely, if ever, was quoted as producing a weak maxim (thus Murphy’s Law).
 
still don't follow, despite being familiar with confucious and murphy's law. are you saying that murphy's law is a weak maxim and this would has annoyed confucious, to whom a comment that murphy's law was responsible for an event would seem trite?

ah, that makes sense. i understand now, thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top