Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to have my app "topmost"

3 views
Skip to first unread message

Kathy

unread,
Jan 8, 2005, 8:22:49 AM1/8/05
to
I want to app to be always the topmost window, i.e. the user
cannot bring other windows on topof my window. How do I
set this up?

Veign

unread,
Jan 8, 2005, 11:59:29 AM1/8/05
to
Set window order (aka Keep a Form On Top):
http://www.veign.com/vrc_codeview.asp?type=app&id=36

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

"Kathy" <kha...@yahoo.com.nospam> wrote in message
news:OoNhoUY9...@tk2msftngp13.phx.gbl...

CajunCoiler (http://tesla.msbdatasystems.com)

unread,
Jan 8, 2005, 3:55:41 PM1/8/05
to
I have a control to do just that.
Proceed to...
http://www.msbdatasystems.com/Downloads/VB/index.htm
...and look for the control "StayOnTop".

"Kathy" <kha...@yahoo.com.nospam> wrote in message
news:OoNhoUY9...@tk2msftngp13.phx.gbl...

Veign

unread,
Jan 8, 2005, 4:03:24 PM1/8/05
to
Why add a dependency for what is very simple to do through code?

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

"CajunCoiler (http://tesla.msbdatasystems.com)"
<cajun...@totallyspamless.msbdatasystems.com> wrote in message
news:gMXDd.46921$F25.6030@okepread07...

alpine

unread,
Jan 8, 2005, 4:52:56 PM1/8/05
to
And furthermore, what problem does the OP have with using the method
in Karl's ForceFore example? You can't get something done if you
aren't willing to use the correct methods to accomplish what you want
to do. ;-)

Bryan
____________________________________________________________
New Vision Software "When the going gets weird,"
Bryan Stafford "the weird turn pro."
alpine_don'tsen...@mvps.org Hunter S. Thompson -
Microsoft MVP-Visual Basic Fear and Loathing in LasVegas


On Sat, 8 Jan 2005 16:03:24 -0500, "Veign" <NOSPAM...@veign.com>
wrote:

Veign

unread,
Jan 8, 2005, 5:13:55 PM1/8/05
to
Was that from a prior post?

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

"alpine" <alpine_don'tsen...@mvps.org> wrote in message
news:kbl0u0hh089gq0i3q...@4ax.com...

Kathy

unread,
Jan 8, 2005, 6:01:05 PM1/8/05
to
Sorry yes, I posted earlier, as Alpine has said (different psudo
name). I have sorted it out, all that is necessary is

SetWindowPos( _
Me.hWnd, _
HWND_TOPMOST, _
0, _
0, _
0, _
0, _
SWP_NOSIZE Or SWP_NOMOVE _
)

in the form_load of the dialog. I don't believe anyone mentioned
this, so I suppose we can consider this as a new way, certainly
easier, and less hacking than the poke in the threads method of
enforcefor

Any comments?

Jeff Johnson [MVP: VB]

unread,
Jan 8, 2005, 6:18:53 PM1/8/05
to

"Veign" <NOSPAM...@veign.com> wrote in message
news:u0JEKYc9...@TK2MSFTNGP09.phx.gbl...

> Why add a dependency for what is very simple to do through code?

I believe I asked the same question of this person in the past.


alpine

unread,
Jan 8, 2005, 6:38:24 PM1/8/05
to
On Sat, 8 Jan 2005 23:01:05 -0000, "Kathy" <kha...@yahoo.com.nospam>
wrote:


It's not a "new way" but more of a "hack" method to attempt to
accomplish what you said you wanted to do. I say hack because it
doesn't set focus on your application. If you app is so all-fire
important that the user MUST interact with it when you want them to,
you should be shifting focus to it rather than just annoying them with
a topmost window that may or may not obscure what they were working
on. By failing to set focus to your app, you force the user to
undergo an extra step of first bringing focus to the app and only then
can they interact with your annoying window thus annoying them doubly.
(any app that was *that* annoying wouldn't last long on my system.
;-) )

HTH,

CajunCoiler (http://tesla.msbdatasystems.com)

unread,
Jan 9, 2005, 10:46:56 AM1/9/05
to
I'm getting a little fed up with the attitude you guys are taking
around here. Every time someone outside of your "clique"
answers a question, it's automatically wrong, or nonsense.

Well now dig this....
You add a dependency for the very simple reason
that doing it through code is NOT simple to these
newcomers. If it were was simple as you guys seem
to believe it is, they wouldn't be coming in here and
asking for help.

Now get off your high-horses, and let people talk,
without try to pick apart every word they say.


"Jeff Johnson [MVP: VB]" <i....@enough.spam> wrote in message
news:uHg4zgd9...@TK2MSFTNGP09.phx.gbl...

playwin

unread,
Jan 9, 2005, 11:49:01 AM1/9/05
to
Try following:

Public 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

Public Const HWND_TOPMOST = -1
Public Const HWND_NOTOPMOST = -2
Public Const SWP_NOMOVE = &H2
Public Const SWP_NOSIZE = &H1
Public Const FLAG = SWP_NOMOVE Or SWP_NOSIZE

Sub setWindowOnTop(ByVal handle As Long, _
Optional ontop As Boolean = True)

If ontop Then
Call SetWindowPos(handle, HWND_TOPMOST, 0, 0, 0, 0, FLAG)
Else
Call SetWindowPos(handle, HWND_NOTOPMOST, 0, 0, 0, 0, FLAG)
End If
End Sub

--> Happy coding!

--
_______________________________________________________________________

news:LkcEd.47265$F25.10109@okepread07...

playwin

unread,
Jan 9, 2005, 11:55:49 AM1/9/05
to
Try following:

'This should be only in one line...
Private 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

Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1
Private Const FLAG = SWP_NOMOVE Or SWP_NOSIZE

Sub setWindowOnTop(ByVal handle As Long, _
Optional ontop As Boolean = True)

If ontop Then
Call SetWindowPos(handle, HWND_TOPMOST, 0, 0, 0, 0, FLAG)
Else
Call SetWindowPos(handle, HWND_NOTOPMOST, 0, 0, 0, 0, FLAG)
End If
End Sub

--> Happy coding!


--
_______________________________________________________________________

news:LkcEd.47265$F25.10109@okepread07...

Veign

unread,
Jan 9, 2005, 12:24:46 PM1/9/05
to
Ouch...

Teaching someone to add a reference and drop a control on their form to
solve the problem is not teaching them anything. Giving them the code and
showing them how to use it teaches and gives them insight for future
situations that may arise.

A person should not get in the habit of adding 3rd party controls or DLL's.
This only add unnecessary references to a project and will only cause
problems in the future.

What advantage does adding a control over adding 20lines of code give
someone?

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

news:LkcEd.47265$F25.10109@okepread07...

Rick Rothstein

unread,
Jan 9, 2005, 12:32:26 PM1/9/05
to
> You add a dependency for the very simple reason
> that doing it through code is NOT simple to these
> newcomers. If it were was simple as you guys seem
> to believe it is, they wouldn't be coming in here and
> asking for help.

Just because something is simple to do doesn't mean everyone
automatically knows how to do it. That's why people come to the
newsgroups... to learn what they don't know (or are having trouble
figuring out how to make something work). If you look at the code Chris
(Veign) refers the OP to, it is one of the more light-duty API functions
around (and even has a nice self-describing name of SetWindowOrder). If
the OP is inspired to learn a little bit about API functions, this gives
him a starting point. On the other hand, if the OP simply copies and
uses the code directly, well that would be no different than
incorporating your ActiveX control into his project. Actually, there
would be one difference... the OP wouldn't have to carry around an extra
dependency with Chris' approach.

By the way, I took a quick look at your website. In particular, I looked
at your StringStuff code (String manipulation is sort of a hobby with
me<g>) and I have a couple of comments for you. In your IsDigits
function, if the programmer specifies True for your optional AlwDec
argument, the function will return True for inputted string values
containing multiple decimal points. You might consider putting in a
check for that. Your GetExtension function assumes all file extensions
are 3 characters long... that is not always the case. You might consider
looking for the last period in the string and assume anything after that
is an extension (however, that is not guaranteed since a file does not
have to have an extension and file names can contains periods; but it is
probably a reasonable rule to follow). While it is not a giant time
saver by any means, in your DeriveName function, you might consider
looping backwards through the string (Step -1, reverse loop limits) in
order to find the last backslash character. That way, as soon as you
find it, you can stop the loop (instead of traveling the string from
left to right and storing/replacing each previous backslash character
until you hit the end of the string).

Rick - MVP

Randy Birch

unread,
Jan 9, 2005, 12:45:33 PM1/9/05
to
Hi Rick ..

: (Veign) refers the OP to, it is one of the more light-duty API functions


: around (and even has a nice self-describing name of SetWindowOrder). If

The API is SetWindowPos; the wrapper is SetWindowOrder. :-)

--


Randy


alpine

unread,
Jan 9, 2005, 12:57:48 PM1/9/05
to
Even though your heart is in the right place in attempting to make
things easier for someone who doesn't understand the use of API
functions, you are actually making their life more difficult. This is
because they will have to deal with the extra reference that is added
to their project and the fact that having more references vastly
increases their chances of running into DLL hell issues when
distributing their applications.

If there is any "clique" involved here, it is the clique of those who
have experienced DLL hell first hand and want to help others avoid it.
So, it is the opinion of many who have been around awhile that it is
far better to teach someone how to do what they want to do using the
Windows API instead of steering them toward the potential of creating
DLL hell problems for their applications.

HTH,
Bryan
____________________________________________________________
New Vision Software "When the going gets weird,"
Bryan Stafford "the weird turn pro."
alpine_don'tsen...@mvps.org Hunter S. Thompson -
Microsoft MVP-Visual Basic Fear and Loathing in LasVegas


On Sun, 9 Jan 2005 09:46:56 -0600, "CajunCoiler
\(http://tesla.msbdatasystems.com\)"

Rick Rothstein

unread,
Jan 9, 2005, 12:50:19 PM1/9/05
to

Oops! Too fast with the Copy/Paste.

Rick

Gaurav - http://www.gauravcreations.com

unread,
Jan 10, 2005, 2:57:09 AM1/10/05
to
Here is hte api u need to call

' ontop api '
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

Const HWND_TOPMOST = -1
Const SWP_NOMOVE = &H2
Const SWP_NOSIZE = &H1
Const TOPMOST_FLAGS = SWP_NOMOVE Or SWP_NOSIZE

' make a form topmost '
Public Sub MakeTopMost(hWnd As Long)
SetWindowPos hWnd, HWND_TOPMOST, 0, 0, 0, 0, TOPMOST_FLAGS
End Sub


write the following the form load event

ontop.MakeTopMost hWnd

--
Gaurav Creations

J French

unread,
Jan 10, 2005, 3:48:31 AM1/10/05
to
On Sun, 9 Jan 2005 09:46:56 -0600, "CajunCoiler
\(http://tesla.msbdatasystems.com\)"
<cajun...@totallyspamless.msbdatasystems.com> wrote:

>I'm getting a little fed up with the attitude you guys are taking
>around here. Every time someone outside of your "clique"
>answers a question, it's automatically wrong, or nonsense.

Any advice that tells people to add a third party OCX or AX DLL is bad
advice


0 new messages