C# - on mouseover at taskbar, a preview is generated. how can i achieve this by C# coding

坚强是说给别人听的谎言 提交于 2019-11-27 02:28:03

问题


I am developing a winForm application in which i am list all the running processes. on mouseover of any process, i want preview window like (In Windows 7, when you mouse over an application in your task bar, a preview is generated showing the contents of the application window.) See Image.

Any idea how to achieve this, i am not able to get it. Any suggestion will be helpful. Thanks..


回答1:


full example at this site
You need two functions :

[DllImport("dwmapi.dll")]
static extern int DwmRegisterThumbnail(IntPtr dest, IntPtr src, out IntPtr thumb);

[DllImport("dwmapi.dll")]
static extern int DwmUpdateThumbnailProperties(IntPtr hThumb, ref DWM_THUMBNAIL_PROPERTIES props);

usage of DwmRegisterThumbnail
you are at your form, and process it a external program that you want to paint at your program.

IntPtr hWnd = process.MainWindowHandle;
int i = DwmRegisterThumbnail(this.Handle, hWnd, out thumb);

after registration, you just saying to windows the location to paint the picture

            DWM_THUMBNAIL_PROPERTIES props = new DWM_THUMBNAIL_PROPERTIES();

            props.fVisible = true;
            props.dwFlags = DWM_TNP_VISIBLE | DWM_TNP_RECTDESTINATION | DWM_TNP_OPACITY;
            props.opacity = 255;
            props.rcDestination = new Rect(panel.Left, panel.Top, panel.Right, panel.Bottom);

            DwmUpdateThumbnailProperties(thumb, ref props);



回答2:


You don't need to write any code to make this happen. It's part of the Aero theme, introduced with Windows Vista and still present in Windows 7. By default, a little thumbnail of the application's window is shown when you hover over its icon in the taskbar. That's true for the Skype example you showed, and also for a C# application that you write yourself.

If you want a finer level of control over exactly what gets shown in the preview (like if you only wanted to show a small portion of your app's window), you can write some code that calls one or more of the relevant DWM API functions.

But don't write all of the P/Invoke code yourself. Use one of the existing libraries that wraps it all up in a .NET friendly way, like Windows Forms Aero or the Windows API Code Pack.




回答3:


If you want your own application to display an Aero thumbnail, maybe this C++ sample could help you. Apparently it uses DwmRegisterThumbnail() to say "This HWND will now display a thumbnail of this other one".

So, a little P/Invoke call and IWin32Window...



来源:https://stackoverflow.com/questions/17484978/c-sharp-on-mouseover-at-taskbar-a-preview-is-generated-how-can-i-achieve-thi

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