C#桌面上畫了一個實心的紅色矩形

這段代碼是我參考網上的vc代碼翻譯成c#,然後我再桌面上畫了一個實心的紅色矩形,可以參考一下
C# code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace WindowsFormsApplication13
{
    public partial class Form1 : Form
    {
        [DllImport("User32.dll ", EntryPoint = "FindWindow")]
        static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

        [DllImport("User32.dll ")]
        static extern IntPtr FindWindowEx(IntPtr parent, IntPtr childe, string strclass, string strname);

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            IntPtr P = FindWindow("Progman", "Program Manager");
            P = FindWindowEx(P, IntPtr.Zero, "SHELLDLL_DefView", null);
            P = FindWindowEx(P, IntPtr.Zero, "SysListView32", null);
            Graphics G = Graphics.FromHwnd(P);
            G.FillRectangle(new SolidBrush(Color.Red), new Rectangle(new Point(100, 100), new Size(500, 500)));
            G.Dispose();
        }
    }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章