核心提示:方法一: 通过SelectObject来实现 procedureInvertTracker(hwndDest:HWND); //画边框 var hdcDest:HWND; hPen:HWND; hOl...
方法一: 通过 SelectObject 来实现
procedure InvertTracker(hwndDest: HWND);
//画边框
var
hdcDest : HWND;
hPen : HWND;
hOldPen : HWND;
hOldBrush : HWND;
cr : HWND;
rc : TRect;
begin
GetWindowRect(hwndDest, rc);
hdcDest := GetWindowDC(hwndDest);
SetROP2(hdcDest,R2_NOT);
cr := clBlack;
hPen := CreatePen(PS_INSIDEFRAME,2,cr);
hOldPen := SelectObject(hdcDest, hPen);
hOldBrush := SelectObject(hdcDest, GetStockObject(NULL_BRUSH));
Rectangle(hdcDest, 0, 0, rc.Right - rc.Left, rc.Bottom - rc.Top);
SelectObject(hdcDest, hOldBrush);
SelectObject(hdcDest, hOldPen);
ReleaseDC(hwndDest, hdcDest);
DeleteObject(hPen);
end;
方法二:
将边框区域颜色取反
procedure HighlightWindow(hWndWindow: HWND);
var hDCWindow: HDC;
RECT: TRect;
DINV: Integer;
begin
if (hWndWindow = 0) or (Not IsWindow(hWndWindow)) then
Exit
else begin
hDCWindow := GetWindowDC(hWndWindow);
Windows.GetWindowRect(hWndWindow, RECT);
OffsetRect(RECT, -RECT.Left,-RECT.Top);
DINV := 4;
if Not IsRectEmpty(RECT) then
begin
PatBlt(hDCWindow, RECT.Left, RECT.Top, RECT.Right - RECT.Left, DINV, DSTINVERT);
PatBlt(hDCWindow, RECT.left, RECT.bottom - DINV, DINV,
-(RECT.bottom - RECT.top - 2 * DINV), DSTINVERT);
PatBlt(hDCWindow, RECT.right - DINV, RECT.top + DINV, DINV,
RECT.bottom - RECT.top - 2 * DINV, DSTINVERT);
PatBlt(hDCWindow, RECT.right, RECT.bottom - DINV, -(RECT.right - RECT.left),
DINV, DSTINVERT);
end;
ReleaseDC(hWndWindow, hDCWindow);
end;
end;
不过这两个都无法实现异型窗体的高亮