Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How do I catch all WM_PAINT message from all control

Posted on 2007-11-30
1
Medium Priority
?
4,308 Views
Last Modified: 2008-02-01
Hi Experts,

I got stuck when trying implementing a method to catch WM_PAINT message from all control. When I run my apps, the UI seems freeze.
Does anything wrong with my code ?
public partial class frmMain : Form
{
        CustomFilter c = new CustomFilter();
 
        #region Form Method
        public frmMain()
        {
            InitializeComponent();
        }
        private void frmMain_Load(object sender, EventArgs e)
        {
            Application.AddMessageFilter(c);          
 
            c.Redraw += new AllControlRedraw(RedrawLine);
        }
 
        void RedrawLine()
        {
            IntPtr handle = Win32Helper.GetDesktopWindow();
            IntPtr hDc = Win32Helper.GetWindowDC(handle);
 
            Graphics g = Graphics.FromHdc(hDc);
            Pen p = new Pen(Color.Red, 2);
 
            Point[] StartLine = new Point[] { new Point(40, 10) };
            Point[] EndLine = new Point[] { new Point(40, 200) };
 
            for (int i = 0; i < StartLine.Length; i++)
                g.DrawLine(p, this.PointToScreen(StartLine[i]), this.PointToScreen(EndLine[i]));
 
            g.Dispose();
            Win32Helper.ReleaseDC(handle, hDc);
        }
}
 
    public delegate void AllControlRedraw(object sender, System.EventArgs e);
 
    class CustomFilter : System.Windows.Forms.IMessageFilter
    {
        private const int WM_PAINT = 0x000F;
        public event AllControlRedraw Redraw;
 
        #region IMessageFilter Members
 
        public bool PreFilterMessage(ref System.Windows.Forms.Message m)
        {
            AllControlRedraw t = Redraw;
            if (t != null)
            {
                switch (m.Msg)
                {
                    case WM_PAINT:
                        t(this, new EventArgs());
                        break;
                }
            }
 
            return true;
        }
 
        #endregion
 
        
    }

Open in new window

0
Comment
Question by:Aryo1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 3

Accepted Solution

by:
wizrr earned 2000 total points
ID: 20386150
Ofcourse

http://msdn2.microsoft.com/en-us/library/system.windows.forms.imessagefilter.prefiltermessage.aspx

Retuen value:
true to filter the message and stop it from being dispatched; false to allow the message to continue to the next filter or control.

You should return false.

Anyway your drawing code will be replaced with control's drawing code. Maybe you should subclass all windows in your app? (i think this is crazy idea)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

663 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question