Keeping a VB App on top?.? 
Author Message
 Keeping a VB App on top?.?

How can you make a VB app stay on top?  I would like to keep my app on top
even if another app starts after mine, how would you do this?

--
Chris Barger
L3 Communications - Satellite Transmission System
Digital Systems Division
Voice (516) 272-5796



Sun, 12 Nov 2000 03:00:00 GMT  
 Keeping a VB App on top?.?

Chris,

Quote:
>How can you make a VB app stay on top?  I would like to keep my app on top
>even if another app starts after mine, how would you do this?

Use the Win32API's SetWidnowPos, Below is the description from the Win32.hlp
file.

Hope it helps,
-Erik Thompson

============================================================================
=

The SetWindowPos function changes the size, position, and Z order of a
child, pop-up, or top-level window. Child, pop-up, and top-level windows are
ordered according to their appearance on the screen. The topmost window
receives the highest rank and is the first window in the Z order.

BOOL SetWindowPos(

    HWND hWnd, // handle of window
    HWND hWndInsertAfter, // placement-order handle
    int X, // horizontal position
    int Y, // vertical position
    int cx, // width
    int cy, // height
    UINT uFlags  // window-positioning flags
   );

Parameters

hWnd

Identifies the window.

hWndInsertAfter

Identifies the window to precede the positioned window in the Z order. This
parameter must be a window handle or one of the following values:

Value Meaning
HWND_BOTTOM Places the window at the bottom of the Z order. If the hWnd
parameter identifies a topmost window, the window loses its topmost status
and is placed at the bottom of all other windows.
HWND_NOTOPMOST Places the window above all non-topmost windows (that is,
behind all topmost windows). This flag has no effect if the window is
already a non-topmost window.
HWND_TOP Places the window at the top of the Z order.
HWND_TOPMOST Places the window above all non-topmost windows. The window
maintains its topmost position even when it is deactivated.

For more information about how this parameter is used, see the following
Remarks section.

X

Specifies the new position of the left side of the window.

Y

Specifies the new position of the top of the window.

cx

Specifies the new width of the window, in pixels.

cy

Specifies the new height of the window, in pixels.

uFlags

Specifies the window sizing and positioning flags. This parameter can be a
combination of the following values:

Value Meaning
SWP_DRAWFRAME Draws a frame (defined in the window's class description)
around the window.
SWP_FRAMECHANGED Sends a WM_NCCALCSIZE message to the window, even if the
window's size is not being changed. If this flag is not specified,
WM_NCCALCSIZE is sent only when the window's size is being changed.
SWP_HIDEWINDOW Hides the window.
SWP_NOACTIVATE Does not activate the window. If this flag is not set, the
window is activated and moved to the top of either the topmost or
non-topmost group (depending on the setting of the hWndInsertAfter
parameter).
SWP_NOCOPYBITS Discards the entire contents of the client area. If this flag
is not specified, the valid contents of the client area are saved and copied
back into the client area after the window is sized or repositioned.
SWP_NOMOVE Retains the current position (ignores the X and Y parameters).
SWP_NOOWNERZORDER Does not change the owner window's position in the Z
order.
SWP_NOREDRAW Does not redraw changes. If this flag is set, no repainting of
any kind occurs. This applies to the client area, the nonclient area
(including the title bar and scroll bars), and any part of the parent window
uncovered as a result of the window being moved. When this flag is set, the
application must explicitly invalidate or redraw any parts of the window and
parent window that need redrawing.
SWP_NOREPOSITION Same as the SWP_NOOWNERZORDER flag.
SWP_NOSENDCHANGING Prevents the window from receiving the
WM_WINDOWPOSCHANGING message.
SWP_NOSIZE Retains the current size (ignores the cx and cy parameters).
SWP_NOZORDER Retains the current Z order (ignores the hWndInsertAfter
parameter).
SWP_SHOWWINDOW Displays the window.

Return Values

If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error
information, call GetLastError.

Remarks

If the SWP_SHOWWINDOW or SWP_HIDEWINDOW flag is set, the window cannot be
moved or sized.
All coordinates for child windows are client coordinates (relative to the
upper-left corner of the parent window's client area).
A window can be made a topmost window either by setting the hWndInsertAfter
parameter to HWND_TOPMOST and ensuring that the SWP_NOZORDER flag is not
set, or by setting a window's position in the Z order so that it is above
any existing topmost windows. When a non-topmost window is made topmost, its
owned windows are also made topmost. Its owners, however, are not changed.

If neither the SWP_NOACTIVATE nor SWP_NOZORDER flag is specified (that is,
when the application requests that a window be simultaneously activated and
its position in the Z order changed), the value specified in hWndInsertAfter
is used only in the following circumstances:

Neither the HWND_TOPMOST nor HWND_NOTOPMOST flag is specified in
hWndInsertAfter.
The window identified by hWnd is not the active window.

An application cannot activate an inactive window without also bringing it
to the top of the Z order. Applications can change an activated window's
position in the Z order without restrictions, or it can activate a window
and then move it to the top of the topmost or non-topmost windows.
If a topmost window is repositioned to the bottom (HWND_BOTTOM) of the Z
order or after any non-topmost window, it is no longer topmost. When a
topmost window is made non-topmost, its owners and its owned windows are
also made non-topmost windows.

A non-topmost window can own a topmost window, but the reverse cannot occur.
Any window (for example, a dialog box) owned by a topmost window is itself
made a topmost window, to ensure that all owned windows stay above their
owner.
If an application is not in the foreground, and should be in the foreground,
it must call the SetForegroundWindow function.



Sun, 12 Nov 2000 03:00:00 GMT  
 Keeping a VB App on top?.?

Quote:

>How can you make a VB app stay on top?  I would like to keep my app on top
>even if another app starts after mine, how would you do this?

you have to use the api:

Declare Sub SetWindowPos Lib "USER" (ByVal hWnd As Integer, ByVal
hWndInsertAfter As Integer, ByVal X As Integer, ByVal Y As Integer, ByVal cx
As Integer, ByVal cy As Integer, ByVal wFlags As Integer)

        ' SetWindowPos Flags
        Public Const SWP_NOSIZE = &H1
        Public Const SWP_NOMOVE = &H2
        Public Const SWP_NOZORDER = &H4
        Public Const SWP_NOREDRAW = &H8
        Public Const SWP_NOACTIVATE = &H10
        Public Const SWP_DRAWFRAME = &H20
        Public Const SWP_SHOWWINDOW = &H40
        Public Const SWP_HIDEWINDOW = &H80
        Public Const SWP_NOCOPYBITS = &H100
        Public Const SWP_NOREPOSITION = &H200

        'SetWindowPos() hWndInsertAfter values
        Public Const HWND_TOP = 0
        Public Const HWND_BOTTOM = 1
        Public Const HWND_TOPMOST = -1
        Public Const HWND_NOTOPMOST = -2

Sub AllwaysOnTop(hWnd As Long)
SetWindowPos hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE +
SWP_SHOWWINDOW
End Sub



Sun, 12 Nov 2000 03:00:00 GMT  
 Keeping a VB App on top?.?

I think we should change the subject of these newsgroups to: "Always on
top".  Afterall, enough people have asked how to do it.

Bodi

Quote:


>>How can you make a VB app stay on top?  I would like to keep my app on top
>>even if another app starts after mine, how would you do this?

>you have to use the api:

>Declare Sub SetWindowPos Lib "USER" (ByVal hWnd As Integer, ByVal
>hWndInsertAfter As Integer, ByVal X As Integer, ByVal Y As Integer, ByVal
cx
>As Integer, ByVal cy As Integer, ByVal wFlags As Integer)

>        ' SetWindowPos Flags
>        Public Const SWP_NOSIZE = &H1
>        Public Const SWP_NOMOVE = &H2
>        Public Const SWP_NOZORDER = &H4
>        Public Const SWP_NOREDRAW = &H8
>        Public Const SWP_NOACTIVATE = &H10
>        Public Const SWP_DRAWFRAME = &H20
>        Public Const SWP_SHOWWINDOW = &H40
>        Public Const SWP_HIDEWINDOW = &H80
>        Public Const SWP_NOCOPYBITS = &H100
>        Public Const SWP_NOREPOSITION = &H200

>        'SetWindowPos() hWndInsertAfter values
>        Public Const HWND_TOP = 0
>        Public Const HWND_BOTTOM = 1
>        Public Const HWND_TOPMOST = -1
>        Public Const HWND_NOTOPMOST = -2

>Sub AllwaysOnTop(hWnd As Long)
>SetWindowPos hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE +
>SWP_SHOWWINDOW
>End Sub

begin 666 Bodi Klamph.vcf
M0D5'24XZ5D-!4D0-"E9%4E-)3TXZ,BXQ#0I..DML86UP:#M";V1I#0I&3CI"
M;V1I($ML86UP: T*14U!24P[4%)%1CM)3E1%4DY%5#I"2VQA;7!H0$%Z=7)E

`
end


Sun, 12 Nov 2000 03:00:00 GMT  
 Keeping a VB App on top?.?

I think we should change the subject of these newsgroups to: "Always on
top".  Afterall, enough people have asked how to do it.

Bodi

Quote:


>>How can you make a VB app stay on top?  I would like to keep my app on top
>>even if another app starts after mine, how would you do this?

>you have to use the api:

>Declare Sub SetWindowPos Lib "USER" (ByVal hWnd As Integer, ByVal
>hWndInsertAfter As Integer, ByVal X As Integer, ByVal Y As Integer, ByVal
cx
>As Integer, ByVal cy As Integer, ByVal wFlags As Integer)

>        ' SetWindowPos Flags
>        Public Const SWP_NOSIZE = &H1
>        Public Const SWP_NOMOVE = &H2
>        Public Const SWP_NOZORDER = &H4
>        Public Const SWP_NOREDRAW = &H8
>        Public Const SWP_NOACTIVATE = &H10
>        Public Const SWP_DRAWFRAME = &H20
>        Public Const SWP_SHOWWINDOW = &H40
>        Public Const SWP_HIDEWINDOW = &H80
>        Public Const SWP_NOCOPYBITS = &H100
>        Public Const SWP_NOREPOSITION = &H200

>        'SetWindowPos() hWndInsertAfter values
>        Public Const HWND_TOP = 0
>        Public Const HWND_BOTTOM = 1
>        Public Const HWND_TOPMOST = -1
>        Public Const HWND_NOTOPMOST = -2

>Sub AllwaysOnTop(hWnd As Long)
>SetWindowPos hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE +
>SWP_SHOWWINDOW
>End Sub

begin 666 Bodi Klamph.vcf
M0D5'24XZ5D-!4D0-"E9%4E-)3TXZ,BXQ#0I..DML86UP:#M";V1I#0I&3CI"
M;V1I($ML86UP: T*14U!24P[4%)%1CM)3E1%4DY%5#I"2VQA;7!H0$%Z=7)E

`
end


Sun, 12 Nov 2000 03:00:00 GMT  
 Keeping a VB App on top?.?

Quote:

>I think we should change the subject of these newsgroups to: "Always on
>top".  Afterall, enough people have asked how to do it.

>Bodi

agreed.

i think there ought to be a chain. EVERYBODY asks once, and once you've
found out it's your job to answer the next 5 postings about it. after that,
ignore it. It's someone elses turn.



Tue, 14 Nov 2000 03:00:00 GMT  
 Keeping a VB App on top?.?

Perhaps what this ng needs is a way to keep the FAQ on top!

Quote:


>>I think we should change the subject of these newsgroups to: "Always on
>>top".  Afterall, enough people have asked how to do it.

>>Bodi

>agreed.

>i think there ought to be a chain. EVERYBODY asks once, and once you've
>found out it's your job to answer the next 5 postings about it. after that,
>ignore it. It's someone elses turn.



Tue, 14 Nov 2000 03:00:00 GMT  
 Keeping a VB App on top?.?

Sorry, looks like I was the latest to ask.  Though technically, I asked
how to keep my "form" "in front."  Thanks anyway, for helping us
struggling newbies.

Quote:

> Insert module.  Call function.

> --

> Tony Selke

> (please remove the _No-Junk-Mail_ prior to responding)

> /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\



> >>I think we should change the subject of these newsgroups to: "Always on
> >>top".  Afterall, enough people have asked how to do it.

> >>Bodi

> >agreed.

> >i think there ought to be a chain. EVERYBODY asks once, and once you've
> >found out it's your job to answer the next 5 postings about it. after that,
> >ignore it. It's someone elses turn.

>                    Name: OnTop.bas
>     Part 1.2       Type: unspecified type (application/octet-stream)
>                Encoding: x-uuencode



Fri, 17 Nov 2000 03:00:00 GMT  
 Keeping a VB App on top?.?

Quote:

>>>How can you make a VB app stay on top?  I would like to keep my app on

top

By coincidence, I made an activeX control to do this.  It was one of my
first experiments when I started playing around with ActiveX development in

you could find a use for it, I'll drop it on a web page.

However, it really is a rather large (code-wise) solution to something that
is relatively easy using the Win32 API



Fri, 17 Nov 2000 03:00:00 GMT  
 Keeping a VB App on top?.?

Quote:

> How can you make a VB app stay on top?  I would like to keep my app on top
> even if another app starts after mine, how would you do this?

> --
> Chris Barger
> L3 Communications - Satellite Transmission System
> Digital Systems Division
> Voice (516) 272-5796


Chris,

This question has been asked (and answered) hundreds of times in
Newsgroups.  Your best bet when you have a new question is to go to
www.dejanews.com and search for your topic.  Odds are you will find many
answers to your question.

In any case, you need to look at the SetWindowsPos API call.  You will
pass a flag into it something like HWND_TOPMOST.  This will make your
window the "topmost window" as far as Windows is concerned.  Another app
can call the same function later and take over your spot, but this is
not likely.  Most apps have no need to monopolize the screen.

Dan Appleman's book about VB Programming and Win32 API is sure to have
an example of this, and many other Windows API calls.

--
Regards,

Steve Woodward
Ford Motor Co.
PTEIS

**All postings constitute my opinions only**

Remove the # and everything after it in my email address to respond.



Tue, 21 Nov 2000 03:00:00 GMT  
 Keeping a VB App on top?.?

I'm clueless as to why this NG is FAQ-less??? Others have made the same
point recently. Let's get *on top* of this thing!

Pip pip,
Bertie

Quote:

>This question has been asked (and answered) hundreds of times in
>Newsgroups



Wed, 22 Nov 2000 03:00:00 GMT  
 Keeping a VB App on top?.?

The code to do this is also provided by the VB5 documentation, in the
example code given for the HWnd property.



Wed, 22 Nov 2000 03:00:00 GMT  
 
 [ 12 post ] 

 Relevant Pages 

1. how do you keep a vb app always on top

2. How to keep Office toolbar, taskbar on top of VB app

3. How to keep Office toolbar, taskbar on top of VB app

4. Keeping app on top

5. Keep App on Top?

6. Can't keep forms on top of my apps

7. How To Keep App On Top?

8. Keeping VB forms always on Top - SetWindowPos behavior?

9. Keeping VB applications on top

10. Keeping a VB program on Top

11. Keeping a VB form On Top

12. Keep a minimized VB app on top of other apps?

 

 
Powered by phpBB® Forum Software