想做一個桌面時鍾,釘在桌面上不影響正常使用,只在看桌面的時候顯示。
從網上多方尋找找到這么個代碼,但是還是有不方便的地方,大家探討一下。
這個程序在使用“顯示桌面”的時候還可以顯示,將程序的Form1.cs改為:
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- using System.Runtime.InteropServices;
- namespace cbgfinder
- {
- public partial class Form1 : Form
- {
- [DllImport("user32.dll", CharSet = CharSet.Auto)]
- public static extern IntPtr FindWindow([MarshalAs(UnmanagedType.LPTStr)] string lpClassName, [MarshalAs(UnmanagedType.LPTStr)] string lpWindowName);
- [DllImport("user32")]
- private static extern IntPtr FindWindowEx(IntPtr hWnd1, IntPtr hWnd2, string lpsz1, string lpsz2);
- [DllImport("user32.dll")]
- public static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- IntPtr pWnd = FindWindow("Progman", null);
- pWnd = FindWindowEx(pWnd, IntPtr.Zero, "SHELLDLL_DefVIew", null);
- pWnd = FindWindowEx(pWnd, IntPtr.Zero, "SysListView32", null);
- //IntPtr tWnd = new System.Windows.Interop.WindowInteropHelper(this).Handle;
- SetParent(this.Handle, pWnd);
- }
- }
- }
代碼的下載地址是:http://download.csdn.net/detail/icyfox_bupt/4382848 沒資源分
這個程序的問題在於,如果我想寫:
- this.FormBorderStyle=None
就是設置無邊框程序,就沒法釘在桌面,就成了正常的程序了
大家一起來討論一下吧。