Auf Desktop zeichnen

Sumpfkrautjunkie

Grünschnabel
Hi,
Ich habe ein Problem bein Zeichnen auf den Desktop:
Ich habe das Zeichnen nach unzähligen Versuchen einigermaßen über:
Code:
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;
using System.Drawing.Imaging;


namespace TastaturVisualizer
{

   

    public partial class Form1 : Form
    {
        
        public Form1()
        {
            InitializeComponent();
            
            this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true);
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            
        }

        private void timer1_Tick(object sender, EventArgs e)
        {

            IntPtr deskDC = User32.GetDC(IntPtr.Zero);
            
            Graphics g = Graphics.FromHdc(deskDC);
           
            Pen p = new Pen(Color.FromArgb(100, 0, 0), 10);
            g.DrawLine(p, 5, 5, 300, 300);
            User32.InvalidateRect(IntPtr.Zero, IntPtr.Zero, false);
            g.Dispose();

            User32.ReleaseDC(0, deskDC);
           
        }

        
    }

               

                   
                
 #region User32
    internal class User32
    {

        [DllImport("user32")]
        internal static extern IntPtr GetDC(IntPtr hwnd);
       

        [DllImport("User32.dll")]
        internal static extern void ReleaseDC(int hwnd, IntPtr hdc);
        [DllImport("user32.dll")]
        internal static extern bool InvalidateRect(IntPtr hWnd, IntPtr lpRect, bool bErase);

    }
    #endregion
}

realisiert, allerdings flackert der Bildschirm dadurch unerträglich.
Ich habe schon nach Doublebuffering-Methoden gesucht, doch sie waren alle auf Fensterbetrieb ausgelegt und ich konnte das Prinzip nicht so recht auf den ganzen Bildschirm anwenden.

Kann mir da jemand mit dem Flackerproblem helfen?
Und gibt es eventuell eine einfachere Methode auf den Bildschirm zu zeichnen?
Wichtig ist mir dabei eigentlich nur, dass das Gezeichnete das Anklicken der Elemente im Hintergrund nicht verhindert (da dürften also transparente Fenster, in denen gezeichnet wird wegfallen)



EDIT: Problem gelöst: Man kann die Fenster doch als durchklickbar einstellen:
Code:
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;
using System.Drawing.Imaging;


namespace TastaturVisualizer
{



    public partial class Form1 : Form
    {
        [DllImport("user32.dll", SetLastError = true)]
        static extern int GetWindowLong(IntPtr hWnd, int nIndex);
        [DllImport("user32.dll", SetLastError = true)]
        static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);

        private const int GWL_EXSTYLE = -20;
        private const int WS_EX_TRANSPARENT = 0x20;
        public Form1()
        {
            InitializeComponent();

            this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true);
        }
        

        private void Form1_Load(object sender, EventArgs e)
        {

            int exstyle = GetWindowLong(this.Handle, GWL_EXSTYLE);
            exstyle |= WS_EX_TRANSPARENT;
            SetWindowLong(this.Handle, GWL_EXSTYLE, exstyle);
        }

        


    }



}
 
Zuletzt bearbeitet:

Neue Beiträge

Zurück