Form의 BorderStyle로 제어할 수 없는 상황이 생겨, 윈도우 메시지를 사용했습니다.
type
TForm1 = class(TForm)
..
private
fFormResize: Boolean;
protected
procedure WMSysCommand(var Msg: TWMSysCommand); message WM_SYSCOMMAND;
procedure WMSetCursor(var Msg: TMessage); message WM_SETCURSOR;
end;
procedure TForm1.WMSetCursor(var Msg: TMessage);
function isBorder(AParam: Word): Boolean;
begin
Result := (AParam = HTTOP) or
(AParam = HTLEFT) or
(AParam = HTRIGHT) or
(AParam = HTBOTTOM);
end;
begin
//마우스가 Border에 있을 때, 마우스 포인터 강제 변경.
if not fFormResize and isBorder(Msg.LParamLo) then
WinApi.Windows.SetCursor(Screen.Cursors[crDefault])
else
DefaultHandler(Msg);
end;
procedure TForm1.WMSysCommand(var Msg: TWMSysCommand);
const
HIT_LEFT_BORDER = 61441;
HIT_RIGHT_BORDER = 61442;
HIT_TOP_BORDER = 61443;
// HIT_LEFTTOP_BORDER = 61444;
// HIT_RIGHTTOP_BORDER = 61445;
HIT_BOTTOM_BORDER = 61446;
// HIT_LEFTBOTTOM_BORDER = 61447;
// HIT_RIGHTBOTTOM_BORDER = 61448;
function HitBorder(ABorder: NativeUInt): Boolean;
begin
Result := (ABorder = HIT_TOP_BORDER) or
(ABorder = HIT_LEFT_BORDER) or
(ABorder = HIT_RIGHT_BORDER) or
(ABorder = HIT_BOTTOM_BORDER);
end;
begin
//마우스 포인터가 Border일 때, 마우스 커멘드 제거
if not fFormResize and HitBorder(Msg.CmdType) then
Msg.CmdType := 0;
DefaultHandler(Msg);
end;
반응형