简体   繁体   中英

How to get a print screen of the desktop without any windows or the taskbar?

My application is a Windows Forms one.

I tried using the windows wallpaper, but this depends on the "Fill", "Stretch", "Fit" or "Tile" settings. I just need the image as it is on the desktop, but including the part "under" the taskbar, because this part is visible in case of transparent taskbar.

Why I need this? Because I have a tray application which slides from under the taskbar when opening. And I need to set a mask there, so it can't be seen sliding, until it reaches the top of the taskbar. Again, this is only a problem when the taskbar is transparent.

I am not sure if I understood your question correctly. But to me, it seems that you need the image that has created wallpaper. If it seems easier, take a look at registry entries at following location:

HKEY_CURRENT_USER\Control Panel\Desktop

This will give you the path, size, tile/no tile etc. information for the wallpaper.

您可以尝试使用一个名为PaintDesktop的Win32函数,但是除非我误解了您,否则您应该能够调整窗口的高度,因此它永远不会真正位于任务栏的后面。

Why I need this? Because I have a tray application which slides from under the taskbar when opening. And I need to set a mask there, so it can't be seen sliding, until it reaches the top of the taskbar. Again, this is only a problem when the taskbar is transparent.

The problem here is that you're starting the slide up from the bottom of the entire screen , rather than starting from the bottom of the screen's working area (ie, the top of the taskbar). That's why you're seeing the pop-up window slide up behind a transparent taskbar.

Luckily, the solution is much simpler than obtaining the desktop background and/or doing any type of masking. It's also much faster , and it's always good that your eye candy isn't unnecessarily taxing the user's computer.

All you need to do is determine the coordinates of the screen's working area, which is defined by Windows as the area that can be used by applications, not including the taskbar and other side bars. You can obtain this information easily in WinForms by querying the Screen.PrimaryScreen.WorkingArea property . This will return a Rectangle that corresponds to the primary screen's working area. Since you know that the taskbar is always displayed on the primary screen, this is exactly what you want.

Once you have the coordinates of the primary screen's working area, start your pop-up window's slide from the bottom of that. *

This is a good lesson of why you should always include an explanation of why you want to accomplish something. There's often an even better way that you haven't thought of.

* Of course, I'm ignoring the fact that a user might not have their taskbar positioned at the bottom of the screen. You can put it on either side or even on top. It sounds to me like you haven't considered this in your question, either. If this is an app that you're writing only for yourself or for a controlled environment where you can be sure that no one has their taskbar in non-default positions, that might be OK. But if you're writing software to distribute to a wider audience, you will need to take this into account. The rcWork coordinates will be correct, regardless of where the taskbar is positioned, of course, but you will need to know whether to start the pop-up window's slide from the bottom, the left side, the right side, or the top.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM