none
C#怎么把窗体设在壁纸之上桌面图标之下 RRS feed

  • 问题

  • C#怎么把窗体设在壁纸之上桌面图标之下

     

    IntPtr P = FindWindow("Progman", "Program Manager"); P = FindWindowEx(P, IntPtr.Zero, "SHELLDLL_DefView", null); P = FindWindowEx(P, IntPtr.Zero, "SysListView32", null); SetParent(FrmName, P);

    在网上找到的这个还是会覆盖桌面图标!
    等待高人指点
    2009年11月29日 14:37

答案

  • /// <summary>
          /// 查找窗体
          /// </summary>
          /// <param name="lpClassName">窗体类名</param>
          /// <param name="lpWindowName">窗体标题</param>
          /// <returns></returns>
          [DllImport("User32.dll", EntryPoint = "FindWindow")]
          private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
          /// <summary>
          /// FindWindowEx 比 FindWindow 多出两个句柄参数
          /// </summary>
          /// <param name="hwndParent">要查找子窗体的父窗体句柄</param>
          /// <param name="hwndChildAfter">子窗体句柄</param>
          /// <param name="lpClassName"></param>
          /// <param name="lpWindowName"></param>
          /// <returns></returns>
          /// <remarks>如果 Parent 是 0, 则函数以桌面窗口为父窗口, 查找桌面窗口的所有子窗口;
          /// 如果是 HWND_MESSAGE, 函数仅查找所有消息窗口;
          /// 子窗口必须是 Parent 窗口的直接子窗口;
          /// 如果 Child 是 0, 查找从 Parent 的第一个子窗口开始
          /// 如果 Parent 和 Child 同时是 0, 则函数查找所有的顶层窗口及消息窗口.
          /// </remarks>
          [DllImport("User32.dll", EntryPoint = "FindWindowEx")]
          private static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpClassName, string lpWindowName);

          [DllImport("user32.dll", CharSet = CharSet.Auto)]
          public static extern IntPtr GetWindowDC(IntPtr hWnd);
          /// <summary>
          /// 设置父窗体
          /// </summary>
          /// <param name="child">要设置的窗体句柄</param>
          /// <param name="newParent">要设置为父窗体的句柄</param>
          /// <returns></returns>
          [DllImport("user32.dll", SetLastError = true)]
          static extern IntPtr SetParent(IntPtr child, IntPtr newParent);

          private void Form1_Load(object sender, EventArgs e)
          {

             IntPtr P = FindWindow("Progman", "Program Manager");
             IntPtr shellHandle = FindWindowEx(P, IntPtr.Zero, "SHELLDLL_DefView", null);
             IntPtr viewHandle = FindWindowEx(shellHandle, IntPtr.Zero, "SysListView32", null);

             SetParent(this.comboBoxTreeView1.Handle, viewHandle);

          }


    我试了下确实没法放在图标下一层 估计是控件窗体的handle没找对


    Wenn ich dich hab’,gibt es nichts, was unerträglich ist.坚持不懈!My blog~~~
    2009年11月30日 7:45
    版主
  • 你的窗口是桌面的子窗口,无法设置在父窗口之下。

    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful.
    Visual C++ MVP
    2009年11月30日 20:10
    版主

全部回复

  • /// <summary>
          /// 查找窗体
          /// </summary>
          /// <param name="lpClassName">窗体类名</param>
          /// <param name="lpWindowName">窗体标题</param>
          /// <returns></returns>
          [DllImport("User32.dll", EntryPoint = "FindWindow")]
          private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
          /// <summary>
          /// FindWindowEx 比 FindWindow 多出两个句柄参数
          /// </summary>
          /// <param name="hwndParent">要查找子窗体的父窗体句柄</param>
          /// <param name="hwndChildAfter">子窗体句柄</param>
          /// <param name="lpClassName"></param>
          /// <param name="lpWindowName"></param>
          /// <returns></returns>
          /// <remarks>如果 Parent 是 0, 则函数以桌面窗口为父窗口, 查找桌面窗口的所有子窗口;
          /// 如果是 HWND_MESSAGE, 函数仅查找所有消息窗口;
          /// 子窗口必须是 Parent 窗口的直接子窗口;
          /// 如果 Child 是 0, 查找从 Parent 的第一个子窗口开始
          /// 如果 Parent 和 Child 同时是 0, 则函数查找所有的顶层窗口及消息窗口.
          /// </remarks>
          [DllImport("User32.dll", EntryPoint = "FindWindowEx")]
          private static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpClassName, string lpWindowName);

          [DllImport("user32.dll", CharSet = CharSet.Auto)]
          public static extern IntPtr GetWindowDC(IntPtr hWnd);
          /// <summary>
          /// 设置父窗体
          /// </summary>
          /// <param name="child">要设置的窗体句柄</param>
          /// <param name="newParent">要设置为父窗体的句柄</param>
          /// <returns></returns>
          [DllImport("user32.dll", SetLastError = true)]
          static extern IntPtr SetParent(IntPtr child, IntPtr newParent);

          private void Form1_Load(object sender, EventArgs e)
          {

             IntPtr P = FindWindow("Progman", "Program Manager");
             IntPtr shellHandle = FindWindowEx(P, IntPtr.Zero, "SHELLDLL_DefView", null);
             IntPtr viewHandle = FindWindowEx(shellHandle, IntPtr.Zero, "SysListView32", null);

             SetParent(this.comboBoxTreeView1.Handle, viewHandle);

          }


    我试了下确实没法放在图标下一层 估计是控件窗体的handle没找对


    Wenn ich dich hab’,gibt es nichts, was unerträglich ist.坚持不懈!My blog~~~
    2009年11月30日 7:45
    版主
  • 你的窗口是桌面的子窗口,无法设置在父窗口之下。

    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful.
    Visual C++ MVP
    2009年11月30日 20:10
    版主