.
In Depth Banner
Skip Navigation Links

Select your preferred language

The WndProc override.

To facilitate the recognition of messages the WM_xxxxx definitions from WINUSER.H were required. The enumerations below shows the definitions required. The list has been shortened for brevity but the code page includes the full window message list.

  #region Windows Message Definitions converted from WinUser.h

  public enum WMDefs

  {

    WM_DRAWITEM           =0x002B,

    WM_REFLECT            =0x2000,

    WM_NOTIFY             =0x004e

  }

  #endregion

 

  #region Header Notification Definitions

  public enum HDNDefs

  {

    HDN_FIRST               =-300,

    HDN_ENDTRACKA           =(HDN_FIRST-7),

    HDN_ENDTRACKW           =(HDN_FIRST-27),

  }

  #endregion

 

  protected override void WndProc(ref Message m)

  {

    switch(m.Msg)

    {

      case (int)(WMDefs.WM_NOTIFY):

        NMHDR hdr=(NMHDR)m.GetLParam(typeof(NMHDR));

        if(hdr.code==(int)HDNDefs.HDN_ENDTRACKA || hdr.code==(int)HDNDefs.HDN_ENDTRACKW)

          AutoSizeLastColumn();

        base.WndProc(ref m);

        break;

      case (int)(WMDefs.WM_REFLECT | WMDefs.WM_DRAWITEM):

        ProcessDrawItem(ref m);

        break;

      default:

        base.WndProc (ref m);

        break;

    }

  }

 

The WndProc override simply detects the messages or hands control back to the base class WndProc implementation. ProcessDrawItem is the method we'll use to do custom drawing. AutoSizeLastColumn sets the width of the last column to -2 which forces it to resize to fill the width of the control

 

 

Return to the article.

Copyright © Bob Powell 2000-.  All rights reserved.