Вывод графики на экран, поверх всех окон. - C#
Формулировка задачи:
Здравствуйте!
Интерисует такой вопрос, как можно выводить графику на экран, не в область окна приложения, а поверх всего. К примеру, как нарисовать линию или вывести изображение. Заранее спасибо.
Решение задачи: «Вывод графики на экран, поверх всех окон.»
textual
Листинг программы
[DllImport("user32.dll")]
static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
[DllImport("user32.dll", SetLastError = true)]
static extern int GetWindowLong(IntPtr hWnd, int nIndex);
private const int ExStyle = -20;
private const int Transparent = 0x20;
private const int Layered = 0x80000;
private int initialStyle;
public Form1()
{
InitializeComponent();
initialStyle = GetWindowLong(Handle, ExStyle);
TransparencyKey = BackColor;
SetWindowLong(Handle, ExStyle, initialStyle | Layered | Transparent);
StartPosition = FormStartPosition.CenterScreen;
TopMost = true;
ShowIcon = false;
ShowInTaskbar = false;
}
protected override void OnPaint(PaintEventArgs e)
{
Font f = new Font("Microsoft Sans Serif", 30f);
e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
;
e.Graphics.DrawString("HELLO WORLD!", f, new SolidBrush(Color.Red), new PointF(0, 0) );
}
const int WM_NCHITTEST = 0x0084;
const int HTTRANSPARENT = -1;
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_NCHITTEST)
{
m.Result = (IntPtr)HTTRANSPARENT;
return;
}
base.WndProc(ref m);
}