modal form is not at the front when parent form is set to stay on top

I have a form where I can set it to stay on top. On this form, I have a menu entry for an about box which is modal.

In normal operation, ie no staying on top, the about form displays properly and the mainform won't get focus until the about box is dismissed. This is good.

When I select the main form to stay on top, then select the about form, the about form goes behind the main form, which I suppose is correct as this is what I am asking for, but how do I get the about box to stay over the main form?

Vas.
[542 byte] By [vserghi] at [2007-11-20 10:03:05]
# 1 Re: modal form is not at the front when parent form is set to stay on top
Hi Vas :) ,

Use:
frmAbout.Show 1, Me
manu.patel at 2007-11-9 19:35:45 >
# 2 Re: modal form is not at the front when parent form is set to stay on top
I already have this; perhaps I should of posted some code also.

This is what I have so open the about form

frmAbout.show vbModal, me

I am using SetWindowPos API in the user32 library in the main form. When I select "Stay On Top", this code gets called;

Public Sub mnuWinOnTop_Click()

winOnTop Me.hwnd, True

End Sub

Public Sub winOnTop(frmID as long, onTop as Boolean)

Const SWP_NOMOVE = 2
Const SWP NOSIZE = 1
Const HWND_TOPMOST = -1
Const HWND_NOTOPMOST = -2
Const FLAGS = SWP_NOMOVE or SWP_NOSIZE

if onTop = True then
onTop = SetWindowPos(frmID, HWND_TOPMOST, 0, 0, 0, FLAGS)
else
onTop = SetWindowPos(frmID, HWND_NOTOPMOST, 0, 0, 0, FLAGS)
end if

end sub

I have also tried tried changing the ZOrder of the forms, without any success;

frmMain.ZOrder(1)
frmAbout.ZOrder(0)
vserghi at 2007-11-9 19:36:51 >
# 3 Re: modal form is not at the front when parent form is set to stay on top
I had a problem like that. Ended up getting rid of the modal form, and just doing it myself.
dglienna at 2007-11-9 19:37:45 >
# 4 Re: modal form is not at the front when parent form is set to stay on top
Just you need to create your about form also onTop by calling your winOnTop procedure inside aboutForm's load event.

Before that, you need to transfer all your api, const and procedure to module and then call from any form.
pragashan at 2007-11-9 19:38:50 >
# 5 Re: modal form is not at the front when parent form is set to stay on top
Funnily enough, I had a thought today to take the winOnTop off the main form whilst any modal form is being shown. This would still allow the about box top be modal.

I'll try this, and let you all know.
vserghi at 2007-11-9 19:39:49 >
# 6 Re: modal form is not at the front when parent form is set to stay on top
Funnily enough, I had a thought today to take the winOnTop off the main form whilst any modal form is being shown. This would still allow the about box top be modal.

I'll try this, and let you all know.

If you take off the main form topwin then you can access all other windows even if you show the model as topwin.

check this code.
pragashan at 2007-11-9 19:40:51 >
# 7 Re: modal form is not at the front when parent form is set to stay on top
Tried this, and it did work, although I now have another problem where I cannot set the focus onto a text box.

searchTextBox.setfocus is put in the Form_Activate function. This works ok, if I do not use the winStayOnTop. As soon as I make the changes as above, ie, make the main form normal again whilst the about box is modal, whenever the Form_Activate function is called it brings an error when I try to set the focus back onto the searchTextBox

I'll have a look at your code tomorrow, thanks.
vserghi at 2007-11-9 19:41:50 >
# 8 Re: modal form is not at the front when parent form is set to stay on top
That did it!!!!. Thank you, thank you, thank you, thank you, thank you, thank you.

I moved the winOnTop stuff into the main module.bas, and got every form to go winOnTop in Form_Activate. Even the focusing issue has gone. Thanks for code it really helped.

I thought that I would have top drop this feature because of this problem. Big thank you again.
vserghi at 2007-11-9 19:42:59 >