Home All Groups Group Topic Archive Search About
Author
19 Oct 2005 8:10 PM
Tommy
Hi,

I have an application with two forms. The application is often run in
background with form1 (maximized) and with for example Word on top. At a
certain time I want form2 to get visible.

Question: How can I get form2 on top without also putting form1 on top? I
want form1 to reside in the background if it is the current position.

Thanks

/Tommy

Author
19 Oct 2005 8:12 PM
Veign
Not sure what you are asking but if you are looking to force a window on top
check out the SetWindowPos API.

--
Chris Hanscom - Microsoft MVP (VB)
Veign's Resource Center
http://www.veign.com/vrc_main.asp
Veign's Blog
http://www.veign.com/blog
--


Show quoteHide quote
"Tommy" <To***@discussions.microsoft.com> wrote in message
news:619B8544-0EF3-4156-8676-D2039C85A0C3@microsoft.com...
> Hi,
>
> I have an application with two forms. The application is often run in
> background with form1 (maximized) and with for example Word on top. At a
> certain time I want form2 to get visible.
>
> Question: How can I get form2 on top without also putting form1 on top? I
> want form1 to reside in the background if it is the current position.
>
> Thanks
>
> /Tommy
>
Author
19 Oct 2005 8:27 PM
Someone
Use SetForegroundWindow. Example:

Option Explicit

Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As
Long) As Long

Private Sub Form_Load()
    Timer1.Interval = 5000 ' 5 seconds
End Sub

Private Sub Timer1_Timer()
    SetForegroundWindow Me.hwnd
End Sub


Show quoteHide quote
"Tommy" <To***@discussions.microsoft.com> wrote in message
news:619B8544-0EF3-4156-8676-D2039C85A0C3@microsoft.com...
> Hi,
>
> I have an application with two forms. The application is often run in
> background with form1 (maximized) and with for example Word on top. At a
> certain time I want form2 to get visible.
>
> Question: How can I get form2 on top without also putting form1 on top? I
> want form1 to reside in the background if it is the current position.
>
> Thanks
>
> /Tommy
>
Author
19 Oct 2005 8:53 PM
Jeff Johnson [MVP:VB]
"Tommy" <To***@discussions.microsoft.com> wrote in message
news:619B8544-0EF3-4156-8676-D2039C85A0C3@microsoft.com...

> I have an application with two forms. The application is often run in
> background with form1 (maximized) and with for example Word on top. At a
> certain time I want form2 to get visible.
>
> Question: How can I get form2 on top without also putting form1 on top? I
> want form1 to reside in the background if it is the current position.

Due to the voodoo that VB works behind the scenes, this is not possible.
When you activate one window in a VB app, they all come forward. This is
because they are all ultimately parented to a hidden window. This came up a
long time ago and I speculated that you might be able to play with
SetWindowLong() and remove this parentage, but I never tried it myself and I
don't think anyone else did either.
Author
19 Oct 2005 9:14 PM
Tom Esh
On Wed, 19 Oct 2005 13:10:06 -0700, "Tommy"
<To***@discussions.microsoft.com> wrote:

>I have an application with two forms. The application is often run in
>background with form1 (maximized) and with for example Word on top. At a
>certain time I want form2 to get visible.
>
>Question: How can I get form2 on top without also putting form1 on top? I
>want form1 to reside in the background if it is the current position.

As Jeff noted, by default VB forms are z-order linked to a hidden
"owner" window. However it's fairly simple to use the API to remove
the linkage and give a form independent z-ordering:

'declares (bas module)...
Public Const GWL_HWNDPARENT = (-8)
Public Declare Function SetWindowLong Lib "user32" _
    Alias "SetWindowLongA" _
    (ByVal hwnd As Long, ByVal nIndex As Long, _
    ByVal dwNewLong As Long) As Long


'usage (form module)...
SetWindowLong Me.hwnd, GWL_HWNDPARENT, 0


-Tom
MVP - Visual Basic
(please post replies to the newsgroup)