uses
Windows;
폼, 패널 등의 마우스 다운 이벤트에서 사용에 맞게 처리합니다.
//폼 이동
ReleaseCapture;
PostMessage(Self.Handle, WM_SYSCOMMAND, $f012, 0);
//폼 사이즈 조절1
ReleaseCapture;
SendMessage(Self.Handle, WM_NCLBUTTONDOWN, ???, 0);
???
HTLEFT -> 왼쪽 크기 조절
HTRIGHT -> 오른쪽 크기 조절
HTBOTTOM -> 아래쪽 크기 조절
HTTOP -> 위쪽 크기 조절
HTTOPLEFT -> 좌상단 모서리 크기 조절
HTBOTTOMLEFT -> 좌하단 모서리 크기 조절
HTTOPRIGHT -> 우상단 모서리 크기 조절
HTBOTTOMRIGHT -> 우하단 모서리 크기 조절
마우스의 위치에 따른 메시지를 가로채서 사용하는 방법입니다.
//폼 사이즈 조절2
type
TForm1 = Class(TForm)
..
public
..
procedure WMNCHITTEST(var msg: TMessage); message WM_NCHITTEST;
end;
procedure TForm1.WMNCHITTEST(var msg: TMessage);
var
MousePos: TPoint;
const
BorderWidth = 4;
begin
MousePos := Point(msg.LParam and $FFFF, (msg.LParam shr 16) and $FFFF);
MousePos := Self.ScreenToClient(MousePos);
if (MousePos.X <= BorderWidth) then msg.Result := HTLEFT;
if (Width - BorderWidth <= MousePos.X) then msg.Result := HTRIGHT;
if (Height - BorderWidth <= MousePos.Y) then msg.Result := HTBOTTOM;
if (MousePos.Y <= BorderWidth) then msg.Result := HTTOP;
if ((MousePos.X <= BorderWidth) and
(MousePos.Y <= BorderWidth)) then msg.Result := HTTOPLEFT;
if ((MousePos.X <= BorderWidth) and
(Height - BorderWidth <= MousePos.BorderWidth)) then msg.Result := HTBOTTOMLEFT;
if ((Width - BorderWidth <= MousePos.X) and
(MousePos.Y <= BorderWidth)) then msg.Result := HTTOPRIGHT;
if ((Width - BorderWidth <= MousePos.X) and
(Height - BorderWidth <= MousePos.Y)) then msg.Result := HTBOTTOMRIGHT;
end;