none
用MessageWindow类如何响应WM_PAINT消息? RRS feed

  • 问题

  • 代码如下,但是怎么都没法响应WM_PAINT消息,该如何才能响应WM_PAINT消息啊?我是从treeview继承的,想在WM_PAINT里重绘。

     

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Windows.Forms;
    using Microsoft.WindowsCE.Forms;
    using System.Drawing;

     

    namespace MyControls
    {
        public class MyControl : TreeView
        {
            Image image = null;

            private MsgWnd msgwnd;

     

             public MyControl ()
             {
                 msgwnd = new MsgWnd(this);

             }

            public void setBackGround(Image bk)
            {
                image = bk;
                this.Invalidate();
            }


            public class MsgWnd : MessageWindow
            {
                private MyControl parent;

                public MsgWnd(MyControl myControl )
                {
                    parent = myControl ;
                }

                protected override void WndProc(ref Message message)
                {
                    const int WM_PAINT = 0x000F;
                    const int WM_PRINTCLIENT = 0x0318;
                    const int WM_ERASEBKGND = 0x0014;

                    switch (message.Msg)
                    {

                        case WM_ERASEBKGND:
                            return;

                        case WM_PAINT:
                           处理代码

                            return;
                    }
                    base.WndProc(ref message);
                }
            }
         
        }
    }

    2008年4月18日 9:26

答案