用setwindowrgn的函数创建的roundrect窗体如何自绘border?最好还能拉伸。(300分)

  • 主题发起人 主题发起人 shangshang
  • 开始时间 开始时间
S

shangshang

Unregistered / Unconfirmed
GUEST, unregistred user!
如题。 感谢lichengbin大侠。呵呵, 各大侠如有指点,有分奉上
 
type<br> &nbsp;TForm1 = class(TForm)<br> &nbsp; &nbsp;procedure FormCreate(Sender: TObject);<br> &nbsp; &nbsp;procedure FormPaint(Sender: TObject);<br> &nbsp; &nbsp;procedure FormResize(Sender: TObject);<br> &nbsp;private<br> &nbsp; &nbsp;{ Private declarations }<br> &nbsp; &nbsp;procedure WMNCHitTest(var Message: TWMNCHitTest); message WM_NCHITTEST;<br> &nbsp;protected<br> &nbsp; &nbsp;procedure CreateParams(var Params: TCreateParams); override; &nbsp;<br> &nbsp;public<br> &nbsp; &nbsp;{ Public declarations }<br> &nbsp;end;<br><br>procedure TForm1.CreateParams(var Params: TCreateParams);<br>begin<br> &nbsp;inherited CreateParams(Params);<br> &nbsp;Params.Style := WS_POPUP or WS_SIZEBOX;<br>end;<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>var<br> &nbsp;hr: HRGN;<br>begin<br> &nbsp;hr := CreateRoundRectRgn(0, 0, Width, Height, 20, 20);<br> &nbsp;SetWindowRgn(Handle, hr, True);<br> &nbsp;DeleteObject(hr);<br>end;<br><br>procedure TForm1.FormPaint(Sender: TObject);<br>var<br> &nbsp;C: TCanvas;<br>begin<br> &nbsp;C := TControlCanvas.Create;<br> &nbsp;try<br> &nbsp; &nbsp;C.Handle := GetWindowDC(Handle);<br> &nbsp; &nbsp;C.Brush.Style := bsClear;<br> &nbsp; &nbsp;C.Pen.Color := clBlue;<br> &nbsp; &nbsp;C.Pen.Width := 3;<br> &nbsp; &nbsp;C.RoundRect(1, 1, Width-2, Height-2, 20, 20);<br> &nbsp;finally<br> &nbsp; &nbsp;C.Free; // TControlCanvas.FreeHandle会ReleaseDC<br> &nbsp;end;<br>end;<br><br>procedure TForm1.WMNCHitTest(var Message: TWMNCHitTest);<br>begin<br> &nbsp;inherited;<br> &nbsp;if Message.Result = HTCLIENT then Message.Result := HTCAPTION;<br>end;<br><br>procedure TForm1.FormResize(Sender: TObject);<br>var<br> &nbsp;hr: HRGN;<br>begin<br> &nbsp;hr := CreateRoundRectRgn(0, 0, Width, Height, 20, 20);<br> &nbsp;SetWindowRgn(Handle, hr, True);<br> &nbsp;DeleteObject(hr);<br> &nbsp;Invalidate;<br>end;
 
呵呵,老大是在偶窗体上画个border出来,这个思路也不错。偶只想着如何重载系统画border的方法呢。 正好又摸到用AdjustClientRect来调整窗口clientarea,呵呵,效果还不错。谢老大了。
 
后退
顶部