#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default User Form

can anyone tell me how to make the user form in excel VBA more similar
to VB version?
As in: VB's user form has maximize and minimize button beside
close[X],However, excel user form hasn't, vb can add in pulldown menu
easily, but excel user form can't.

Another question is: How can i view the full picture by using
Loadpicture function if the picture size is greater than the
picturebox's size?

thank you.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 130
Default User Form

To add the min or max button to the userform, put this code in a standard
code module:

'///////////////////////////////////////'
'/ /'
'/ API calls to add the Minimize and /'
'/ Restore buttons to the Title Bar /'
'/ of a VBA UserForm. /'
'/ /'
'///////////////////////////////////////'
'
'Written: Jan. 30, 2007
'Author: Leith Ross


'Constants for ShowWindow (nCmdShow)
Const SW_HIDDEN As Long = 0
Const SW_NORMAL As Long = 1
Const SW_MINIMIZED As Long = 2
Const SW_MAXIMIZED As Long = 3
Const SW_NOTACTIVE As Long = 4
Const SW_UNHIDDEN As Long = 5
Const SW_MINWITHFOCUS As Long = 6
Const SW_MINNOTACTIVE As Long = 7
Const SW_RESTORE As Long = 9

'Constants for GetWindow
Const GW_HWNDFIRST As Long = &H0
Const GW_HWNDLAST As Long = &H1
Const GW_HWNDNEXT As Long = &H2
Const GW_HWNDPREV As Long = &H3
Const GW_OWNER As Long = &H4
Const GW_CHILD As Long = &H5

'Window Style constants
Const WS_DISABLE As Long = 0
Const WS_MAXIMIZEBOX As Long = &H10000
Const WS_MINIMIZEBOX As Long = &H20000
Const WS_THICKFRAME As Long = &H40000 'Style to add a sizable Frame
Const WS_SYSMENU As Long = &H80000
Const WS_ENABLE As Long = &HFFFFFFFF

'Get Window Long constants
Const GWL_HINSTANCE As Long = (-6)
Const GWL_HWNDPARENT As Long = (-8)
Const GWL_ID As Long = (-12)
Const GWL_STYLE As Long = (-16)
Const GWL_EXSTYLE As Long = (-20)

Private Declare Function GetWindowLong _
Lib "user32.dll" _
Alias "GetWindowLongA" _
(ByVal hWnd As Long, ByVal nIndex As Long) As
Long

Private Declare Function SetWindowLong _
Lib "user32.dll" _
Alias "SetWindowLongA" _
(ByVal hWnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long

'Function to Change how Window is Displayed
Private Declare Function ShowWindow _
Lib "user32.dll" _
(ByVal hWnd As Long, _
ByVal nCmdShow As Long) As Long

'Returns the Window Handle of the Active Window
Public Declare Function GetActiveWindow _
Lib "user32.dll" () As Long

'Redraw the Icons on the Window's Title Bar
Private Declare Function DrawMenuBar _
Lib "user32.dll" _
(ByVal hWnd As Long) As Long

Public Sub MinimizeWindow(Optional ByVal Window_Handle As Long, _
Optional ByVal With_Focus As Boolean)

Dim RetVal

If With_Focus = True Then
RetVal = ShowWindow(Window_Handle, SW_MINWITHFOCUS)
Else
RetVal = ShowWindow(Window_Handle, SW_MINNOTACTIVE)
End If

End Sub

Public Sub RestoreWindow(Optional ByVal Window_Handle As Long)

Dim RetVal

RetVal = ShowWindow(Window_Handle, SW_NORMAL)

End Sub


Public Sub AddMinBox(Optional Window_Handle As Long)

Dim hWnd As Long
Dim BitMask As Long
Dim WindowStyle As Long

If Window_Handle = 0 Then
hWnd = GetActiveWindow()
Else
hWnd = Window_Handle
End If

WindowStyle = GetWindowLong(hWnd, GWL_STYLE)
BitMask = WindowStyle Or WS_MINIMIZEBOX

Call SetWindowLong(hWnd, GWL_STYLE, BitMask)
Call DrawMenuBar(hWnd)

End Sub

Public Sub AddMaxBox(Optional Window_Handle As Long)

Dim hWnd As Long
Dim BitMask As Long
Dim WindowStyle As Long

If Window_Handle = 0 Then
hWnd = GetActiveWindow()
Else
hWnd = Window_Handle
End If

WindowStyle = GetWindowLong(hWnd, GWL_STYLE)
BitMask = WindowStyle Or WS_MAXIMIZEBOX

Call SetWindowLong(hWnd, GWL_STYLE, BitMask)
Call DrawMenuBar(hWnd)

End Sub

You will also need to add these lines to the Userform code:

Private Sub UserForm_Activate()
' Add min and max buttons to userform
Call AddMinBox
Call AddMaxBox
End Sub

Credit for this code goes to Leigh Ross, whose code I copied from this
forum.

As for a pull down menu, I'm not sure what you mean. You can add a combobox
control to the form, and that can be configured as a drop-down control.

Regarding the picture, set the image control's Autosize property to TRUE
before loading the pictu

Me.Controls(yourControlHere).Autosize = True

Hope this helps,
Matthew Pfluger

" wrote:

can anyone tell me how to make the user form in excel VBA more similar
to VB version?
As in: VB's user form has maximize and minimize button beside
close[X],However, excel user form hasn't, vb can add in pulldown menu
easily, but excel user form can't.

Another question is: How can i view the full picture by using
Loadpicture function if the picture size is greater than the
picturebox's size?

thank you.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default User Form

On 1月20日, 上午9时30分, Matthew Pfluger
wrote:
To add the min or max button to the userform, put this code in a standard
code module:

'///////////////////////////////////////'
'/ /'
'/ API calls to add the Minimize and /'
'/ Restore buttons to the Title Bar /'
'/ of a VBA UserForm. /'
'/ /'
'///////////////////////////////////////'
'
'Written: Jan. 30, 2007
'Author: Leith Ross

'Constants for ShowWindow (nCmdShow)
Const SW_HIDDEN As Long = 0
Const SW_NORMAL As Long = 1
Const SW_MINIMIZED As Long = 2
Const SW_MAXIMIZED As Long = 3
Const SW_NOTACTIVE As Long = 4
Const SW_UNHIDDEN As Long = 5
Const SW_MINWITHFOCUS As Long = 6
Const SW_MINNOTACTIVE As Long = 7
Const SW_RESTORE As Long = 9

'Constants for GetWindow
Const GW_HWNDFIRST As Long = &H0
Const GW_HWNDLAST As Long = &H1
Const GW_HWNDNEXT As Long = &H2
Const GW_HWNDPREV As Long = &H3
Const GW_OWNER As Long = &H4
Const GW_CHILD As Long = &H5

'Window Style constants
Const WS_DISABLE As Long = 0
Const WS_MAXIMIZEBOX As Long = &H10000
Const WS_MINIMIZEBOX As Long = &H20000
Const WS_THICKFRAME As Long = &H40000 'Style to add a sizable Frame
Const WS_SYSMENU As Long = &H80000
Const WS_ENABLE As Long = &HFFFFFFFF

'Get Window Long constants
Const GWL_HINSTANCE As Long = (-6)
Const GWL_HWNDPARENT As Long = (-8)
Const GWL_ID As Long = (-12)
Const GWL_STYLE As Long = (-16)
Const GWL_EXSTYLE As Long = (-20)

Private Declare Function GetWindowLong _
Lib "user32.dll" _
Alias "GetWindowLongA" _
(ByVal hWnd As Long, ByVal nIndex As Long) As
Long

Private Declare Function SetWindowLong _
Lib "user32.dll" _
Alias "SetWindowLongA" _
(ByVal hWnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long

'Function to Change how Window is Displayed
Private Declare Function ShowWindow _
Lib "user32.dll" _
(ByVal hWnd As Long, _
ByVal nCmdShow As Long) As Long

'Returns the Window Handle of the Active Window
Public Declare Function GetActiveWindow _
Lib "user32.dll" () As Long

'Redraw the Icons on the Window's Title Bar
Private Declare Function DrawMenuBar _
Lib "user32.dll" _
(ByVal hWnd As Long) As Long

Public Sub MinimizeWindow(Optional ByVal Window_Handle As Long, _
Optional ByVal With_Focus As Boolean)

Dim RetVal

If With_Focus = True Then
RetVal = ShowWindow(Window_Handle, SW_MINWITHFOCUS)
Else
RetVal = ShowWindow(Window_Handle, SW_MINNOTACTIVE)
End If

End Sub

Public Sub RestoreWindow(Optional ByVal Window_Handle As Long)

Dim RetVal

RetVal = ShowWindow(Window_Handle, SW_NORMAL)

End Sub

Public Sub AddMinBox(Optional Window_Handle As Long)

Dim hWnd As Long
Dim BitMask As Long
Dim WindowStyle As Long

If Window_Handle = 0 Then
hWnd = GetActiveWindow()
Else
hWnd = Window_Handle
End If

WindowStyle = GetWindowLong(hWnd, GWL_STYLE)
BitMask = WindowStyle Or WS_MINIMIZEBOX

Call SetWindowLong(hWnd, GWL_STYLE, BitMask)
Call DrawMenuBar(hWnd)

End Sub

Public Sub AddMaxBox(Optional Window_Handle As Long)

Dim hWnd As Long
Dim BitMask As Long
Dim WindowStyle As Long

If Window_Handle = 0 Then
hWnd = GetActiveWindow()
Else
hWnd = Window_Handle
End If

WindowStyle = GetWindowLong(hWnd, GWL_STYLE)
BitMask = WindowStyle Or WS_MAXIMIZEBOX

Call SetWindowLong(hWnd, GWL_STYLE, BitMask)
Call DrawMenuBar(hWnd)

End Sub

You will also need to add these lines to the Userform code:

Private Sub UserForm_Activate()
' Add min and max buttons to userform
Call AddMinBox
Call AddMaxBox
End Sub

Credit for this code goes to Leigh Ross, whose code I copied from this
forum.

As for a pull down menu, I'm not sure what you mean. You can add a combobox
control to the form, and that can be configured as a drop-down control.

Regarding the picture, set the image control's Autosize property to TRUE
before loading the pictu

Me.Controls(yourControlHere).Autosize = True

Hope this helps,
Matthew Pfluger



" wrote:
can anyone tell me how to make the user form in excel VBA more similar
to VB version?
As in: VB's user form has maximize and minimize button beside
close[X],However, excel user form hasn't, vb can add in pulldown menu
easily, but excel user form can't.


Another question is: How can i view the full picture by using
Loadpicture function if the picture size is greater than the
picturebox's size?


thank you.- 隐藏被引用文字 -


- 显示引用的文字 -


thank you matthew.
regarding the picturebox control, if i set Autosize=True, the picture
will be shown completely. However, what i want is a smaller picture
which is shown fully in the small picturebox. If Autosize=true, the
picture still the large picture regardless the size of picturebox.
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 133
Default User Form

On Jan 20, 1:41 am, wrote:
On 1月20日, 上午9时30分, Matthew Pfluger



wrote:
To add the min or max button to the userform, put this code in a standard
code module:


'///////////////////////////////////////'
'/ /'
'/ API calls to add the Minimize and /'
'/ Restore buttons to the Title Bar /'
'/ of a VBA UserForm. /'
'/ /'
'///////////////////////////////////////'
'
'Written: Jan. 30, 2007
'Author: Leith Ross


'Constants for ShowWindow (nCmdShow)
Const SW_HIDDEN As Long = 0
Const SW_NORMAL As Long = 1
Const SW_MINIMIZED As Long = 2
Const SW_MAXIMIZED As Long = 3
Const SW_NOTACTIVE As Long = 4
Const SW_UNHIDDEN As Long = 5
Const SW_MINWITHFOCUS As Long = 6
Const SW_MINNOTACTIVE As Long = 7
Const SW_RESTORE As Long = 9


'Constants for GetWindow
Const GW_HWNDFIRST As Long = &H0
Const GW_HWNDLAST As Long = &H1
Const GW_HWNDNEXT As Long = &H2
Const GW_HWNDPREV As Long = &H3
Const GW_OWNER As Long = &H4
Const GW_CHILD As Long = &H5


'Window Style constants
Const WS_DISABLE As Long = 0
Const WS_MAXIMIZEBOX As Long = &H10000
Const WS_MINIMIZEBOX As Long = &H20000
Const WS_THICKFRAME As Long = &H40000 'Style to add a sizable Frame
Const WS_SYSMENU As Long = &H80000
Const WS_ENABLE As Long = &HFFFFFFFF


'Get Window Long constants
Const GWL_HINSTANCE As Long = (-6)
Const GWL_HWNDPARENT As Long = (-8)
Const GWL_ID As Long = (-12)
Const GWL_STYLE As Long = (-16)
Const GWL_EXSTYLE As Long = (-20)


Private Declare Function GetWindowLong _
Lib "user32.dll" _
Alias "GetWindowLongA" _
(ByVal hWnd As Long, ByVal nIndex As Long) As
Long


Private Declare Function SetWindowLong _
Lib "user32.dll" _
Alias "SetWindowLongA" _
(ByVal hWnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long


'Function to Change how Window is Displayed
Private Declare Function ShowWindow _
Lib "user32.dll" _
(ByVal hWnd As Long, _
ByVal nCmdShow As Long) As Long


'Returns the Window Handle of the Active Window
Public Declare Function GetActiveWindow _
Lib "user32.dll" () As Long


'Redraw the Icons on the Window's Title Bar
Private Declare Function DrawMenuBar _
Lib "user32.dll" _
(ByVal hWnd As Long) As Long


Public Sub MinimizeWindow(Optional ByVal Window_Handle As Long, _
Optional ByVal With_Focus As Boolean)


Dim RetVal


If With_Focus = True Then
RetVal = ShowWindow(Window_Handle, SW_MINWITHFOCUS)
Else
RetVal = ShowWindow(Window_Handle, SW_MINNOTACTIVE)
End If


End Sub


Public Sub RestoreWindow(Optional ByVal Window_Handle As Long)


Dim RetVal


RetVal = ShowWindow(Window_Handle, SW_NORMAL)


End Sub


Public Sub AddMinBox(Optional Window_Handle As Long)


Dim hWnd As Long
Dim BitMask As Long
Dim WindowStyle As Long


If Window_Handle = 0 Then
hWnd = GetActiveWindow()
Else
hWnd = Window_Handle
End If


WindowStyle = GetWindowLong(hWnd, GWL_STYLE)
BitMask = WindowStyle Or WS_MINIMIZEBOX


Call SetWindowLong(hWnd, GWL_STYLE, BitMask)
Call DrawMenuBar(hWnd)


End Sub


Public Sub AddMaxBox(Optional Window_Handle As Long)


Dim hWnd As Long
Dim BitMask As Long
Dim WindowStyle As Long


If Window_Handle = 0 Then
hWnd = GetActiveWindow()
Else
hWnd = Window_Handle
End If


WindowStyle = GetWindowLong(hWnd, GWL_STYLE)
BitMask = WindowStyle Or WS_MAXIMIZEBOX


Call SetWindowLong(hWnd, GWL_STYLE, BitMask)
Call DrawMenuBar(hWnd)


End Sub


You will also need to add these lines to the Userform code:


Private Sub UserForm_Activate()
' Add min and max buttons to userform
Call AddMinBox
Call AddMaxBox
End Sub


Credit for this code goes to Leigh Ross, whose code I copied from this
forum.


As for a pull down menu, I'm not sure what you mean. You can add a combobox
control to the form, and that can be configured as a drop-down control.


Regarding the picture, set the image control's Autosize property to TRUE
before loading the pictu


Me.Controls(yourControlHere).Autosize = True


Hope this helps,
Matthew Pfluger


" wrote:
can anyone tell me how to make the user form in excel VBA more similar
to VB version?
As in: VB's user form has maximize and minimize button beside
close[X],However, excel user form hasn't, vb can add in pulldown menu
easily, but excel user form can't.


Another question is: How can i view the full picture by using
Loadpicture function if the picture size is greater than the
picturebox's size?


thank you.- 隐藏被引用文字 -


- 显示引用的文字 -


thank you matthew.
regarding the picturebox control, if i set Autosize=True, the picture
will be shown completely. However, what i want is a smaller picture
which is shown fully in the small picturebox. If Autosize=true, the
picture still the large picture regardless the size of picturebox.


Set Autosize = False. It's PictureSizeMode = Stretch or Zoom that
fits the picture into the size of the box you defined. Pick the one
you want.

SteveM
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default User Form

On 1月20日, 下午3时21分, SteveM wrote:
On Jan 20, 1:41 am, wrote:





On 1月20日, 上午9时30分, Matthew Pfluger


wrote:
To add the min or max button to the userform, put this code in a standard
code module:


'///////////////////////////////////////'
'/ /'
'/ API calls to add the Minimize and /'
'/ Restore buttons to the Title Bar /'
'/ of a VBA UserForm. /'
'/ /'
'///////////////////////////////////////'
'
'Written: Jan. 30, 2007
'Author: Leith Ross


'Constants for ShowWindow (nCmdShow)
Const SW_HIDDEN As Long = 0
Const SW_NORMAL As Long = 1
Const SW_MINIMIZED As Long = 2
Const SW_MAXIMIZED As Long = 3
Const SW_NOTACTIVE As Long = 4
Const SW_UNHIDDEN As Long = 5
Const SW_MINWITHFOCUS As Long = 6
Const SW_MINNOTACTIVE As Long = 7
Const SW_RESTORE As Long = 9


'Constants for GetWindow
Const GW_HWNDFIRST As Long = &H0
Const GW_HWNDLAST As Long = &H1
Const GW_HWNDNEXT As Long = &H2
Const GW_HWNDPREV As Long = &H3
Const GW_OWNER As Long = &H4
Const GW_CHILD As Long = &H5


'Window Style constants
Const WS_DISABLE As Long = 0
Const WS_MAXIMIZEBOX As Long = &H10000
Const WS_MINIMIZEBOX As Long = &H20000
Const WS_THICKFRAME As Long = &H40000 'Style to add a sizable Frame
Const WS_SYSMENU As Long = &H80000
Const WS_ENABLE As Long = &HFFFFFFFF


'Get Window Long constants
Const GWL_HINSTANCE As Long = (-6)
Const GWL_HWNDPARENT As Long = (-8)
Const GWL_ID As Long = (-12)
Const GWL_STYLE As Long = (-16)
Const GWL_EXSTYLE As Long = (-20)


Private Declare Function GetWindowLong _
Lib "user32.dll" _
Alias "GetWindowLongA" _
(ByVal hWnd As Long, ByVal nIndex As Long) As
Long


Private Declare Function SetWindowLong _
Lib "user32.dll" _
Alias "SetWindowLongA" _
(ByVal hWnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long


'Function to Change how Window is Displayed
Private Declare Function ShowWindow _
Lib "user32.dll" _
(ByVal hWnd As Long, _
ByVal nCmdShow As Long) As Long


'Returns the Window Handle of the Active Window
Public Declare Function GetActiveWindow _
Lib "user32.dll" () As Long


'Redraw the Icons on the Window's Title Bar
Private Declare Function DrawMenuBar _
Lib "user32.dll" _
(ByVal hWnd As Long) As Long


Public Sub MinimizeWindow(Optional ByVal Window_Handle As Long, _
Optional ByVal With_Focus As Boolean)


Dim RetVal


If With_Focus = True Then
RetVal = ShowWindow(Window_Handle, SW_MINWITHFOCUS)
Else
RetVal = ShowWindow(Window_Handle, SW_MINNOTACTIVE)
End If


End Sub


Public Sub RestoreWindow(Optional ByVal Window_Handle As Long)


Dim RetVal


RetVal = ShowWindow(Window_Handle, SW_NORMAL)


End Sub


Public Sub AddMinBox(Optional Window_Handle As Long)


Dim hWnd As Long
Dim BitMask As Long
Dim WindowStyle As Long


If Window_Handle = 0 Then
hWnd = GetActiveWindow()
Else
hWnd = Window_Handle
End If


WindowStyle = GetWindowLong(hWnd, GWL_STYLE)
BitMask = WindowStyle Or WS_MINIMIZEBOX


Call SetWindowLong(hWnd, GWL_STYLE, BitMask)
Call DrawMenuBar(hWnd)


End Sub


Public Sub AddMaxBox(Optional Window_Handle As Long)


Dim hWnd As Long
Dim BitMask As Long
Dim WindowStyle As Long


If Window_Handle = 0 Then
hWnd = GetActiveWindow()
Else
hWnd = Window_Handle
End If


WindowStyle = GetWindowLong(hWnd, GWL_STYLE)
BitMask = WindowStyle Or WS_MAXIMIZEBOX


Call SetWindowLong(hWnd, GWL_STYLE, BitMask)
Call DrawMenuBar(hWnd)


End Sub


You will also need to add these lines to the Userform code:


Private Sub UserForm_Activate()
' Add min and max buttons to userform
Call AddMinBox
Call AddMaxBox
End Sub


Credit for this code goes to Leigh Ross, whose code I copied from this
forum.


As for a pull down menu, I'm not sure what you mean. You can add a combobox
control to the form, and that can be configured as a drop-down control..


Regarding the picture, set the image control's Autosize property to TRUE
before loading the pictu


Me.Controls(yourControlHere).Autosize = True


Hope this helps,
Matthew Pfluger


" wrote:
can anyone tell me how to make the user form in excel VBA more similar
to VB version?
As in: VB's user form has maximize and minimize button beside
close[X],However, excel user form hasn't, vb can add in pulldown menu
easily, but excel user form can't.


Another question is: How can i view the full picture by using
Loadpicture function if the picture size is greater than the
picturebox's size?


thank you.- 隐藏被引用文字 -


- 显示引用的文字 -


thank you matthew.
regarding the picturebox control, if i set Autosize=True, the picture
will be shown completely. However, what i want is a smaller picture
which is shown fully in the small picturebox. If Autosize=true, the
picture still the large picture regardless the size of picturebox.


Set Autosize = False. It's PictureSizeMode = Stretch or Zoom that
fits the picture into the size of the box you defined. Pick the one
you want.

SteveM- 隐藏被引用文字 -

- 显示引用的文字 -


sorry, i tried but still the same.


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 247
Default User Form

i had the same problem and the zoom/stretch worked for me. i used stretch
and then size the picture box

" wrote:

On 1鏈20鏃, 涓嬪崍3鏃21鍒, SteveM wrote:
On Jan 20, 1:41 am, wrote:





On 1鏈20鏃, 涓婂崍9鏃30鍒, Matthew Pfluger


wrote:
To add the min or max button to the userform, put this code in a standard
code module:


'///////////////////////////////////////'
'/ /'
'/ API calls to add the Minimize and /'
'/ Restore buttons to the Title Bar /'
'/ of a VBA UserForm. /'
'/ /'
'///////////////////////////////////////'
'
'Written: Jan. 30, 2007
'Author: Leith Ross


'Constants for ShowWindow (nCmdShow)
Const SW_HIDDEN As Long = 0
Const SW_NORMAL As Long = 1
Const SW_MINIMIZED As Long = 2
Const SW_MAXIMIZED As Long = 3
Const SW_NOTACTIVE As Long = 4
Const SW_UNHIDDEN As Long = 5
Const SW_MINWITHFOCUS As Long = 6
Const SW_MINNOTACTIVE As Long = 7
Const SW_RESTORE As Long = 9


'Constants for GetWindow
Const GW_HWNDFIRST As Long = &H0
Const GW_HWNDLAST As Long = &H1
Const GW_HWNDNEXT As Long = &H2
Const GW_HWNDPREV As Long = &H3
Const GW_OWNER As Long = &H4
Const GW_CHILD As Long = &H5


'Window Style constants
Const WS_DISABLE As Long = 0
Const WS_MAXIMIZEBOX As Long = &H10000
Const WS_MINIMIZEBOX As Long = &H20000
Const WS_THICKFRAME As Long = &H40000 'Style to add a sizable Frame
Const WS_SYSMENU As Long = &H80000
Const WS_ENABLE As Long = &HFFFFFFFF


'Get Window Long constants
Const GWL_HINSTANCE As Long = (-6)
Const GWL_HWNDPARENT As Long = (-8)
Const GWL_ID As Long = (-12)
Const GWL_STYLE As Long = (-16)
Const GWL_EXSTYLE As Long = (-20)


Private Declare Function GetWindowLong _
Lib "user32.dll" _
Alias "GetWindowLongA" _
(ByVal hWnd As Long, ByVal nIndex As Long) As
Long


Private Declare Function SetWindowLong _
Lib "user32.dll" _
Alias "SetWindowLongA" _
(ByVal hWnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long


'Function to Change how Window is Displayed
Private Declare Function ShowWindow _
Lib "user32.dll" _
(ByVal hWnd As Long, _
ByVal nCmdShow As Long) As Long


'Returns the Window Handle of the Active Window
Public Declare Function GetActiveWindow _
Lib "user32.dll" () As Long


'Redraw the Icons on the Window's Title Bar
Private Declare Function DrawMenuBar _
Lib "user32.dll" _
(ByVal hWnd As Long) As Long


Public Sub MinimizeWindow(Optional ByVal Window_Handle As Long, _
Optional ByVal With_Focus As Boolean)


Dim RetVal


If With_Focus = True Then
RetVal = ShowWindow(Window_Handle, SW_MINWITHFOCUS)
Else
RetVal = ShowWindow(Window_Handle, SW_MINNOTACTIVE)
End If


End Sub


Public Sub RestoreWindow(Optional ByVal Window_Handle As Long)


Dim RetVal


RetVal = ShowWindow(Window_Handle, SW_NORMAL)


End Sub


Public Sub AddMinBox(Optional Window_Handle As Long)


Dim hWnd As Long
Dim BitMask As Long
Dim WindowStyle As Long


If Window_Handle = 0 Then
hWnd = GetActiveWindow()
Else
hWnd = Window_Handle
End If


WindowStyle = GetWindowLong(hWnd, GWL_STYLE)
BitMask = WindowStyle Or WS_MINIMIZEBOX


Call SetWindowLong(hWnd, GWL_STYLE, BitMask)
Call DrawMenuBar(hWnd)


End Sub


Public Sub AddMaxBox(Optional Window_Handle As Long)


Dim hWnd As Long
Dim BitMask As Long
Dim WindowStyle As Long


If Window_Handle = 0 Then
hWnd = GetActiveWindow()
Else
hWnd = Window_Handle
End If


WindowStyle = GetWindowLong(hWnd, GWL_STYLE)
BitMask = WindowStyle Or WS_MAXIMIZEBOX


Call SetWindowLong(hWnd, GWL_STYLE, BitMask)
Call DrawMenuBar(hWnd)


End Sub


You will also need to add these lines to the Userform code:


Private Sub UserForm_Activate()
' Add min and max buttons to userform
Call AddMinBox
Call AddMaxBox
End Sub


Credit for this code goes to Leigh Ross, whose code I copied from this
forum.


As for a pull down menu, I'm not sure what you mean. You can add a combobox
control to the form, and that can be configured as a drop-down control..


Regarding the picture, set the image control's Autosize property to TRUE
before loading the pictu


Me.Controls(yourControlHere).Autosize = True


Hope this helps,
Matthew Pfluger


" wrote:
can anyone tell me how to make the user form in excel VBA more similar
to VB version?
As in: VB's user form has maximize and minimize button beside
close[X],However, excel user form hasn't, vb can add in pulldown menu
easily, but excel user form can't.


Another question is: How can i view the full picture by using
Loadpicture function if the picture size is greater than the
picturebox's size?


thank you.- 闅愯棌琚紩鐢ㄦ枃* -


- 鏄剧ず寮曠敤鐨勬枃* -


thank you matthew.
regarding the picturebox control, if i set Autosize=True, the picture
will be shown completely. However, what i want is a smaller picture
which is shown fully in the small picturebox. If Autosize=true, the
picture still the large picture regardless the size of picturebox.


Set Autosize = False. It's PictureSizeMode = Stretch or Zoom that
fits the picture into the size of the box you defined. Pick the one
you want.

SteveM- 闅愯棌琚紩鐢ㄦ枃* -

- 鏄剧ず寮曠敤鐨勬枃* -


sorry, i tried but still the same.

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 247
Default User Form


how do i get it to open maximized?




"Matthew Pfluger" wrote:

To add the min or max button to the userform, put this code in a standard
code module:

'///////////////////////////////////////'
'/ /'
'/ API calls to add the Minimize and /'
'/ Restore buttons to the Title Bar /'
'/ of a VBA UserForm. /'
'/ /'
'///////////////////////////////////////'
'
'Written: Jan. 30, 2007
'Author: Leith Ross


'Constants for ShowWindow (nCmdShow)
Const SW_HIDDEN As Long = 0
Const SW_NORMAL As Long = 1
Const SW_MINIMIZED As Long = 2
Const SW_MAXIMIZED As Long = 3
Const SW_NOTACTIVE As Long = 4
Const SW_UNHIDDEN As Long = 5
Const SW_MINWITHFOCUS As Long = 6
Const SW_MINNOTACTIVE As Long = 7
Const SW_RESTORE As Long = 9

'Constants for GetWindow
Const GW_HWNDFIRST As Long = &H0
Const GW_HWNDLAST As Long = &H1
Const GW_HWNDNEXT As Long = &H2
Const GW_HWNDPREV As Long = &H3
Const GW_OWNER As Long = &H4
Const GW_CHILD As Long = &H5

'Window Style constants
Const WS_DISABLE As Long = 0
Const WS_MAXIMIZEBOX As Long = &H10000
Const WS_MINIMIZEBOX As Long = &H20000
Const WS_THICKFRAME As Long = &H40000 'Style to add a sizable Frame
Const WS_SYSMENU As Long = &H80000
Const WS_ENABLE As Long = &HFFFFFFFF

'Get Window Long constants
Const GWL_HINSTANCE As Long = (-6)
Const GWL_HWNDPARENT As Long = (-8)
Const GWL_ID As Long = (-12)
Const GWL_STYLE As Long = (-16)
Const GWL_EXSTYLE As Long = (-20)

Private Declare Function GetWindowLong _
Lib "user32.dll" _
Alias "GetWindowLongA" _
(ByVal hWnd As Long, ByVal nIndex As Long) As
Long

Private Declare Function SetWindowLong _
Lib "user32.dll" _
Alias "SetWindowLongA" _
(ByVal hWnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long

'Function to Change how Window is Displayed
Private Declare Function ShowWindow _
Lib "user32.dll" _
(ByVal hWnd As Long, _
ByVal nCmdShow As Long) As Long

'Returns the Window Handle of the Active Window
Public Declare Function GetActiveWindow _
Lib "user32.dll" () As Long

'Redraw the Icons on the Window's Title Bar
Private Declare Function DrawMenuBar _
Lib "user32.dll" _
(ByVal hWnd As Long) As Long

Public Sub MinimizeWindow(Optional ByVal Window_Handle As Long, _
Optional ByVal With_Focus As Boolean)

Dim RetVal

If With_Focus = True Then
RetVal = ShowWindow(Window_Handle, SW_MINWITHFOCUS)
Else
RetVal = ShowWindow(Window_Handle, SW_MINNOTACTIVE)
End If

End Sub

Public Sub RestoreWindow(Optional ByVal Window_Handle As Long)

Dim RetVal

RetVal = ShowWindow(Window_Handle, SW_NORMAL)

End Sub


Public Sub AddMinBox(Optional Window_Handle As Long)

Dim hWnd As Long
Dim BitMask As Long
Dim WindowStyle As Long

If Window_Handle = 0 Then
hWnd = GetActiveWindow()
Else
hWnd = Window_Handle
End If

WindowStyle = GetWindowLong(hWnd, GWL_STYLE)
BitMask = WindowStyle Or WS_MINIMIZEBOX

Call SetWindowLong(hWnd, GWL_STYLE, BitMask)
Call DrawMenuBar(hWnd)

End Sub

Public Sub AddMaxBox(Optional Window_Handle As Long)

Dim hWnd As Long
Dim BitMask As Long
Dim WindowStyle As Long

If Window_Handle = 0 Then
hWnd = GetActiveWindow()
Else
hWnd = Window_Handle
End If

WindowStyle = GetWindowLong(hWnd, GWL_STYLE)
BitMask = WindowStyle Or WS_MAXIMIZEBOX

Call SetWindowLong(hWnd, GWL_STYLE, BitMask)
Call DrawMenuBar(hWnd)

End Sub

You will also need to add these lines to the Userform code:

Private Sub UserForm_Activate()
' Add min and max buttons to userform
Call AddMinBox
Call AddMaxBox
End Sub

Credit for this code goes to Leigh Ross, whose code I copied from this
forum.

As for a pull down menu, I'm not sure what you mean. You can add a combobox
control to the form, and that can be configured as a drop-down control.

Regarding the picture, set the image control's Autosize property to TRUE
before loading the pictu

Me.Controls(yourControlHere).Autosize = True

Hope this helps,
Matthew Pfluger

" wrote:

can anyone tell me how to make the user form in excel VBA more similar
to VB version?
As in: VB's user form has maximize and minimize button beside
close[X],However, excel user form hasn't, vb can add in pulldown menu
easily, but excel user form can't.

Another question is: How can i view the full picture by using
Loadpicture function if the picture size is greater than the
picturebox's size?

thank you.

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 130
Default User Form

Sorry, I'm not sure about that one. You might be able to get the screen size
resolution and change the form size that way, but I've never needed to do
that.

Matthew Pfluger

"pswanie" wrote:


how do i get it to open maximized?





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Call user form from ThisWorkbook; close file if form closed XP Excel Programming 2 July 20th 07 07:04 PM
Automatically add a textbox to a user form based on user requireme Brite Excel Programming 4 April 7th 07 11:37 PM
User form ComboBox Items: Remember user entries? [email protected] Excel Programming 0 March 29th 07 06:41 PM
How to: User Form to assign a user defined range to a macro variab TrevTrav Excel Programming 1 March 22nd 05 07:57 PM


All times are GMT +1. The time now is 08:52 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright 2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"