C# Position Window On Desktop

好久不见. 提交于 2020-01-10 03:15:09

问题


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 desktop or one above?

Like a widget or a rainmeter skin. Any ideas?


回答1:


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.



来源:https://stackoverflow.com/questions/1966229/c-sharp-position-window-on-desktop

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