?
Solved

A form always (ON TOP)

Posted on 2003-03-21
6
Medium Priority
?
192 Views
Last Modified: 2010-05-01
I want to have a form always (ON TOP) and I don't want to use vbModal.
0
Comment
Question by:ADawn
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 5

Expert Comment

by:Rubyn
ID: 8180936
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 SWP_SHOWWINDOW = &H40
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1

Private Sub ShowWindowTopMost(Obj As Form)
    Call SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 100, 100, SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE)
End Sub

Private Sub Form_Load()
    Call ShowWindowTopMost(Me)
End Sub

You can also show any form using this function without using form1.show else you can use on form which is already shown to make it top most

This is exactly what you asked. :)
0
 

Accepted Solution

by:
Fuisseran earned 80 total points
ID: 8181081
This is what I use in a general .bas file i tend to attch to most of my projects

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 Sub AlwaysOntop(MyForm As Form, value As Boolean)
 If value Then
  SetWindowPos MyForm.hwnd, -1, 0, 0, 0, 0, &H1 Or &H2
 Else
  SetWindowPos MyForm.hwnd, -2, 0, 0, 0, 0, &H1 Or &H2
 End If
End Sub

You can then use the function at anytime to put any form ontop or not like this

AlwaysOntop frmMain, True ' makes the frmMain form always on top

AlwaysOntop frmmain, False ' makes the frmmain act as a normal window again
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 8181111
For that code to works, you should full test it with a compiled version of your program.
Cheers
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 8181628
try
YourForm.Show vbModeless, MainForm

The API suggestion above will put the form in top of ALL applications, vbModeless only in from of the form MainForm

Cheers
0
 

Expert Comment

by:CleanupPing
ID: 8531882
Hi ADawn,
This old question (QID 20558662) needs to be finalized -- accept an answer, split points, or get a refund.  Please see http://www.cityofangels.com/Experts/Closing.htm for information and options.
0
 
LVL 6

Expert Comment

by:GPrentice00
ID: 8957427
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

-->Accept Fuisseran 's comments as answer

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

GPrentice00
EE Cleanup Volunteer
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month10 days, 7 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question