Creating a .NET app that “docks” to the side of the screen and limits other windows' sizes when maximized

时间秒杀一切 提交于 2019-12-20 03:31:10

问题


I got an interesting request from the higher ups. They want a simple app that will show on users' computers to display the time in multiple time zones. That, in itself, is trivial; a simple window with a timer that will get the current UTC time and convert it to any number of time zones they want to see to update some labels' text.

Here's the rub, though; to meet requirements all around, the window can never obscure nor be obscured by anything else on the desktop. The user will be running other applications that must be fully visible at all times, and at the same time this app cannot be covered by one of those windows.

So, I was thinking of implementing it in one of two ways:

  • As an app that is always on top, but the background would be completely transparent and the time displays would be 50% transparent or some such. Moving the mouse over the window would "highlight" the time displays by removing their transparency and/or adding opaque high-contrast backgrounds. AFAIK this solution cannot use Windows Aero, because the OS of the primary users would be Windows XP.

  • As an app that uses low-level Windows messages to somehow mimic the behavior of the Windows taskbar in its "always on top" mode; it will dock to the top of the screen, will always show on top of "normal"-state windows, and additionally will govern the "maximize" behavior of other windows so that those windows won't overlap it when maximized.

I really have no idea where to start to implement either of these, but I would hazard a guess that given the WinXP limitation, the second option is easier if possible at all. So, what behaviors would I be looking to implement to tell Windows to never maximize over the top of my form?


回答1:


As an epitaph, since Hans Passant seems reticent to post answers, I found that what I needed was to make the app an "Application Desktop Toolbar", or Appbar. The CodePlex link Hans gave, http://codeproject.com/KB/dotnet/AppBar.aspx, as well as the MSDN article on the topic, http://msdn.microsoft.com/en-us/library/windows/desktop/cc144177%28v=vs.85%29.aspx, give a lot of information. I was able to pretty much copy/paste the region of code from CodePlex defining the AppBar behavior into an otherwise normal .NET form, to create a simple proof-of-concept:

The one change I made from the CodePlex code was to sever the half of RegisterBar() that registers the form as an AppBar from the code that tears it down, so a call to RegisterBar() always does exactly that instead of alternately registering and un-registering it.



来源:https://stackoverflow.com/questions/8510065/creating-a-net-app-that-docks-to-the-side-of-the-screen-and-limits-other-wind

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!