如何有效地借鉴C#桌面? [英] How to effectively draw on desktop in C#?

查看:149
本文介绍了如何有效地借鉴C#桌面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想直接在C#在桌面上进行绘制。从搜索了一下,我结束了使用从桌面HDC(空)Graphics对象。然后,我画通常使用该图形对象。

I want to draw directly on the desktop in C#. From searching a bit, I ended up using a Graphics object from the Desktop HDC (null). Then, I painted normally using this Graphics object.

的问题是,当在屏幕的任何部分被重绘我的形状迷路。我尝试了While循环,但它实际上结束了快速绘制的CAN应用,这不是桌面的更新速率。

The problem is that my shapes get lost when any part of the screen is redrawn. I tried a While loop, but it actually ends up drawing as fast as the application can, which is not the update rate of the desktop.

通常情况下,我需要把我的画code在一个的OnPaint事件,但这样的事情并没有为桌面存在。

Normally, I would need to put my drawing code in a "OnPaint" event, but such thing does not exist for the desktop.

我会怎么做呢?

举例code:的 http://stackoverflow.com/questions/1536141/how-to-draw-directly-on-the-windows-desktop-c

推荐答案

当你画到HDC(NULL)你画到屏幕上,在一个非管理的方式。正如您所发现的,只要Windows刷新屏幕的一部分,您的更改将被覆盖。

When you draw to HDC(NULL) you draw to the screen, in an unmanaged way. As you've discovered, as soon as windows refreshes that part of the screen, your changes are overwritten.

有几个选项,这取决于你想达到什么:

There are a couple of options, depending upon what you want to achieve:


  1. 创建一个无国界的,可能
    非矩形窗口。 (使用
    的SetWindowRgn使一个窗口
    非矩形)。您可以让这个桌面窗口的子窗口。

  2. 子类桌面窗口。这并不简单,涉及
    注入DLL到
    Explorer.exe进程。

这篇关于如何有效地借鉴C#桌面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆