日期:2014-05-18 浏览次数:21052 次
private IntPtr GetDesktopPtr() { //http://blog.csdn.net/mkdym/article/details/7018318 // 情况一 IntPtr hwndWorkerW = IntPtr.Zero; IntPtr hShellDefView = IntPtr.Zero; IntPtr hwndDesktop = IntPtr.Zero; IntPtr hProgMan = Win32.FindWindow("ProgMan", null); if (hProgMan != IntPtr.Zero) { hShellDefView = Win32.FindWindowEx(hProgMan, IntPtr.Zero, "SHELLDLL_DefView", null); if (hShellDefView != IntPtr.Zero) { hwndDesktop = Win32.FindWindowEx(hShellDefView, IntPtr.Zero, "SysListView32", null); } } if (hwndDesktop != IntPtr.Zero) return hwndDesktop; // 情况二 while (hwndDesktop == IntPtr.Zero) {//必须存在桌面窗口层次 hwndWorkerW = Win32.FindWindowEx(IntPtr.Zero, hwndWorkerW, "WorkerW", null);//获得WorkerW类的窗口 if (hwndWorkerW == IntPtr.Zero) break;//未知错误 hShellDefView = Win32.FindWindowEx(hwndWorkerW, IntPtr.Zero, "SysListView32", null); if (hShellDefView == IntPtr.Zero) continue; hwndDesktop = Win32.FindWindowEx(hShellDefView, IntPtr.Zero, "SysListView32", null); } return hwndDesktop; }