用Delphi實現
首先,建立一個應用程序,在一個窗體裡加入一個Panel1,保存為main.pas;
然後,分別在Panel1的鼠標移動、鼠標按下事件裡添加代碼;
鼠標移動:控制光標的形狀
procedure TForm1.Panel1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if (x>=0)and(x<=3) then
begin
if (y>=0)and(y<=3) then Panel1.Cursor:=crSizeNWSE;
if (y>3)and(y<Panel1.Height-3) then Panel1.Cursor:=crSizeWE;
if (y>=Panel1.Height-3)and(y<=Panel1.Height) then Panel1.Cursor:=crSizeNESW;
end
else if (x>3)and(x<Panel1.Width-3) then
begin
if (y>=0)and(y<=3) then Panel1.Cursor:=crSizeNS;
if (y>3)and(y<Panel1.Height-3) then Panel1.Cursor:=crArrow;
if (y>=Panel1.Height-3)and(y<=Panel1.Width) then Panel1.Cursor:=crSizeNS;
end
else if (x>=Panel1.Width-3)and(x<=Panel1.Width) then
begin
if (y>=0)and(y<=3) then Panel1.Cursor:=crSizeNESW;
if (y>3)and(y<Panel1.Height-3) then Panel1.Cursor:=crSizeWE;
if (y>=Panel1.Height-3)and(y<=Panel1.Width) then Panel1.Cursor:=crSizeNWSE;
end;
end;
鼠標按下:控制Panel的大小或位置
procedure TForm1.Panel1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
ReleaseCapture;
if (x>=0)and(x<=3) then
begin
file://左上角方向改變大小
if (y>=0)and(y<=3) then Panel1.Perform(WM_SysCommand,$F004,0);
file://左側
if (y>3)and(y<Panel1.Height-3) then Panel1.Perform(WM_SysCommand,$F001,0);
file://左下角
if (y>=Panel1.Height-3)and(y<=Panel1.Height) then Panel1.Perform(WM_SysCommand,$F007,0);
end
else if (x>3)and(x<Panel1.Width-3) then
begin
file://上側
if (y>=0)and(y<=3) then Panel1.Perform(WM_SysCommand,$F003,0);
file://移動控件
if (y>3)and(y<Panel1.Height-3) then Panel1.Perform(WM_SysCommand,$F012,0);
file://下側
if (y>=Panel1.Height-3)and(y<=Panel1.Width) then Panel1.Perform(WM_SysCommand,$F006,0);
end
else if (x>=Panel1.Width-3)and(x<=Panel1.Width) then
begin
file://右上角
if (y>=0)and(y<=3) then Panel1.Perform(WM_SysCommand,$F005,0);
file://右側
if (y>3)and(y<Panel1.Height-3) then Panel1.Perform(WM_SysCommand,$F002,0);
file://右下角
if (y>=Panel1.Height-3)and(y<=Panel1.Width) then Panel1.Perform(WM_SysCommand,$F008,0);
end;
end;
主要使用 Perform 方法為
附錄1.全部代碼如下:
unit main;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Panel1: TPanel;
procedure Panel1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Panel1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Panel1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
ReleaseCapture;
if (x>=0)and(x<=3) then
begin
if (y>=0)and(y<=3) then Panel1.Perform(WM_SysCommand,$F004,0);
if (y>3)and(y<Panel1.Height-3) then Panel1.Perform(WM_SysCommand,$F001,0);
if (y>=Panel1.Height-3)and(y<=Panel1.Height) then Panel1.Perform(WM_SysCommand,$F007,0);
end
else if (x>3)and(x<Panel1.Width-3) then
begin
if (y>=0)and(y<=3) then Panel1.Perform(WM_SysCommand,$F003,0);
if (y>3)and(y<Panel1.Height-3) then Panel1.Perform(WM_SysCommand,$F012,0);
if (y>=Panel1.Height-3)and(y<=Panel1.Width) then Panel1.Perform(WM_SysCommand,$F006,0);
end
else if (x>=Panel1.Width-3)and(x<=Panel1.Width) then
begin
if (y>=0)and(y<=3) then Panel1.Perform(WM_SysCommand,$F005,0);
if (y>3)and(y<Panel1.Height-3) then Panel1.Perform(WM_SysCommand,$F002,0);
if (y>=Panel1.Height-3)and(y<=Panel1.Width) then Panel1.Perform(WM_SysCommand,$F008,0);
end;
end;
procedure TForm1.Panel1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if (x>=0)and(x<=3) then
begin
if (y>=0)and(y<=3) then Panel1.Cursor:=crSizeNWSE;
if (y>3)and(y<Panel1.Height-3) then Panel1.Cursor:=crSizeWE;
if (y>=Panel1.Height-3)and(y<=Panel1.Height) then Panel1.Cursor:=crSizeNESW;
end
else if (x>3)and(x<Panel1.Width-3) then
begin
if (y>=0)and(y<=3) then Panel1.Cursor:=crSizeNS;
if (y>3)and(y<Panel1.Height-3) then Panel1.Cursor:=crArrow;
if (y>=Panel1.Height-3)and(y<=Panel1.Width) then Panel1.Cursor:=crSizeNS;
end
else if (x>=Panel1.Width-3)and(x<=Panel1.Width) then
begin
if (y>=0)and(y<=3) then Panel1.Cursor:=crSizeNESW;
if (y>3)and(y<Panel1.Height-3) then Panel1.Cursor:=crSizeWE;
if (y>=Panel1.Height-3)and(y<=Panel1.Width) then Panel1.Cursor:=crSizeNWSE;
end;
end;
附錄2.API SendMessage()介紹
SendMessage === user32.lib
LRESULT SendMessage(
HWND hWnd, // handle of destination window
UINT Msg, // message to send
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);