Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

make a borderless form stay behind all other forms

Posted on 2014-02-02
22
Medium Priority
?
287 Views
Last Modified: 2014-02-03
How can i make a border-less form stay behind all other forms ?
0
Comment
Question by:isnoend2001
[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
  • 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 49

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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

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

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 49

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 49

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 49

Expert Comment

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

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 49

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 49

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 49

Expert Comment

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

Accepted Solution

by:
Martin Liss earned 2000 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 49

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

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!

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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

721 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