开发者

Setting form as back-most. A form that always stays in background - vb6

开发者 https://www.devze.com 2023-01-18 10:59 出处:网络
Is there a way to set a form as back开发者_如何学C-most (form which always stays in the back no matter what you click on the form)?

Is there a way to set a form as back开发者_如何学C-most (form which always stays in the back no matter what you click on the form)?

I am writing a shell replacement and just using topmost on every window I start really messes some things up for some applications.


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.


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 `

0

精彩评论

暂无评论...
验证码 换一张
取 消