Two questions.
Why do you need to change the caption?
Where is DrawMenuBar defined?
--
HTH
RP
(remove nothere from the email address if mailing direct)
"RB Smissaert" <bartsmissaert@blueyonder.co.uk> wrote in message
news:Oe6GucEHFHA.4084@TK2MSFTNGP14.phx.gbl...
> I think I have this now all worked out.
> This is the code that does it:
>
>
> 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 Const WS_MAXIMIZEBOX = &H10000
> Private Const WS_MINIMIZEBOX = &H20000
> Private Const GWL_STYLE = (-16)
>
> Sub AddMinMax()
>
> Dim hWnd As Long
> Dim lngStyle As Long
>
> hWnd = FindWindow(vbNullString, MainForm.Caption)
>
> lngStyle = GetWindowLong(hWnd, GWL_STYLE)
> lngStyle = lngStyle Or WS_MAXIMIZEBOX
> lngStyle = lngStyle Or WS_MINIMIZEBOX
> SetWindowLong hWnd, GWL_STYLE, lngStyle
>
> DrawMenuBar hWnd
>
> End Sub
>
> Just have to run AddMinMax from the Userform Activate event and after any
> code that alters the caption
> of the userform via Userform.Caption =
> It works very nice indeed.
> Just have to make my keyboard shortcuts now to run these menubar buttons.
>
>
> RBS
>
>
> "RB Smissaert" <bartsmissaert@blueyonder.co.uk> wrote in message
> news:%23HpgJ3AHFHA.1392@TK2MSFTNGP10.phx.gbl...
> > How do I add minimize and maximize buttons to a VBA userform?
> > I have this code that does it, but when I change the caption of the
> > userform
> > the buttons don't work anymore. I am slowly coming to the conclusion
that
> > it probably is not worth the trouble and that it is better to make your
> > own buttons.
> >
> > Public Declare Function FindWindow _
> > Lib "user32" Alias _
> > "FindWindowA" (ByVal lpClassName As Long, _
> > ByVal lpWindowName 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 Sub UserForm_Initialize()
> >
> > Dim hWnd as Long
> >
> > hWnd = FindWindow(vbNullString, UserForm1.Caption)
> > SetWindowLong hWnd, -16, &H20000 Or &H10000 Or &H84C80080
> >
> > End Sub
> >
> >
> > RBS
> >
>
Bookmarks