在自己的网站发表文章感觉太孤独了,没有这么多的同行交流,最终还是决定回到cnblogs,不过毕竟在那里写了一些文章了,稍后把那里的文章都移植过来。
希望以后能够和大家多多交流,共同提高。
posted @ 2006-11-29 23:00 纶巾客 阅读(143) 评论(0) 编辑
2006年11月29日
protected override void WndProc(ref Message m)

{
switch (m.Msg)

{
case (int)WinAPI_WM.WM_NCCALCSIZE:
if (m.WParam.ToInt32() == 0)

{
WinAPI_RECT rc = (WinAPI_RECT)m.GetLParam(typeof(WinAPI_RECT));
rc.Left += 1;
rc.Top += 1;
rc.Right -= 1;
rc.Bottom -= 1;
Marshal.StructureToPtr(rc, m.LParam, true);
m.Result = IntPtr.Zero;
}
else

{
WinAPI_NCCALCSIZE_PARAMS csp;
csp = (WinAPI_NCCALCSIZE_PARAMS)m.GetLParam(typeof(WinAPI_NCCALCSIZE_PARAMS));
csp.rgrc0.Top += 1;
csp.rgrc0.Bottom -= 1;
csp.rgrc0.Left += 1;
csp.rgrc0.Right -= 1;
Marshal.StructureToPtr(csp, m.LParam, true);
//Return zero to preserve client rectangle
m.Result = IntPtr.Zero;
}
break;
case (int)WinAPI_WM.WM_NCPAINT:

{
m.WParam = NCPaint(m.WParam);
break;
}
}
base.WndProc(ref m);
}
public IntPtr NCPaint(IntPtr region)
{
IntPtr hDC = GetWindowDC(this.Handle);
if (hDC != IntPtr.Zero)

{
Graphics grTemp = Graphics.FromHdc(hDC);
int ScrollBarWidth = SystemInformation.VerticalScrollBarWidth;
int ScrollBarHeight = SystemInformation.HorizontalScrollBarHeight;
WINDOWINFO wi = new WINDOWINFO();
wi.cbSize = (uint)Marshal.SizeOf(wi);
//得到当前控件的窗口信息
GetWindowInfo(Handle, ref wi);
wi.rcClient.Right--;
wi.rcClient.Bottom--;

//获得当前控件的区域
Region UpdateRegion = new Region(new Rectangle(wi.rcWindow.Top,wi.rcWindow.Left,wi.rcWindow.Right-wi.rcWindow.Left,wi.rcWindow.Bottom-wi.rcWindow.Top));
//获得客户区以外的区域
UpdateRegion.Exclude(new Rectangle(wi.rcClient.Top, wi.rcClient.Left, wi.rcClient.Right - wi.rcClient.Left, wi.rcClient.Bottom - wi.rcClient.Top));
if (IsHScrollVisible && IsVScrollVisible)

{
UpdateRegion.Exclude(Rectangle.FromLTRB
(wi.rcClient.Right + 1, wi.rcClient.Bottom + 1,
wi.rcWindow.Right, wi.rcWindow.Bottom));
}
//得到当前区域的句柄
IntPtr hRgn = UpdateRegion.GetHrgn(grTemp);
//For Painting we need to zero offset the Rectangles.
Rectangle WindowRect = new Rectangle(wi.rcWindow.Top, wi.rcWindow.Left, wi.rcWindow.Right - wi.rcWindow.Left, wi.rcWindow.Bottom - wi.rcWindow.Top);
Point offset = Point.Empty - (Size)WindowRect.Location;
WindowRect.Offset(offset);
Rectangle ClientRect = WindowRect;
ClientRect.Inflate(-1, -1);
//Fill the BorderArea
Region PaintRegion = new Region(WindowRect);
PaintRegion.Exclude(ClientRect);
grTemp.FillRegion(SystemBrushes.Control, PaintRegion);
//Fill the Area between the scrollbars
if (IsHScrollVisible && IsVScrollVisible)

{
Rectangle ScrollRect = new Rectangle(ClientRect.Right - ScrollBarWidth,
ClientRect.Bottom - ScrollBarHeight, ScrollBarWidth + 2, ScrollBarHeight + 2);
ScrollRect.Offset(-1, -1);
grTemp.FillRectangle(SystemBrushes.Control, ScrollRect);
}
//Adjust ClientRect for Drawing Border.
ClientRect.Inflate(2, 2);
ClientRect.Width--;
ClientRect.Height--;
//Draw Outer Raised Border
ControlPaint.DrawBorder3D(grTemp, WindowRect, Border3DStyle.Raised,
Border3DSide.Bottom | Border3DSide.Left | Border3DSide.Right | Border3DSide.Top);
//Draw Inner Sunken Border
ControlPaint.DrawBorder3D(grTemp, ClientRect, Border3DStyle.Sunken,
Border3DSide.Bottom | Border3DSide.Left | Border3DSide.Right | Border3DSide.Top);
ReleaseDC(Handle, hDC);
grTemp.Dispose();
return hRgn;
}
RefreshScrollBar();
return region;
}