Keep API dialog on top (Modal)

Keep API dialog on top (Modal)

fxcastil
Advocate Advocate
658 Views
8 Replies
Message 1 of 9

Keep API dialog on top (Modal)

fxcastil
Advocate
Advocate
I want to keep the API dialog forms such as (Folder & File Search) . I do not want the user to be able to mouse click inside the AutoCAD window when the from is shown, because this will minimize the dialog box and put it in the taskbar. I have read mant posts about how to do this but I can not keep the dialog form on top. The attached file has examples of how I tried to implement the previous posts.
0 Likes
659 Views
8 Replies
Replies (8)
Message 2 of 9

Anonymous
Not applicable
I use the following in VB executables I run from an ACAD macro:


*** The calling routine

mdlWindow.MakeTopMost Me.hwnd
Me.WindowState = 0


*** In a module I call mdlWindow.bas

Private Declare Function SetWindowPos Lib "user32" _
(ByVal hwnd As Long, _
ByVal hWndInsertAfter As Long, _
ByVal x As Long, y, _
ByVal cx As Long, _
ByVal cy As Long, _
ByVal wFlags As Long) As Long

Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1
Private Const SWP_NOACTIVATE = &H10
Private Const SWP_SHOWWINDOW = &H40
Private Const TOPMOST_FLAGS = SWP_NOMOVE Or SWP_NOSIZE

Public Sub MakeTopMost(Handle As Long)
SetWindowPos Handle, HWND_TOPMOST, 0, 0, 0, 0, TOPMOST_FLAGS
End Sub

Public Sub MakeNormal(Handle As Long)
SetWindowPos Handle, HWND_NOTOPMOST, 0, 0, 0, 0, TOPMOST_FLAGS
End Sub

It will remain stubbornly on top unless you put the minimize button on the
form and click it.

Lennart

wrote in message news:4995221@discussion.autodesk.com...
I want to keep the API dialog forms such as (Folder & File Search) . I do
not want the user to be able to mouse click inside the AutoCAD window when
the from is shown, because this will minimize the dialog box and put it in
the taskbar. I have read mant posts about how to do this but I can not keep
the dialog form on top. The attached file has examples of how I tried to
implement the previous posts.
0 Likes
Message 3 of 9

fxcastil
Advocate
Advocate
Lennart,

Can I get you to do me BIG favor and add this code to the file
I attched I had tried what you described in the attached file , but I can not get it working.

Thanks

Fred C
0 Likes
Message 4 of 9

Anonymous
Not applicable
Fred,
I do not see an attachment 🙂

I use the following...
In a code module:
Public Const SWP_DRAWFRAME = &H20
Public Const SWP_FRAMECHANGED = &H20
Public Const SWP_HIDEWINDOW = &H80
Public Const SWP_NOACTIVATE = &H10
Public Const SWP_NOCOPYBITS = &H100
Public Const SWP_NOMOVE = &H2
Public Const SWP_NOSIZE = &H1
Public Const SWP_NOREDRAW = &H8
Public Const SWP_NOZORDER = &H4
Public Const SWP_SHOWWINDOW = &H40
Public Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE
Public Const HWND_BOTTOM = 1
Public Const HWND_BROADCAST = &HFFFF&
Public Const HWND_DESKTOP = 0
Public Const HWND_NOTOPMOST = -2
Public Const HWND_TOP = 0
Public Const HWND_TOPMOST = -1

' Used for dealing with Forms
Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long

Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Any, ByVal lpWindowName As Any) As Long

Public Function SetTopMostWindow(hwnd As Long, TopMost As Boolean) As Long

If TopMost = True Then
SetTopMostWindow = SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, FLAGS)
Else
SetTopMostWindow = SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, FLAGS)
End If

End Function

And then in the Form's Initialize Event:
Dim retVal As Long
Dim hwndForm As Long

hwndForm = FindWindow(0&, UserForm1.Caption)
retVal = SetTopMostWindow(hwndForm, True)
0 Likes
Message 5 of 9

Anonymous
Not applicable
> I do not see an attachment 🙂

His first post had one.

--
Matt W
"Children are like TV sets. When they start acting weird, whack them across
the head with a big rubber basketball shoe."
0 Likes
Message 6 of 9

Anonymous
Not applicable
Thanks :)...I caught that after re-reading posts...

no editing of posts it seems 😞
0 Likes
Message 7 of 9

fxcastil
Advocate
Advocate
cmd,

The example you gave me uses the userform handle as the argument when calling the function for the setting the top most window. The example in my original post is not a VBA useform but an API dialog box. This is where I am having problems I have tried different methods of getting the dialog box handle and then passing this to the topmost function but still no sucess. I would really appreciate if someone could fix the sample file in my original post so I can actually this this implemented . I have tried all the suggestions given to me but I still can not get it right


Thanks,

Fred
0 Likes
Message 8 of 9

Anonymous
Not applicable
fxcastil <> wrote in news:4995987@discussion.autodesk.com:

> cmd,
>
> The example you gave me uses the userform handle as the argument when
> calling the function for the setting the top most window. The example
> in my original post is not a VBA useform but an API dialog box. This
> is where I am having problems I have tried different methods of
> getting the dialog box handle and then passing this to the topmost
> function but still no sucess. I would really appreciate if someone
> could fix the sample file in my original post so I can actually this
> this implemented . I have tried all the suggestions given to me but I
> still can not get it right
>
>
> Thanks,
>
> Fred


Setting BrwsInfo.howner = AutoCAD.hwnd should work, At least id did in
WindowsXP and Autocad 2006


- Jose
0 Likes
Message 9 of 9

fxcastil
Advocate
Advocate
Jose,

Thanks a bunch that was the trick. Unfortunately not a lot of information on the API function properties is available. I used the function
Declare Function GetActiveWindow Lib "user32" () As Long

to get the active AutoCAD.hwnd , this was an easy fix knowledge is wonderful thing.

Fred C.
0 Likes