设置Windows窗体被最底部 [英] Setting a Windows form to be bottommost

查看:432
本文介绍了设置Windows窗体被最底部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的一个现有客户的经营链,客户访问网上通过PC上网点:■设置为亭(定制的应用程序锁定的计算机上,直到用户已登录,并且流水账很大程度上是通过Windows组策略限制)。目前,每台计算机运行的是Windows XP和使用活动桌面显示的背景广告。但是,由于我的客户已经得到了问题的活动桌面崩溃每天(除普遍减慢电脑),我已要求开发替代它的应用程序。

One of my current clients runs a chain of Internet points where customers an access the net through PC:s set up as "kiosks" (a custom-built application "locks" the computer until a user has signed in, and the running account is heavily restricted through the Windows group policy). Currently, each computer is running Windows XP and uses Active Desktop to display advertisements in the background. However, since my client has got problems with Active Desktop crashing on a daily basis (in addition to generally slowing down the computer) I have been asked to develop an application that replaces it.

我想探讨是否有可能建立一个Windows窗体应用程序(使用C#)说的永远停留在背景的。应用程序应该趴在桌面以上(以便它涵盖任何图标,文件等),但始终所有其他正在运行的应用程序的后面。我想我真的找了表格类的<​​code>最底部属性(它不存在,当然, )。

I am trying to investigate whether it is possible to build a Windows forms application (using C#) that always stays in the background. The application should lie above the desktop (so that it covers any icons, files etc) but always behind all other running applications. I guess I'm really looking for a BottomMost property of the Form class (which doesn't exist, of course).

在如何实现这一目标的任何提示或指针将是非常美联社preciated。

Any tips or pointers on how to achieve this would be highly appreciated.

推荐答案

这是不是直接由.NET Form类的支持,所以你有两个选择:

This isn't directly supported by the .NET Form class, so you have two options:

1)使用Win32 API <一href="http://msdn.microsoft.com/en-us/library/ms633545%28VS.85%29.aspx"><$c$c>SetWindowPos功能。

1) Use the Win32 API SetWindowPos function.

pinvoke.net 展示了如何在C#中声明该使用说明:

pinvoke.net shows how to declare this for use in C#:

[DllImport("user32.dll")]
static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);

static readonly IntPtr HWND_BOTTOM = new IntPtr(1);
const UInt32 SWP_NOSIZE = 0x0001;
const UInt32 SWP_NOMOVE = 0x0002;
const UInt32 SWP_NOACTIVATE = 0x0010;

因此​​,在您code,拨打:

So in your code, call:

SetWindowPos(Handle, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);

当你评论,此招式的形式Z顺序的底部,但不保存它。唯一的解决方法,我可以看到这是调用 SetWindowPos 的Form_Load Form_Activate 事件。如果你的应用最大化,用户无法移动或最小化的形式,那么你可能逃脱这种方法,但它仍然是一个平庸的方法。另外,用户可能会看到一个轻微的忽悠如果窗体被带到Z顺序前的 SetWindowPos 呼叫会做的面前。

As you commented, this moves the form to the bottom of the z-order but doesn't keep it there. The only workaround I can see for this is to call SetWindowPos from the Form_Load and Form_Activate events. If your application is maximized and the user is unable to move or minimise the form then you might get away with this approach, but it's still something of a hack. Also the user might see a slight "flicker" if the form gets brought to the front of the z-order before the SetWindowPos call gets made.

2)子类的形式,覆盖的WndProc 功能和拦截 WM_WINDOWPOSCHANGING 的Windows消息,设置SWP_NOZORDER标志(摘自<一个href="http://stackoverflow.com/questions/595888/how-to-$p$pvent-a-control-from-changing-z-order/1133181#1133181">this 页)。

2) subclass the form, override the WndProc function and intercept the WM_WINDOWPOSCHANGING Windows message, setting the SWP_NOZORDER flag (taken from this page).

这篇关于设置Windows窗体被最底部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆