Solved

make a borderless form stay behind all other forms

Posted on 2014-02-02
22
284 Views
Last Modified: 2014-02-03
How can i make a border-less form stay behind all other forms ?
0
Comment
Question by:isnoend2001
  • 11
  • 8
  • 2
  • +1
22 Comments
 
LVL 4

Expert Comment

by:ravikantninave
ID: 39827937
For example, to show Form2 in this way from Form1, you would use code like this:
Form2.Show vbModal

Open in new window


If you want to make the form go on top of others in your program at a particlar place in your code, but allow the user to switch to another form if they want to (and bring that one on top), you can just change the ZOrder of the form.

ZOrder is the "depth" position on screen, with 0 being the one which is "on top". To bring Form1 to the front you would do this:
Form1.ZOrder 0

Open in new window

To use this API you need to add the following declarations (in the "General" "Declarations" section of a form/module):
    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

Open in new window

To set Form1 to be "on top" of other forms use this code:
    Call SetWindowPos(Form1.hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE)

Open in new window

To return the form to normal, this is the code you need:
    Call SetWindowPos(Form1.hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE)

Open in new window

This code shows Form2, with Form1 being its owner:
Form2.Show vbModeless, Form1

Open in new window

0
 
LVL 47

Expert Comment

by:Martin Liss
ID: 39827961
Try this
Const HWND_BOTTOM As Long = 1

SetWindowPos Me.hWnd, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE
0
 

Author Comment

by:isnoend2001
ID: 39827962
Thanks for adding that
I think is what i need is the
Public Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long,
the form will always be be behind all other forms and never be brought to the front
0
Independent Software Vendors: 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!

 

Author Comment

by:isnoend2001
ID: 39827979
Martinliss i get
variable not defined on this: SWP_NOACTIVATE
0
 
LVL 47

Expert Comment

by:Martin Liss
ID: 39828108
Private Const SWP_NOACTIVATE = &H10
Private Const SWP_SHOWWINDOW = &H40
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 39828280
You should have an application called 'API Text Viewer' in 'Visual Studio 6 Tools'

If you open it and click on 'File', then 'Load Text File...', you should see 'WIN32API.TXT' in the list. Choose it and you will see a list of API function declarations. If you change the API Type to constants, you will get a list that includes those prefixed SWP_.

You might find the application useful in the future,
0
 
LVL 47

Expert Comment

by:Martin Liss
ID: 39828337
You don't have to leave VB6 to get API information. Just go to Add-ins|Api Viewer.
0
 

Author Comment

by:isnoend2001
ID: 39828441
maybe i'm doing something wrong, but that does not put the form behind other forms.
0
 
LVL 47

Expert Comment

by:Martin Liss
ID: 39828481
I'm not at home but will get back to you later.
0
 

Author Comment

by:isnoend2001
ID: 39828492
ok, thanks
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 39828510
Thanks Martin, for that shortcut.

I wish that I could estimate the cumulative hours that it could have saved me since it was introduced.

Unfortunately I don't know when the facility was introduced. I'm pretty sure that it wasn't there at all in VB1. At a guess, I would say VB3, though VB4 with its 16/32 bit versions would seem to be a logical point.
0
 
LVL 47

Expert Comment

by:Martin Liss
ID: 39828554
Thanks Martin, for that shortcut.
You're welcome.
0
 
LVL 47

Expert Comment

by:Martin Liss
ID: 39828575
isnoend2001, please don't take this as the last word on the subject but it may not be possible to do what you want with a borderless form. If you are willing to have a border then you could use a MDIForm as your main form at that type of form, by it's nature, stays in the background.
0
 

Author Comment

by:isnoend2001
ID: 39830125
MartinLiss;
The project I just uploaded the frmBackground is the form i am trying to stay behind all other forms. It fills the whole screen and when smaller forms are shown the effect of Bonus screens would not be so dramatic
I was thinking maybe this would work:
Use a form with a border and set the .top to a negative number to hide the titlle bar.
Possible ?.
0
 
LVL 47

Expert Comment

by:Martin Liss
ID: 39830191
Assuming that frmBackground is showing, is there ever going to be a time when more than one other form will need to be shown?
0
 

Author Comment

by:isnoend2001
ID: 39830240
yes i think frmCleoOptions, frmCleoPayout, and the commondialog
all open in front of frmCleo
0
 
LVL 47

Expert Comment

by:Martin Liss
ID: 39830254
When I force frmBackround to be shown, it shows text that says "12 Free Plays Initiated...". How does that happen?
0
 
LVL 47

Expert Comment

by:Martin Liss
ID: 39830292
Never mind, I see that it's frmBonus12 that I'm looking at.
0
 
LVL 47

Accepted Solution

by:
Martin Liss earned 500 total points
ID: 39830331
The problem does not seem to be getting frmBackground to be the background, instead it's that when other forms are shown on top of it, clicking frmBackground makes the other forms disappear. I think the only solution is to add a MDIForm to your project and use that instead of frmBackground. If you then make all your other forms MDIChild forms it will do what you want.
0
 

Author Closing Comment

by:isnoend2001
ID: 39830379
thanks for your help
Don't know about those MidiForms never used them. will give it more thought
0
 
LVL 47

Expert Comment

by:Martin Liss
ID: 39830419
Here's a bare-bones MDI project. I added the background color.
Q-28354481.zip
0
 

Author Comment

by:isnoend2001
ID: 39830459
Thanks i will check it out
0

Featured Post

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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Spell Check in VB6 13 135
MsgBox 4 71
VBA: copy range dynamically based on config sheet v2 3 55
Error with a code discussed on this page 5 38
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

735 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