type節に追加するコード | |
---|---|
1 2 3 4 5 6 7 |
type TPanel = class(StdCtrls.TPanel) private procedure WMEraseBkgnd(var Message: TWMEraseBkgnd); message WM_ERASEBKGND; procedure WMPaint(var Message: TWMPaint); message WM_PAINT; |
implementation節に追加するコード | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
procedure TPanel.WMEraseBkgnd(var Message: TWMEraseBkgnd); begin end; procedure TPanel.WMPaint(var Message: TWMPaint); var PS: TPaintStruct; w, h: Integer; DC: HDC; bmp, bmpOld: HBITMAP; i, Count, SaveDCIndex: Integer; begin if Message.DC <> 0 then inherited else begin BeginPaint(Handle, PS); try w := PS.rcPaint.Right - PS.rcPaint.Left; h := PS.rcPaint.Bottom - PS.rcPaint.Top; DC := GetDC(HWND(0)); bmp := CreateCompatibleBitmap(DC, w, h); ReleaseDC(HWND(0), DC); try Message.DC := CreateCompatibleDC(HDC(0)); with PS do try bmpOld := SelectObject(Message.DC, bmp); with rcPaint do SetWindowOrgEx(Message.DC, Left, Top, nil); FillRect(Message.DC, rcPaint, Brush.Handle); Count := ControlCount; for i := 0 to Count - 1 do begin if Controls[i] is TWinControl then break; with Controls[i] do begin if Visible and RectVisible(hdc, BoundsRect) then begin SaveDCIndex := SaveDC(Message.DC); OffsetWindowOrgEx(Message.DC, -Left, -Top, nil); IntersectClipRect(Message.DC, 0, 0, Width, Height); Perform(WM_PAINT, Message.DC, 0); RestoreDC(Message.DC, SaveDCIndex); end; end; end; BitBlt(hdc, rcPaint.Left, rcPaint.Top, w, h, Message.DC, rcPaint.Left, rcPaint.Top, SRCCOPY); SelectObject(Message.DC, bmpOld); finally DeleteDC(Message.DC); Message.DC := 0; end; finally DeleteObject(bmp); end; finally EndPaint(Handle, PS); end; end; end; |
TPanel.WMEraseBkgndに追加するコード | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
procedure TPanel.WMEraseBkgnd(var Message: TWMEraseBkgnd); var i, Count: Integer; begin Count := ControlCount - 1; for i := 0 to Count do begin if Controls[i] is TWinControl then if Controls[i].Visible then FillRect(Message.DC, TWinControl(Controls[i]).BoundsRect, TWinControl(Controls[i]).Brush.Handle); end; end; |