VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Make a Sizeable Control

by D Lee (1 Submission)
Category: Windows API Call/Explanation
Compatability: Visual Basic 5.0
Difficulty: Advanced
Date Added: Wed 3rd February 2021
Rating: (3 Votes)

This code allows you to make a non-sizeable control in VB 6.0, to a sizeable control.

Inputs
X as Control Y as Form
Assumes
Thanks to Randy Birch, for most of the code, I encapsulated it as a class, hence: 'to use the class, create a Form1 and Textbox1 Dim clsA as clsUser Set clsA = New clsUser clsA.SetControlResize(Textbox1, Me) Set clsA = Nothing
API Declarations
Option Explicit
'windows constants
Private Const SWP_DRAWFRAME As Long = &H20
Private Const SWP_NOMOVE As Long = &H2
Private Const SWP_NOSIZE As Long = &H1
Private Const SWP_NOZORDER As Long = &H4
Private Const SWP_FLAGS As Long = SWP_NOZORDER Or SWP_NOSIZE Or _
SWP_NOMOVE Or SWP_DRAWFRAME
Private Const GWL_STYLE As Long = (-16)
Private Const WS_THICKFRAME As Long = &H40000
Private Declare Function GetWindowLong Lib "user32" _
Alias "GetWindowLongA" _
(ByVal hwnd As Long, _
ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" _
Alias "SetWindowLongA" _
(ByVal hwnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long
Private Declare Function SetWindowPos Lib "user32" _
(ByVal hwnd As Long, _
ByVal hWndInsertAfter As Long, _
ByVal X As Long, _
ByVal Y As Long, _
ByVal cx As Long, _
ByVal cy As Long, _
ByVal wFlags As Long) As Long

Rate Make a Sizeable Control

Public Sub SetControlResize(X As Control, Y As Form)
  Dim style As Long
 
 'get the current style attributes for the control
  style = GetWindowLong(X.hwnd, GWL_STYLE)
 
 'modify the style to show the sizing frame
  style = style Or WS_THICKFRAME
 
 'set the control to the chosen style
 If style Then
  Call SetWindowLong(X.hwnd, GWL_STYLE, style)
  Call SetWindowPos(X.hwnd, Y.hwnd, 0, 0, 0, 0, SWP_FLAGS)
 End If
End Sub

Download this snippet    Add to My Saved Code

Make a Sizeable Control Comments

No comments have been posted about Make a Sizeable Control. Why not be the first to post a comment about Make a Sizeable Control.

Post your comment

Subject:
Message:
0/1000 characters