Home |
Search |
Today's Posts |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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. |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Call user form from ThisWorkbook; close file if form closed | Excel Programming | |||
Automatically add a textbox to a user form based on user requireme | Excel Programming | |||
User form ComboBox Items: Remember user entries? | Excel Programming | |||
How to: User Form to assign a user defined range to a macro variab | Excel Programming |