C#在屏幕上画图
2014-07-11 13:55
337 查看
[DllImport("user32.dll")]
private static extern int GetDC(int hwnd);
private void button1_Click(object sender, EventArgs e)
{
System.IntPtr p = (IntPtr)GetDC(0);// '取得屏幕
Graphics g= Graphics.FromHdc(p);
g.DrawRectangle(new Pen(Color.Black),new Rectangle (100,100,100,100));
}
可能用到的API有:
[DllImport("user32.dll", EntryPoint = "GetDCEx", CharSet = CharSet.Auto, ExactSpelling = true)]
private static extern IntPtr IntGetDCEx(HandleRef hWnd, HandleRef hrgnClip, int flags);
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern IntPtr GetDesktopWindow();
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
private static extern int IntReleaseDC(HandleRef hWnd, HandleRef hDC);
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
private static extern bool RedrawWindow(HandleRef hwnd, ref RECT rcUpdate, HandleRef hrgnUpdate, int flags);
给你个在桌上画圆的代码吧:
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern IntPtr GetDesktopWindow();
[DllImport("user32.dll", EntryPoint = "GetDCEx", CharSet = CharSet.Auto, ExactSpelling = true)]
private static extern IntPtr GetDCEx(IntPtr hWnd, IntPtr hrgnClip, int flags);
private void button1_Click(object sender, EventArgs e)
{
IntPtr desk = GetDesktopWindow();
IntPtr deskDC = GetDCEx(desk, IntPtr.Zero, 0x403);
Graphics g = Graphics.FromHdc(deskDC);
g.FillEllipse(SystemBrushes.ControlText, 0, 0, 100, 100);
}
我利用了USER32.DLL和GDI32.DLL,为什么这样看不到矩形??
能否给出提示,谢谢
IntPtr hDC = PlatformInvokeUSER32.GetDC(PlatformInvokeUSER32.GetDesktopWindow());
Graphics m_Graphics=Graphics.FromHdc(hDC);
Pen redPen=new Pen(Color.Red, 10);
Rectangle rWorkArea = Screen.GetWorkingArea(Screen.PrimaryScreen.WorkingArea);
m_Graphics.DrawRectangle(redPen,rWorkArea);
PlatformInvokeUSER32.ReleaseDC(PlatformInvokeUSER32.GetDesktopWindow(), hDC);
[DllImport("User32.dll")]
public extern static System.IntPtr GetDC(System.IntPtr hWnd);
private void button1_Click(object sender, System.EventArgs e)
{
System.IntPtr DesktopHandle = GetDC(System.IntPtr.Zero);
Graphics g = System.Drawing.Graphics.FromHdc(DesktopHandle);
g.FillRectangle(new SolidBrush(Color.Red),0,0,100,100);
}
转自;http://wenku.baidu.com/link?url=K8JBBC9vfsDVYPi3sQ0H1ytB0vUpQZUmMw1AsBK5YVJ9Poeh5nkkzUWNkBcRd6dqgB9FQmbtO2CPFirTP8AjjGTA2lYw6oGPdghzXyWbrYG
转自:http://zhidao.baidu.com/link?url=AyjsfNQDhofQqTKVz0J8qXhP6gJocy28MKhv1EEPPrx-GyqWWN1_BhbMeQPsHySVJNBSARnXscBiCbd0A31Peq
private static extern int GetDC(int hwnd);
private void button1_Click(object sender, EventArgs e)
{
System.IntPtr p = (IntPtr)GetDC(0);// '取得屏幕
Graphics g= Graphics.FromHdc(p);
g.DrawRectangle(new Pen(Color.Black),new Rectangle (100,100,100,100));
}
可能用到的API有:
[DllImport("user32.dll", EntryPoint = "GetDCEx", CharSet = CharSet.Auto, ExactSpelling = true)]
private static extern IntPtr IntGetDCEx(HandleRef hWnd, HandleRef hrgnClip, int flags);
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern IntPtr GetDesktopWindow();
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
private static extern int IntReleaseDC(HandleRef hWnd, HandleRef hDC);
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
private static extern bool RedrawWindow(HandleRef hwnd, ref RECT rcUpdate, HandleRef hrgnUpdate, int flags);
给你个在桌上画圆的代码吧:
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern IntPtr GetDesktopWindow();
[DllImport("user32.dll", EntryPoint = "GetDCEx", CharSet = CharSet.Auto, ExactSpelling = true)]
private static extern IntPtr GetDCEx(IntPtr hWnd, IntPtr hrgnClip, int flags);
private void button1_Click(object sender, EventArgs e)
{
IntPtr desk = GetDesktopWindow();
IntPtr deskDC = GetDCEx(desk, IntPtr.Zero, 0x403);
Graphics g = Graphics.FromHdc(deskDC);
g.FillEllipse(SystemBrushes.ControlText, 0, 0, 100, 100);
}
我利用了USER32.DLL和GDI32.DLL,为什么这样看不到矩形??
能否给出提示,谢谢
IntPtr hDC = PlatformInvokeUSER32.GetDC(PlatformInvokeUSER32.GetDesktopWindow());
Graphics m_Graphics=Graphics.FromHdc(hDC);
Pen redPen=new Pen(Color.Red, 10);
Rectangle rWorkArea = Screen.GetWorkingArea(Screen.PrimaryScreen.WorkingArea);
m_Graphics.DrawRectangle(redPen,rWorkArea);
PlatformInvokeUSER32.ReleaseDC(PlatformInvokeUSER32.GetDesktopWindow(), hDC);
[DllImport("User32.dll")]
public extern static System.IntPtr GetDC(System.IntPtr hWnd);
private void button1_Click(object sender, System.EventArgs e)
{
System.IntPtr DesktopHandle = GetDC(System.IntPtr.Zero);
Graphics g = System.Drawing.Graphics.FromHdc(DesktopHandle);
g.FillRectangle(new SolidBrush(Color.Red),0,0,100,100);
}
转自;http://wenku.baidu.com/link?url=K8JBBC9vfsDVYPi3sQ0H1ytB0vUpQZUmMw1AsBK5YVJ9Poeh5nkkzUWNkBcRd6dqgB9FQmbtO2CPFirTP8AjjGTA2lYw6oGPdghzXyWbrYG
c#中怎么通过hdc获取当前窗口的句柄
using System.Runtime.InteropServices; using System.Drawing; public struct Rect { public int Left; public int Top; public int Right; public int Bottom; } class Program { [DllImport("user32.dll")] private static extern IntPtr GetDC(IntPtr hwnd); [DllImport("user32.dll")] private static extern IntPtr ReleaseDC(IntPtr hc, IntPtr hDest); [DllImport("user32.dll")] private static extern IntPtr GetWindowDC(IntPtr hwnd); [DllImport("user32.dll")] private static extern IntPtr GetForegroundWindow(); [DllImport("user32.dll")] private static extern int GetWindowRect(IntPtr hwnd, ref Rect lpRect); static void Main(string[] args) { IntPtr platDC = GetForegroundWindow(); IntPtr windDC = GetWindowDC(platDC); Rect rect = new Rect(); GetWindowRect(windDC, ref rect); Bitmap bmp = new Bitmap(rect.Right - rect.Left, rect.Bottom - rect.Top); Graphics g = Graphics.FromImage(bmp); IntPtr hdc = g.GetHdc(); } }
转自:http://zhidao.baidu.com/link?url=AyjsfNQDhofQqTKVz0J8qXhP6gJocy28MKhv1EEPPrx-GyqWWN1_BhbMeQPsHySVJNBSARnXscBiCbd0A31Peq
相关文章推荐
- 使用C#实现在屏幕上画图效果的代码实例
- C#在屏幕上画图
- C# 在屏幕上画图效果的经典例子
- c# 8条语句实现屏幕抓图
- 运用C#制作屏幕捕捉程序(2)
- C# 通过API获得屏幕某点的颜色(先转别人代码,有时间整理一下)
- c# 屏幕取词的方法(载)
- 运用C#制作屏幕捕捉程序(1)
- 活用C#截取计算机屏幕
- C#实现类似qq的屏幕截图程序
- C#实现类似qq的屏幕截图程序
- C#截取屏幕↑
- C#实现类似qq的屏幕截图程序
- c#利用windowsapi捕捉屏幕图片
- C#实现类似qq的屏幕截图程序
- c# 语句实现屏幕抓图
- 用C#写的一个简单屏幕保护程序
- c# 屏幕取词的方法
- c# 8条语句实现屏幕抓图
- c#利用windowsapi捕捉屏幕图片