Library tutorials & articles
Subclassing
- Introduction
- Catching those messages!
- Using messages - MAXMIN INFO
- Using messages - MENU STATUS
- Other Messages
- Using SSubTmr
Using messages - MAXMIN INFO
One good example of using the messages sent to you is setting the Maximimum width and height for your form. You can do this using the Form_Resize event, however this occurs after the form has been resized, so there will be a large amount of flickering. The message that is sent to you is WM_GETMINMAXINFO. Use the code above to start the subclassing, and add the following code to the module.
Public Declare Sub CopyMemory Lib "kernel32" Alias
"RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
'// extra type declarations
Type POINTAPI
x As Long
y As Long
End Type
Type MINMAXINFO
ptReserved As POINTAPI
ptMaxSize As POINTAPI
ptMaxPosition As POINTAPI
ptMinTrackSize As POINTAPI
ptMaxTrackSize As POINTAPI
End Type
'// the message we will subclass
Public Const WM_GETMINMAXINFO As Long = &H24
'// use this WindowProc procedure
Public Function WindowProc(ByVal hWnd As Long, ByVal iMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
'// ----WARNING----
'// do not attempt to debug this procedure!!
'// ----WARNING----
'// this is our implementation of the message handling routine
'// determine which message was recieved
Select Case iMsg
Case WM_GETMINMAXINFO
'// dimention a variable to hold the structure
passed from Windows in lParam
Dim udtMINMAXINFO As MINMAXINFO
Dim nWidthPixels As Long, nHeightPixels As Long
nWidthPixels = Screen.Width *
Screen.TwipsPerPixelX
nHeightPixels = Screen.Height *
Screen.TwipsPerPixelY
'// copy the struct to our UDT variable
CopyMemory udtMINMAXINFO, ByVal lParam, 40&
With udtMINMAXINFO
'// set the width of
the form when it's maximized
.ptMaxSize.x =
nWidthPixels - (nWidthPixels 4)
'// set the height of
the form when it's maximized
.ptMaxSize.y = nHeightPixels
- (nHeightPixels 4)
'// set the Left of the form
when it's maximized
.ptMaxPosition.x =
nWidthPixels * 8
'// set the Top of the form
when it's maximized
.ptMaxPosition.y =
nHeightPixels * 8
'// set the max width that
the user can drag the form
.ptMaxTrackSize.x =
.ptMaxSize.x
'// set the max height that
the user can drag the form
.ptMaxTrackSize.y =
.ptMaxSize.y
'// set the min width that
the user can drag the form
.ptMinTrackSize.x =
nWidthPixels * 4
'// set the min width that
the user can drag the form
.ptMinTrackSize.y =
nHeightPixels * 4
End With
'// copy our modified struct back to the Windows
struct
CopyMemory ByVal lParam, udtMINMAXINFO, 40&
'// return zero indicating that we have acted on
this message
WindowProc = False
'// exit the function without letting VB get it's
grubby little hands on the message
Exit Function
End Select
'// pass all messages on to VB and then return the value to windows
WindowProc = CallWindowProc(ProcOld, hWnd, iMsg, wParam, lParam)
End Function
Related articles
Related discussion
-
VB6 Runtime error 381 subsript out of range Error
by Uncle (2 replies)
-
passing and reading parameters from using Shell
by jigartoliya (0 replies)
-
Convert C++ code to VB6
by mawcot (4 replies)
-
listbox scrollbar
by Dennijr (10 replies)
-
Can you describe Above simple VB6 code?
by pramodmca09 (0 replies)
Related podcasts
-
Christian Beauclair
14 mai 2008 (�mission #0074) ::.Christian Beauclair: Stratégies de migration VB6 vers .NET Nous discutons avec Christian Beauclair des stratégies de migration VB6 vers .NET. Entre autres, nous discutons comment utiliser le "VB 6 Code Advisor" et le "Interop Forms Toolkit" pour ajouter la puiss...
Pretty hacky functions... Try these:
GetLowWord = Word Mod 65536
End Function
Public Function GetHighWord(Word As Long)
GetHighWord = (Word \ 65536) Mod 65536
End Function
Those will chop off the 1st/2nd and 3rd/4th bytes respectively using pure math. Much faster and more universal.
Hummmm..... This code looks surprisingly like the code in the GETMINMAXINFO example at http://www.mvps.org/vbvision/ Right down to the exact same comments! Coincidence? You be the judge!
http://www.vbaccelerator.com/home/VB/Code/Libraries/Subclassing/SSubTimer/article.asp
the link Download the SSubTmr project code (no DLL) (9kb) not working.
This thread is for discussions of Subclassing.