tags:

views:

28

answers:

2

Hi! Is there a way to set a form as back-most (form wich always stays in the back no matter what you click on the form) I am writting a shell replacemement and just using topmost on every window I start really messes some things up for some applications.

Thanks!

A: 

Disclaimer: this is completely untested.

First, on Form_Load you'll want to use the SetWindowPos API to put your form below all others:

Private Const SWP_NOSIZE = &H1
Private Const SWP_NOMOVE = &H2
Private Const HWND_BOTTOM = 1

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

' Somewhere in form_load...    
RetVal = SetWindowPos(Me.hwnd, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE)

If that is not enough, you will probably need to subclass the form and watch for WM_ACTIVATE and/or WM_MOUSEACTIVATE and redirect those messages. For WM_MOUSEACTIVATE, redirecting to MA_NOACTIVATE could work; for the WM_ACTIVATE message, redirect to WA_INACTIVE.

Joe
A: 

I've found an alternative using a hook to detect opened windows. I'm putting all new windows opened (with parrent or no parrent as topmost) wich acutaly solves the problem and puts the shell interface in the background as it should. The very simplified hooked function looks something like this:

`Public Sub WindowCreated(hwnd As Long)

If Not hwnd = Me.hwnd Then If IsWindowVisible(hwnd) Then

      WindowHandle hwnd, 6 ' set form as topmost and focused
        WindowHandle hwnd, 5

End If end sub `

Miha