<quote>
I need to create a form that will resize only the verticle size of the Form
and not the width. So far I'm partial to the following code. Can someone
please elaborate the ??? . . . .
Const WM_SIZE = &H5
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
Call MyBase.WndProc(m)
Select Case m.Msg
Case WM_SIZE
???
End Select
End Sub
</quote>
Probably a safer way would be to bugger with something inside the Resize
Event, but I couldn't figure out how to do it there.
You need to know the meaning and value of the wParam and lParam items that
get passed to the WindowProc of a window when the operating system sends the
WM_SIZE message:
1. Launch the MSDN Library from your start menu.
2. In the URL combo box on MSDN's toolbar, paste this and press enter (will
wrap):
3. While you're there, lookup bit shift operators, WM_SIZE message,
WindowProc and the Message Structure.
ms-help://MS.MSDNQTR.2003FEB.1033/winui/winui/windowsuserinterface/windowing/windows/windowreference/windowmessages/wm_size.htm
I didn't get it quite right. I'm rusty on my bit-bashing, and didn't
rebuild LParam correctly inside WndProc. But here's a sample Form to get
you started.
---------------------------------------------
Public Class VerticalResize
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents btnHeight As System.Windows.Forms.Button
Friend WithEvents lblHeight As System.Windows.Forms.Label
Friend WithEvents lblWidth As System.Windows.Forms.Label
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.btnHeight = New System.Windows.Forms.Button
Me.lblHeight = New System.Windows.Forms.Label
Me.lblWidth = New System.Windows.Forms.Label
Me.SuspendLayout()
'
'btnHeight
'
Me.btnHeight.Location = New System.Drawing.Point(8, 8)
Me.btnHeight.Name = "btnHeight"
Me.btnHeight.Size = New System.Drawing.Size(80, 23)
Me.btnHeight.TabIndex = 0
Me.btnHeight.Text = "Height += 50"
'
'lblHeight
'
Me.lblHeight.Location = New System.Drawing.Point(96, 8)
Me.lblHeight.Name = "lblHeight"
Me.lblHeight.Size = New System.Drawing.Size(184, 23)
Me.lblHeight.TabIndex = 1
'
'lblWidth
'
Me.lblWidth.Location = New System.Drawing.Point(96, 39)
Me.lblWidth.Name = "lblWidth"
Me.lblWidth.Size = New System.Drawing.Size(184, 23)
Me.lblWidth.TabIndex = 2
'
'VerticalResize
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 69)
Me.Controls.Add(Me.lblWidth)
Me.Controls.Add(Me.lblHeight)
Me.Controls.Add(Me.btnHeight)
Me.Name = "VerticalResize"
Me.Text = "VerticalResize"
Me.ResumeLayout(False)
End Sub
#End Region
' represents the window message flag for a resize
Private Const WM_SIZE As Int32 = &H5
' represents your constant width
Private Const THE_WIDTH As Integer = 500
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
' Don't call MyBase.WndProc(m) out here.
' You want to only call it selectively:
Select Case m.Msg
Case WM_SIZE
' When you get a WM_SIZE message, LParam
' contains a 32-bit integer, but it's represented
' to you by .NET as an IntPtr, so we have to call
' a method to get the Int32 out of it.
Dim lParam As Int32 = m.LParam.ToInt32()
' Here's where it gets bizarre. When you get a WM_SIZE
' message, LParam has an Int32 in it, but it's really that
' the high 16 bits are the height, and the low 16 bits are
' the width. (I hate it when they do that)
Dim high As Int16 'new height
' Doing a 16 right bitshift gets the high word.
high = Convert.ToInt16(lParam >> 16)
lblHeight.Text = high.ToString()
' Now here's where I'm too rusty. We need to reset
' LParam so that the high 16 bits are the same value
' that the message sent to us, but we need to change
' the low 16 bits to represent our constant width.
' you will have to play with this expression to get it right.
m.LParam = New IntPtr(THE_WIDTH << 16 + high)
' Now that we've fiddled with the message so that LParam
' is what we want, we pass it back to let Windows handle
' it normally, but this time it has corrected values.
MyBase.WndProc(m)
Case Else
' Any other message just gets handled normally.
MyBase.WndProc(m)
End Select
End Sub
Private Sub btnHeight_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnHeight.Click
Me.Height += 50
End Sub
End Class
--
Peace & happy computing,
Mike Labosh, MCSD
"Mr. McKittrick, after very careful consideration, I have
come to the conclusion that this new system SUCKS."
-- General Barringer, "War Games"