form on top

very easy question its just I didnt have time to search for an answer
How do you, w/out API, keep a form always on top?
LVL 6
boycyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

woottondCommented:
use the forms lost focus property - easy way to it is open up the code, select the form, pull down the procedure list select lostfocus. When the form calls this procedure this procedure could set it back on top.
0
MTroutwineCommented:
I don't really know of a way to keep your form on top of all other applications without using the SetWindowPos API call.  But you just want it to be on top of your application then you can use this:

  FormName.Show , ParentForm

This will keep it on top of your application
0
VbmasterCommented:
Add this to the form...

  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

  Property Let TopMost(sTopmost As Boolean)

    Const HWND_TOPMOST = -1
    Const HWND_NOTOPMOST = -2

    Select Case sTopmost
    Case Is = True
      Call SetWindowPos(Me.hwnd, HWND_TOPMOST, Me.Left \ Screen.TwipsPerPixelX, Me.Top \ Screen.TwipsPerPixelY, Me.Width \ Screen.TwipsPerPixelX, Me.Height \ Screen.TwipsPerPixelY, 0)
    Case Is = False
      Call SetWindowPos(Me.hwnd, HWND_NOTOPMOST, Me.Left \ Screen.TwipsPerPixelX, Me.Top \ Screen.TwipsPerPixelY, Me.Width \ Screen.TwipsPerPixelX, Me.Height \ Screen.TwipsPerPixelY, 0)
    End Select
 
  End Property


This will add a property to the form and you can set it using simple code like

  formname.TopMost = True
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

VbmasterCommented:
Above.
0
RuchiCommented:
Vvmaster: Boycy does not want the API.

I gave this following comment to the other same question.

try something like this.

Form1.Zorder

0
VbmasterCommented:
Oops
0
kbalarajuCommented:
>>
0
VbmasterCommented:
The correct way of doing this (put form on top) is using the API call, a cheesy (slow and dumb) way of doing it would be to add a timer control and use AppActivate formcaption_here. ;) This will make the end user really annoyed but hell.. if the programmer is so scared about API's the programs can't be any good anyway.
0
RuchiCommented:
I agree with Vbmaster fully.

Boycy: What's wrong with using API? Most programs the programmers make uses the API a lot. Learn how to use API.. I'd suggest that you can buy "Visual Basic Programmer's Guide to Win32 API" book by Dan Appleman, or you can check the site for beginner -- http://www.vbapi.com.
0
dosylCommented:
?
0
BrianWrenCommented:
boycy,

ummmm,  Why would you not want API if that will do what you want done?

Isn't the constraint of no API like asking, "How can I, w/out a saw, saw a piece of wood in half"?

JMHO

Brian
0
VBGuruCommented:
Have a timer control in your form with the default name. Following code should help

Option Explicit

Private Sub Form_Load()
Timer1.Interval = 200
End Sub

Private Sub Timer1_Timer()
On Error GoTo Err_handler
Screen.ActiveControl.SetFocus
Exit Sub
Err_handler:
SetFocus                'There are no controls on the form.
End Sub
0
caraf_gCommented:
"w/out API"

You don't. Period.
0
boycyAuthor Commented:
I remebered seeing a way somewhere to do it w/out API.
I can use the API, its just that it would be easier to not use it
I will cerainly not use a timer to do it, that would slow everything down too much
TNX vbmaster
0
McFauliCommented:
This is a very easy Question, so you don´t have to be on a experts Web Side
0
boycyAuthor Commented:
McFauli: if its such an easy question, can you answer it. The format of what I once saw went something along the lines of
<formname>.show vbmodal
I have tried this but it doesnt work, only makes the form not show in the taskbar
0
BrianWrenCommented:
With message boxes, you can do the following:

    msgbox "prompt", vbSystemModal . . .

Which leads me to believe that through APIs you can change the modality of windows, since a message box is, after all, a window.

vbModal makes a form modal for the app to which it belongs only.

Brian
0
boycyAuthor Commented:
I dont want to do it with a msgbox, but a single form on top of ALL other windows outside the app as well
0
caraf_gCommented:
"msgbox "prompt", vbSystemModal "

Well known Micro$oft lie. The message box actually is not system modal.

"System modal" does not exist in 32-bit Windows.
0
BrianWrenCommented:
caraf_g:

So what does system modal actually do?

And if there is no system modal, how is it that when you tell the machine to shutdown, you must address that dialog before you can do anythnig else?

(I'm not disagreeing, I'm curious.  What you just said doesn't seem to fit the evidence.)
0
caraf_gCommented:
"you must address that dialog before you can do anything else"

That's not true.

I think what they do is to bring up a borderless window with a half-greyed out capture of the screen on it. Then they show a little dialog on top of that.

The dialog is not system modal. Yes, you cannot use the mouse, because the borderless form in the background covers the whole desktop, but you can still use the keyboard.

Try hitting standard windows key combinations such as "windows key"+E and you'll see it still brings up Explorer.
0
caraf_gCommented:
"So what does system modal actually do?"
The same as modal. I think it's there to provide code-level backward compatibility with Win 3.x code, but that's all. It doesn't actually work as specified anymore.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.