Re: Window always on bottom
Wow, it only took me 10 year to solve this one proper...
Subclass the WM_WINDOWPOSCHANGING message. The lParam is a WINDOWPOS. In vb6, you need to use RtlMoveMemory api function to copy the lParam to an empty WINDOWPOS variable.
Set the hWndInsertAfter field to HWND_BOTTOM and copy the structure back to the lParam.
In .Net (where I solved this problem), override the wndproc method. Look for the WINDOWPOSCHANGING message.
vb Code:
Dim memloc As IntPtr = m.LParam
Dim pos As WINDOWPOS = m.GetLParam(GetType(WINDOWPOS))
pos.hWndInsertAfter = HWND_BOTTOM
Marshal.StructureToPtr(pos, memloc, True)
Re: Window always on bottom
Quote:
Originally Posted by
agent
Wow, it only took me 10 year to solve this one proper...
Subclass the WM_WINDOWPOSCHANGING message. The lParam is a WINDOWPOS. In vb6, you need to use RtlMoveMemory api function to copy the lParam to an empty WINDOWPOS variable.
Set the hWndInsertAfter field to HWND_BOTTOM and copy the structure back to the lParam.
In .Net (where I solved this problem), override the wndproc method. Look for the WINDOWPOSCHANGING message.
vb Code:
Dim memloc As IntPtr = m.LParam
Dim pos As WINDOWPOS = m.GetLParam(GetType(WINDOWPOS))
pos.hWndInsertAfter = HWND_BOTTOM
Marshal.StructureToPtr(pos, memloc, True)
Could you (or any Good Samaritan) attach a small (but working) VB6 example project ?
Thanks,
Rob
PS I wouldn't know a windows shell if I found it on the beach. All I am looking for is a normal VB6 program running in a normal Windows (XP) that will allow my project's Form (or whatever display) always be on the bottom. It would show in front of the normal Windows desktop, but would never be in front of other running applications.
Re: Window always on bottom
Code:
'In a BAS module
Option Explicit
Private Const GWL_WNDPROC As Long = (-4&) 'Sets a new address for the window procedure.
Private Const HWND_BOTTOM As Long = 1 'Places the window at the bottom of the Z order.
Private Const WM_DESTROY As Long = &H2 'Sent when a window is being destroyed.
Private Const WM_WINDOWPOSCHANGING As Long = &H46 'Sent to a window whose size, position, or place in the Z order is about to change as a result of a call to the SetWindowPos function or another window-management function.
Private Declare Function CallWindowProc Lib "user32.dll" Alias "CallWindowProcW" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function SetWindowLong Lib "user32.dll" Alias "SetWindowLongW" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Sub PutMem4 Lib "msvbvm60.dll" (ByVal Ptr As Long, ByVal Value As Long)
Private m_PrevWndFunc As Long
'In Form_Load(), call it like: Subclass hWnd
Public Function Subclass(ByVal hWnd As Long) As Boolean
m_PrevWndFunc = SetWindowLong(hWnd, GWL_WNDPROC, AddressOf WindowProc)
Subclass = m_PrevWndFunc <> 0&
End Function
Private Function WindowProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Select Case uMsg
Case WM_WINDOWPOSCHANGING
PutMem4 lParam + 4&, HWND_BOTTOM 'hWndInsertAfter
Exit Function 'Return zero
Case WM_DESTROY
uMsg = SetWindowLong(hWnd, GWL_WNDPROC, m_PrevWndFunc): Debug.Assert uMsg
uMsg = WM_DESTROY
End Select
WindowProc = CallWindowProc(m_PrevWndFunc, hWnd, uMsg, wParam, lParam)
End Function
The Windows Shell:
Quote:
The Windows UI provides users with access to a wide variety of objects necessary for running applications and managing the operating system. The most numerous and familiar of these objects are the folders and files that reside on computer disk drives. There are also a number of virtual objects that allow the user to perform tasks such as sending files to remote printers or accessing the Recycle Bin. The Shell organizes these objects into a hierarchical namespace and provides users and applications with a consistent and efficient way to access and manage objects.