[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Bob Butler

1/26/2012 6:02:00 PM

I have a need in an app to have 2 unrelated windows such that if both are
behind other apps and the user brings one to the foreground the other stays
hidden. To demo the problem create a new project with 2 forms and in Form1
add this:

Private Sub Form1_Load()
Form2.Show
End Sub

Run the project and you get 2 forms displayed. Start something else like
Explorer and the 2 forms will be behind the new app but still showing on the
taskbar. Click either Form1 or Form2 on the taskbar and both forms will
jump to the front. I'm drawing a blank on how to unlink them so that they
behave independently. Is it even possible without using CreateWindow to
make the second form so it isn't owned by the hidden master window?

18 Answers

Jeff Johnson [MVP: VB]

1/26/2012 7:00:00 PM

0

"Bob Butler" <bob_butler@cox.invalid> wrote in message
news:jfs4hl$7hh$1@dont-email.me...

>I have a need in an app to have 2 unrelated windows such that if both are
>behind other apps and the user brings one to the foreground the other stays
>hidden. To demo the problem create a new project with 2 forms and in Form1
>add this:
>
> Private Sub Form1_Load()
> Form2.Show
> End Sub
>
> Run the project and you get 2 forms displayed. Start something else like
> Explorer and the 2 forms will be behind the new app but still showing on
> the taskbar. Click either Form1 or Form2 on the taskbar and both forms
> will jump to the front. I'm drawing a blank on how to unlink them so that
> they behave independently. Is it even possible without using CreateWindow
> to make the second form so it isn't owned by the hidden master window?

Just pulling this out of my ass: SetWindowParent() to 0? (Assuming that API
call even exists. You get the gist, I'm sure.)


Bob Butler

1/26/2012 7:57:00 PM

0


"Jeff Johnson" <I.get@enough.spam> wrote in message
news:jfs7ra$rp8$1@dont-email.me...
> "Bob Butler" <bob_butler@cox.invalid> wrote in message
> news:jfs4hl$7hh$1@dont-email.me...
>
>>I have a need in an app to have 2 unrelated windows such that if both are
>>behind other apps and the user brings one to the foreground the other
>>stays hidden. To demo the problem create a new project with 2 forms and
>>in Form1 add this:
>>
>> Private Sub Form1_Load()
>> Form2.Show
>> End Sub
>>
>> Run the project and you get 2 forms displayed. Start something else like
>> Explorer and the 2 forms will be behind the new app but still showing on
>> the taskbar. Click either Form1 or Form2 on the taskbar and both forms
>> will jump to the front. I'm drawing a blank on how to unlink them so
>> that they behave independently. Is it even possible without using
>> CreateWindow to make the second form so it isn't owned by the hidden
>> master window?
>
> Just pulling this out of my ass: SetWindowParent() to 0? (Assuming that
> API call even exists. You get the gist, I'm sure.)

That was my first thought and I tried using SetParent to GetDesktopWindow()
but it made no difference; I'm guessing it's the owner, not the parent, that
is causing this.

Jimekus

1/26/2012 9:01:00 PM

0

On Jan 27, 8:56 am, "Bob Butler" <bob_but...@cox.invalid> wrote:
> "Jeff Johnson" <I....@enough.spam> wrote in message
>
> news:jfs7ra$rp8$1@dont-email.me...
>
>
>
>
>
>
>
>
>
> > "Bob Butler" <bob_but...@cox.invalid> wrote in message
> >news:jfs4hl$7hh$1@dont-email.me...
>
> >>I have a need in an app to have 2 unrelated windows such that if both are
> >>behind other apps and the user brings one to the foreground the other
> >>stays hidden.  To demo the problem create a new project with 2 forms and
> >>in Form1 add this:
>
> >> Private Sub Form1_Load()
> >> Form2.Show
> >> End Sub
>
> >> Run the project and you get 2 forms displayed.  Start something else like
> >> Explorer and the 2 forms will be behind the new app but still showing on
> >> the taskbar.  Click either Form1 or Form2 on the taskbar and both forms
> >> will jump to the front.  I'm drawing a blank on how to unlink them so
> >> that they behave independently.  Is it even possible without using
> >> CreateWindow to make the second form so it isn't owned by the hidden
> >> master window?
>
> > Just pulling this out of my ass: SetWindowParent() to 0? (Assuming that
> > API call even exists. You get the gist, I'm sure.)
>
> That was my first thought and I tried using SetParent to GetDesktopWindow()
> but it made no difference; I'm guessing it's the owner, not the parent, that
> is causing this.

You could try setting the border style to none and they will not show
in the taskbar. Then you can create another mouse/mechanism for
bringing them to the front. Forms of this type are notorious for
acting independently and since moving my development over to Windows
7, some of my forms of this type are disappearing unpredictably.

Karl E. Peterson

1/26/2012 9:32:00 PM

0

Bob Butler pretended :
>> Just pulling this out of my ass: SetWindowParent() to 0? (Assuming that API
>> call even exists. You get the gist, I'm sure.)
>
> That was my first thought and I tried using SetParent to GetDesktopWindow()
> but it made no difference; I'm guessing it's the owner, not the parent, that
> is causing this.

Yeah. Tried GWL_HWNDPARENT?

--
..NET: It's About Trust!
http://vfre...


Bob Butler

1/26/2012 9:35:00 PM

0


"Jimekus" <jimekus@gmail.com> wrote in message
news:f0e14a91-206d-4d2c-ab9c-bd59a37786c4@ih8g2000pbc.googlegroups.com...
On Jan 27, 8:56 am, "Bob Butler" <bob_but...@cox.invalid> wrote:
> You could try setting the border style to none and they will not show
> in the taskbar. Then you can create another mouse/mechanism for
> bringing them to the front. Forms of this type are notorious for
> acting independently and since moving my development over to Windows
> 7, some of my forms of this type are disappearing unpredictably.

Guess I should have been more explicit... one of the 2 forms is already
borderless in the real app. The project two standard forms was just to help
make it easy to see the problem.

The app runs and the main form shows and then under certain conditions a
second form is shown in the lower right-hand corner; it is borderless and
uses transparency settings to gradually fade away (like the 'new mail'
popups in outlook and other similar apps). my problem is that if the main
form is not minimized it also comes to the front when I do secondform.show

I've tried using SetWindowPos and ShowWindow but the main form always jumps
to the front whenever the notification form shows.

Bob Butler

1/26/2012 9:50:00 PM

0


"Karl E. Peterson" <karl@exmvps.org> wrote in message
news:jfsgnl$ioi$1@dont-email.me...
> Bob Butler pretended :
>>> Just pulling this out of my ass: SetWindowParent() to 0? (Assuming that
>>> API call even exists. You get the gist, I'm sure.)
>>
>> That was my first thought and I tried using SetParent to
>> GetDesktopWindow() but it made no difference; I'm guessing it's the
>> owner, not the parent, that is causing this.
>
> Yeah. Tried GWL_HWNDPARENT?

I hadn't but it doesn't help. I'll play around some more with the simple
app and see if I can figure out what's going on.

Karl E. Peterson

1/26/2012 10:10:00 PM

0

Bob Butler explained :
> "Karl E. Peterson" <karl@exmvps.org> wrote in message
> news:jfsgnl$ioi$1@dont-email.me...
>> Bob Butler pretended :
>>>> Just pulling this out of my ass: SetWindowParent() to 0? (Assuming that
>>>> API call even exists. You get the gist, I'm sure.)
>>>
>>> That was my first thought and I tried using SetParent to
>>> GetDesktopWindow() but it made no difference; I'm guessing it's the owner,
>>> not the parent, that is causing this.
>>
>> Yeah. Tried GWL_HWNDPARENT?
>
> I hadn't but it doesn't help. I'll play around some more with the simple app
> and see if I can figure out what's going on.

Hmmmm, seems to work here. In Form1.frm:

Private Declare Function SetWindowLong Lib "user32" Alias
"SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal
dwNewLong As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias
"GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Private Const GWL_HWNDPARENT As Long = -8&
Private m_hParent As Long

Private Sub Form_Load()
m_hParent = GetWindowLong(Me.hWnd, GWL_HWNDPARENT)
Call SetWindowLong(Me.hWnd, GWL_HWNDPARENT, 0&)
Form2.Show
End Sub

Private Sub Form_Unload(Cancel As Integer)
Call SetWindowLong(Me.hWnd, GWL_HWNDPARENT, m_hParent)
End Sub

Same thing in Form2, minus the "Form2.Show" line. :-)

--
..NET: It's About Trust!
http://vfre...


unknown

1/26/2012 10:36:00 PM

0

"Bob Butler" <bob_butler@cox.invalid> wrote in message
news:jfs4hl$7hh$1@dont-email.me...
>I have a need in an app to have 2 unrelated windows such that if both are
>behind other apps and the user brings one to the foreground the other stays
>hidden. To demo the problem create a new project with 2 forms and in Form1
>add this:
>
> Private Sub Form1_Load()
> Form2.Show
> End Sub
>
> Run the project and you get 2 forms displayed. Start something else like
> Explorer and the 2 forms will be behind the new app but still showing on
> the taskbar. Click either Form1 or Form2 on the taskbar and both forms
> will jump to the front. I'm drawing a blank on how to unlink them so that
> they behave independently. Is it even possible without using CreateWindow
> to make the second form so it isn't owned by the hidden master window?

One way: Intercept WM_CREATE using a hook, and set hwndParent to 0. This
allows you to change the parameters that were used in the call to
CreateWindow(Ex). See fAppHook() function in the sample below:

http://www.thescarms.com/vbasic/Owner...


Karl E. Peterson

1/26/2012 11:07:00 PM

0

Farnsworth explained :
> One way: Intercept WM_CREATE using a hook, and set hwndParent to 0. This
> allows you to change the parameters that were used in the call to
> CreateWindow(Ex).

What's the advantage over a simple...

Call SetWindowLong(Me.hWnd, GWL_HWNDPARENT, 0&)

?

--
..NET: It's About Trust!
http://vfre...


Mike Scirocco

1/27/2012 1:45:00 AM

0

On 1/26/2012 3:07 PM, Karl E. Peterson wrote:
> Farnsworth explained :
>> One way: Intercept WM_CREATE using a hook, and set hwndParent to 0.
>> This allows you to change the parameters that were used in the call to
>> CreateWindow(Ex).
>
> What's the advantage over a simple...
>
> Call SetWindowLong(Me.hWnd, GWL_HWNDPARENT, 0&)
>
> ?

Or hide the one that is not on top?