Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

A form always (ON TOP)

Posted on 2003-03-21
6
Medium Priority
?
193 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
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
Technology Partners: 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

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month10 days, 5 hours left to enroll

571 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