Click here to Skip to main content
Click here to Skip to main content

Tagged as

Go to top

Creating a BOTTOMMOST Window

, 16 Mar 2012
Rate this:
Please Sign up or sign in to vote.
How to create a BOTTOMMOST window (Win32 and .NET).

Introduction

To create a topmost window is simple, thanks to window style WS_EX_TOPMOST or Form.TopMost propertie in .NET. But unfortunately the counter part style BOTTOMMOST is not out of the box.

Background

An application window Z order, along with other parameters, can be enforced at runtime by modifying WINDOWPOS structure received with WM_WINOWPOSCHANGING message.

Using the code

To create a bottommost window, on the window message WM_WINOWPOSCHANGING add this code:
((LPWINDOWPOS)lParam)->hwndInsertAfter = HWND_BOTTOM;
This works in C or C++. For .NET, the code can be included in a dll and used inside the window procedure.
The resulted window behave like it is embedded in the wallpaper.

 dll code (C):

__declspec(dllexport) void Bottommost(LPARAM lParam);

void Bottommost(LPARAM lParam)
{
((LPWINDOWPOS)lParam)->hwndInsertAfter = HWND_BOTTOM;
}

C# code:

using System.Runtime.InteropServices;

[DllImport("mydll.dll")]
static extern void Bottommost(IntPtr lParam);

[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")]
protected override void WndProc(ref Message Message)
{
if (Message.Msg == 0x46)//WM_WINDOWPOSCHANGING
{
Bottommost(Message.LParam);
}
base.WndProc(ref Message);
}

VB code:

Imports System.Runtime.InteropServices

<DllImport("mydll.dll")>
Shared Function Bottommost(lParam As IntPtr) As Boolean
End Function

<System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")>
Protected Overrides Sub WndProc(ByRef Message As Message)
If (Message.Msg = &H46) Then 'WM_WINDOWPOSCHANGING
Bottommost(Message.LParam)
End If
MyBase.WndProc(Message)
End Sub

 Win32 code (C, C++):

LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
switch(Message)
{
case WM_WINDOWPOSCHANGING:
((LPWINDOWPOS)lParam)->hwndInsertAfter = HWND_BOTTOM;
return 0L;    
break;
//...
}
return DefWindowProc(hwnd, Message, wParam, lParam);
}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Florin Gherghel

United States United States
No Biography provided

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | Last Updated 16 Mar 2012
Article Copyright 2012 by Florin Gherghel
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid