User form styles

User form styles

Anonymous
Not applicable
656 Views
9 Replies
Message 1 of 10

User form styles

Anonymous
Not applicable
Hi, I'm using userforms in VBA, and I noticed that they only have a close option on the top right corner. Is it possible to add also the minimise and restore options to user forms? Thanks.

Edited by: maltaCAD on Jan 27, 2010 12:55 PM Edited by: maltaCAD on Jan 27, 2010 12:57 PM
0 Likes
657 Views
9 Replies
Replies (9)
Message 2 of 10

Anonymous
Not applicable
Can someone tell me if this can be done please? Thanks.
0 Likes
Message 3 of 10

Anonymous
Not applicable
Hello,

I've found the following link by doing some reaserch for my thread:

http://www.vbaexpress.com/kb/getarticle.php?kb_id=165

I haven't tried it yet but it seems to be what you're looking for.

Michel
0 Likes
Message 4 of 10

Anonymous
Not applicable
Other than Michel's suggestion the only thing I can think of is making it a external application (exe). I personally use Visual Basic and there your have a few choices, VB6 and VB.NET. Then there's them matter of how to execute the external application. The code below is from an addin button using VB.NET but Shell is also available in VBA, so you could make a macro that execute the external app.

{code}
'Addin button
Private Sub moBtnDef_GeneralNoteGenerator_OnExecute(ByVal Context As Inventor.NameValueMap) Handles moBtnDef_GeneralNoteGenerator.OnExecute
Dim sAddinPath As String
sAddinPath = System.Reflection.Assembly.GetExecutingAssembly.Location
sAddinPath = Mid(sAddinPath, 1, InStrRev(sAddinPath, "\"))

Shell(sAddinPath & "\GeneralNoteGenerator.exe", AppWinStyle.NormalFocus)
End Sub
{code}
0 Likes
Message 5 of 10

Anonymous
Not applicable
Thanks for your help...I tried the code on the link given by Michel as follows: (Note: I have several forms but if I manage to minimise form A, it would be enough)

In Module 1 I wrote:

Private Declare Function FindWindowA Lib "USER32" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Private Declare Function GetWindowLongA Lib "USER32" (ByVal hWnd As Long, ByVal nIndex As Long) As Long

Private Declare Function SetWindowLongA Lib "USER32" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Option Explicit

Sub FormatUserForm(UserFormCaption As String)

Dim hWnd As Long
Dim exLong As Long

hWnd = FindWindowA(vbNullString, UserFormCaption)
exLong = GetWindowLongA(hWnd, -16)
If (exLong And &H20000) = 0 Then
SetWindowLongA hWnd, -16, exLong Or &H20000
Else
End If

End Sub


Public Sub Foresee()
frmA.Show vbModeless
frmB.Hide
frmC.Hide
frmD.Hide
End Sub



Then in frmA I wrote:


Private Sub frmA_Initialize()

Call FormatUserForm(Me.Caption)

End Sub


However it's not working....actually it is skipping the Initialize part...why is that? thanks.
0 Likes
Message 6 of 10

Anonymous
Not applicable
Hello,

I'm not able to test it in Inventor but I have tested it in Excel and it works properly.

You can try to download the sample file of the link in order to check weather you have placed your code at the right place.

Michel
0 Likes
Message 7 of 10

Anonymous
Not applicable
Placing of the code seems ok....

However for some reason the Initialize method is not working. I tried to add Load FrmA before the Show method, but it still didn't work.
0 Likes
Message 8 of 10

Anonymous
Not applicable
I haven't tried any of this, so it may be basically the same, but this site
looks like it has a fair amount of info on it.

http://www.cpearson.com/excel/formcontrol.aspx

--
KWiKMcad
Kent Keller
"MaltaCAD" wrote in message news:6326830@discussion.autodesk.com...
Thanks for your help...I tried the code on the link given by Michel as
follows: (Note: I have several forms but if I manage to minimise form A, it
would be enough)

In Module 1 I wrote:

Private Declare Function FindWindowA Lib "USER32" (ByVal lpClassName As
String, ByVal lpWindowName As String) As Long

Private Declare Function GetWindowLongA Lib "USER32" (ByVal hWnd As Long,
ByVal nIndex As Long) As Long

Private Declare Function SetWindowLongA Lib "USER32" (ByVal hWnd As Long,
ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Option Explicit

Sub FormatUserForm(UserFormCaption As String)

Dim hWnd As Long
Dim exLong As Long

hWnd = FindWindowA(vbNullString, UserFormCaption)
exLong = GetWindowLongA(hWnd, -16)
If (exLong And &H20000) = 0 Then
SetWindowLongA hWnd, -16, exLong Or &H20000
Else
End If

End Sub


Public Sub Foresee()
frmA.Show vbModeless
frmB.Hide
frmC.Hide
frmD.Hide
End Sub



Then in frmA I wrote:


Private Sub frmA_Initialize()

Call FormatUserForm(Me.Caption)

End Sub


However it's not working....actually it is skipping the Initialize
part...why is that? thanks.
0 Likes
Message 9 of 10

Anonymous
Not applicable
Thanks....I have tried the code from that link you gave me Kent however it needs the following sub:

Function WindowHWnd(W As Excel.Window) As Long
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' WindowHWnd
' This returns the HWnd of the Window referenced by W.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Dim AppHWnd As Long
Dim DeskHWnd As Long
Dim WHWnd As Long
Dim Cap As String

AppHWnd = Application.hwnd
DeskHWnd = FindWindowEx(AppHWnd, 0&, C_EXCEL_DESK_CLASSNAME, vbNullString)
If DeskHWnd > 0 Then
Cap = WindowCaption(W)
WHWnd = FindWindowEx(DeskHWnd, 0&, C_EXCEL_WINDOW_CLASSNAME, Cap)
End If
WindowHWnd = WHWnd

End Function


And obviously Excel.Window (in the first line) is not being recognised. Is there such an object in Inventor? I have tried Inventor.Window and Autodesk.Window but seems that no such object exists.
0 Likes
Message 10 of 10

Anonymous
Not applicable
Finally I managed...I used another method to get the handle of the window and it's working now....

Thanks all for your help 🙂
0 Likes