C# Position Window On Desktop

后端 未结 1 1884
被撕碎了的回忆
被撕碎了的回忆 2020-12-18 13:18

Lets say I have a plain window in C#. It has no border styles so it cannot be moved or resized etc. How would i position that window so it appears at the same level as the d

相关标签:
1条回答
  • 2020-12-18 13:42

    If I understand you correctly and you want to draw on the desktop, basically, then this might help: http://www.neowin.net/forum/lofiversion/index.php/t293883.html

    [DllImport("user32.dll", CharSet=CharSet.Auto)]
     public static extern IntPtr FindWindow(
      [MarshalAs(UnmanagedType.LPTStr)] string lpClassName,
      [MarshalAs(UnmanagedType.LPTStr)] string lpWindowName);
    [DllImport("user32.dll")]
     public static extern IntPtr SetParent(
      IntPtr hWndChild,      // handle to window
      IntPtr hWndNewParent   // new parent window
      );
    
    
    IntPtr hwndf = this.Handle;
    IntPtr hwndParent = FindWindow("ProgMan", null);
    SetParent(hwndf,hwndParent);
    this.TopMost = false;
    

    That would reparent your form as a child window of the desktop itself.

    After reading the code some more times I'm not sure why they use FindWindow() looking for "ProgMan" instead of using

    [DllImport("user32.dll")]
    static extern IntPtr GetDesktopWindow();
    

    but I didn't give it a try myself so far.

    0 讨论(0)
提交回复
热议问题