How do I display open IE tabs as DWM thumbnails?

前端 未结 3 796
面向向阳花
面向向阳花 2021-02-20 06:46

I am building a WPF application in C# and I want to display thumbnails of open IE tabs in a listbox. I\'m essentially trying to duplicate the DWM functionality in Windows 7.

3条回答
  •  太阳男子
    2021-02-20 07:04

    This code enumerates window handles that correspond to IE thumbnails and can be used as the hwndSource parameter of the DwmRegisterThumbnail function

    public static IEnumerable EnumerateIEDwmThumbnails()
    {
        List ptrs = new List();
        StringBuilder cls = new StringBuilder(100);
        EnumWindows((hwnd, lparam) =>
        {
            GetClassName(hwnd, cls, cls.Capacity);
            if (cls.ToString() == "TabThumbnailWindow")
            {
                ptrs.Add(hwnd);
            }
            return true;
        }, IntPtr.Zero);
        return ptrs;
    }
    
    [DllImport("user32.dll")]
    private static extern bool EnumWindows(EnumWindowsCallback lpEnumFunc, IntPtr lParam);
    private delegate bool EnumWindowsCallback(IntPtr hwnd, IntPtr lParam);
    
    [DllImport("user32.dll")]
    private static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount);
    

提交回复
热议问题