tony.reynolds
Board Regular
- Joined
- Jul 8, 2010
- Messages
- 97
Im Trying to create a userform that behaves similar to normal windows (i.e. can be resized to whatever size the user wants.
I have got a fair way with the minimize and maximimize buttons .. now i need to have a grab handle in the corner or make the borders activate resize handles
below is the code so far which works really well so far.
Can soemone help me with code for resizing?
I have got a fair way with the minimize and maximimize buttons .. now i need to have a grab handle in the corner or make the borders activate resize handles
below is the code so far which works really well so far.
Can soemone help me with code for resizing?
Code:
Option Compare Text
Option Explicit
Private Declare Function SendMessage Lib "USER32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Long) As Long
Private Declare Function ExtractIcon Lib "shell32.dll" Alias "ExtractIconA" (ByVal hInst As Long, ByVal lpszExeFileName As String, ByVal nIconIndex As Long) As Long
Private Declare Function GetActiveWindow32 Lib "USER32" Alias "GetActiveWindow" () As Integer
Private Declare Function GetWindowLong Lib "USER32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function ShowWindow Lib "USER32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Declare Function FindWindow Lib "USER32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) 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 SetFocus Lib "USER32" (ByVal hwnd As Long) As Long
Private Const GWL_STYLE As Long = -16
Private Const GWL_EXSTYLE As Long = -20
Private Const WS_CAPTION As Long = &HC00000
Private Const WS_MINIMIZEBOX As Long = &H20000
Private Const WS_MAXIMIZEBOX As Long = &H10000
Private Const WS_POPUP As Long = &H80000000
Private Const WS_VISIBLE As Long = &H10000000
Private Const WS_EX_DLGMODALFRAME As Long = &H1
Private Const WS_EX_APPWINDOW As Long = &H40000
Private Const SW_SHOW As Long = 5
Private Const WM_SETICON = &H80
Private Sub CommandButtonCloseMe_Click()
Workbooks("XYZ.xlsm").Save
Unload Me
End Sub
Private Sub UserForm_Activate()
Dim lngHwnd As Long
Dim lngCurrentStyle As Long
Dim lngNewStyle As Long
Dim lngXLHwnd As Long
Dim lngIcon As Long
Dim strIconPath As String
Application.Visible = True
UserFormPengarMainWindow.Top = Range("OptionsDataWindowTop").Value
UserFormPengarMainWindow.Left = Range("OptionsDataWindowLeft").Value
lngHwnd = FindWindow("ThunderDFrame", Me.Caption)
'''''''''Set the Windows style so that the userform has a minimise and maximise button
lngCurrentStyle = GetWindowLong(lngHwnd, GWL_STYLE)
lngNewStyle = lngCurrentStyle Or WS_MINIMIZEBOX Or WS_MAXIMIZEBOX
lngNewStyle = lngNewStyle And Not WS_VISIBLE And Not WS_POPUP
SetWindowLong lngHwnd, GWL_STYLE, lngNewStyle
''''''''''Set the extended style to provide a taskbar icon
lngCurrentStyle = GetWindowLong(lngHwnd, GWL_EXSTYLE)
lngNewStyle = lngCurrentStyle Or WS_EX_APPWINDOW
SetWindowLong lngHwnd, GWL_EXSTYLE, lngNewStyle
ShowWindow lngHwnd, SW_SHOW
''''''''''Add a Icon to the Taskbar and Window Frame
strIconPath = ActiveWorkbook.Path & "\PengarIcon.ico"
lngXLHwnd = FindWindow("XYZ", Application.Caption)
lngIcon = ExtractIcon(0, strIconPath, 0)
SendMessage lngXLHwnd, WM_SETICON, False, lngIcon
SendMessage GetActiveWindow32(), &H80, 1, lngIcon '< 1 = big Icon
SendMessage GetActiveWindow32(), &H80, 0, lngIcon '< 0 = small Icon
End Sub