Keep form at the back of all windows.
Hi there i was just thinking earlier if i could make a little application that stays on the back of all the applications. Like the desktop. I was just wanting to know if there was a little piece of code that keeps the form at the back all of the time, also i would like to know if there was a simple piece of code that takes away the minimize, maximize and the exit button from the top of the form.
Thanks in advanced.
Alistair.
Re: Keep form at the back of all windows.
For question #1. It is an API call. Try the following
Code:
' place this at the top of your form
Private Const HWND_BOTTOM As Long = 1
Private Const SWP_NOMOVE As Long = &H2
Private Const SWP_NOSIZE As Long = &H1
Private Declare Function SetWindowPos Lib "user32.dll" (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
' now in your form load event, try adding this line
SetWindowPos Me.hWnd, HWND_BOTTOM, 0,0, 0,0, SWP_NOMOVE Or SWP_NOSIZE
Note that the above won't guarantee that your form will always be at the bottom of the zOrder. This is because other windows can also add themselves to the bottom and if done after yours, then they will be below your window. Understand. There is another possible solution using SetParent and GetDesktopWindow APIs.
For question #2. Your form has a property call ControlBox. Set it to False
But be warned, if you do this then there is no way your users can close the application (except taskmanager) without you providing a menu or some other button to close it. Last but not least, you also want to prevent the window from showing on the task bar (ShowInTaskbar property), else users can hit FlyingWindowsKey + M to minimize your window. Pretty sure about that, but not positive.
Re: Keep form at the back of all windows.
Thanks yet again LaVolpe. Great work. I will reply later if it does what i want it to do.