Solved

make a borderless form stay behind all other forms

Posted on 2014-02-02
22
283 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 46

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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

Author Comment

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

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 46

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 46

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 46

Expert Comment

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

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 46

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 46

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 46

Expert Comment

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

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 46

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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 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…

840 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