Solved

How do I catch all WM_PAINT message from all control

Posted on 2007-11-30
1
4,274 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 500 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASP.NET data base connection 35 81
Can Selenium do Load Testing? 2 56
Removing Version of .NET in Windows 10 17 106
How do you think this website does searches? 5 30
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

736 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