SetWindowLongA
CallWindowProc
这俩个API写法应该如何 满足需要 代码贴上
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
trec=record
x: integer;
y: integer;
end;
hanshu=record
jubing:Integer;
yuanhanshu:Integer;
end;
type
TForm1 = class(TForm)
Panel1: TPanel;
Panel2: TPanel;
Panel3: TPanel;
Panel4: TPanel;
Panel5: TPanel;
Button1: TButton;
procedure sibian(hwnd:Integer);
procedure Button1Click(Sender: TObject);
function xinhanshu(jubing,xiaoxi,canshu1,canshu2:Integer):Integer;
procedure huasibian(hwnd:Integer);
private
hanshu1:hanshu;
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
sibian(Button1.Handle);
hanshu1.yuanhanshu:=SetWindowLongA(Button1.Handle,-4,Integer(@xinhanshu));
hanshu1.jubing:=Button1.Handle;
end;procedure TForm1.huasibian(hwnd: Integer);
var
hDC,hPen,nWidth,nHeight,hBrush:Integer;
rect2:TRect;
PAINTSTRUCT:TPAINTSTRUCT;
TrPoint:array [1..4] of trec;
begin
GetWindowRect (hwnd, rect2);
nWidth:=rect2.Right-rect2.Left;
nHeight:=rect2.Bottom-rect2.Top;
hdc:=GetDC(hwnd);
hpen:=createpen(2,1,0);
SelectObject (hDC, hPen);
hBrush:=GetStockObject (5);
SelectObject (hDC, hBrush);
SetBkMode (hDC, 1);
TrPoint[1].x:=nHeight div 2 +2;
TrPoint[1].y:=2;
TrPoint[2].x:=nWidth-4;
TrPoint[2].y:=2;
TrPoint[3].x:=nWidth-nHeight div 2 -2;
TrPoint[3].y:=nHeight-4;
TrPoint[4].x:=4;
TrPoint[4].y:=nHeight-4;
Polygon (hDC, TrPoint, 4);
DeleteObject (hPen);
DeleteObject (hBrush);
ReleaseDC (hwnd, hDC);
end;procedure TForm1.sibian(hwnd: Integer);
var
hggn:THandle;
nWidth,nHeight:Integer;
Rcet2:TRect;
TrPoint:array [1..4] of trec;
begin
GetWindowRect(hwnd,Rcet2);
nWidth:=Rcet2.Right-Rcet2.Left;
TrPoint[1].x:=nHeight div 2;
TrPoint[1].y:=0;
TrPoint[2].x:=nWidth;
TrPoint[2].y:=0;
TrPoint[3].x:=nWidth-nHeight div 2;
TrPoint[3].y:=nHeight;
TrPoint[4].x:=0;
TrPoint[4].y:=nHeight;
hggn := CreatePolygonRgn(TrPoint,4,ALTERNATE);
SetWindowRgn(hwnd,hggn,TRUE);
DeleteObject(hggn);
end;function TForm1.xinhanshu(jubing, xiaoxi, canshu1, canshu2: Integer): Integer;
begin
if xiaoxi=WM_SETFOCUS then Result:=1;
if jubing=GetFocus() then
begin
huasibian(jubing);
Result:=CallWindowProc(hanshu1.yuanhanshu,jubing,xiaoxi,canshu1,canshu2);
end;
end;end.
CallWindowProc
这俩个API写法应该如何 满足需要 代码贴上
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
trec=record
x: integer;
y: integer;
end;
hanshu=record
jubing:Integer;
yuanhanshu:Integer;
end;
type
TForm1 = class(TForm)
Panel1: TPanel;
Panel2: TPanel;
Panel3: TPanel;
Panel4: TPanel;
Panel5: TPanel;
Button1: TButton;
procedure sibian(hwnd:Integer);
procedure Button1Click(Sender: TObject);
function xinhanshu(jubing,xiaoxi,canshu1,canshu2:Integer):Integer;
procedure huasibian(hwnd:Integer);
private
hanshu1:hanshu;
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
sibian(Button1.Handle);
hanshu1.yuanhanshu:=SetWindowLongA(Button1.Handle,-4,Integer(@xinhanshu));
hanshu1.jubing:=Button1.Handle;
end;procedure TForm1.huasibian(hwnd: Integer);
var
hDC,hPen,nWidth,nHeight,hBrush:Integer;
rect2:TRect;
PAINTSTRUCT:TPAINTSTRUCT;
TrPoint:array [1..4] of trec;
begin
GetWindowRect (hwnd, rect2);
nWidth:=rect2.Right-rect2.Left;
nHeight:=rect2.Bottom-rect2.Top;
hdc:=GetDC(hwnd);
hpen:=createpen(2,1,0);
SelectObject (hDC, hPen);
hBrush:=GetStockObject (5);
SelectObject (hDC, hBrush);
SetBkMode (hDC, 1);
TrPoint[1].x:=nHeight div 2 +2;
TrPoint[1].y:=2;
TrPoint[2].x:=nWidth-4;
TrPoint[2].y:=2;
TrPoint[3].x:=nWidth-nHeight div 2 -2;
TrPoint[3].y:=nHeight-4;
TrPoint[4].x:=4;
TrPoint[4].y:=nHeight-4;
Polygon (hDC, TrPoint, 4);
DeleteObject (hPen);
DeleteObject (hBrush);
ReleaseDC (hwnd, hDC);
end;procedure TForm1.sibian(hwnd: Integer);
var
hggn:THandle;
nWidth,nHeight:Integer;
Rcet2:TRect;
TrPoint:array [1..4] of trec;
begin
GetWindowRect(hwnd,Rcet2);
nWidth:=Rcet2.Right-Rcet2.Left;
TrPoint[1].x:=nHeight div 2;
TrPoint[1].y:=0;
TrPoint[2].x:=nWidth;
TrPoint[2].y:=0;
TrPoint[3].x:=nWidth-nHeight div 2;
TrPoint[3].y:=nHeight;
TrPoint[4].x:=0;
TrPoint[4].y:=nHeight;
hggn := CreatePolygonRgn(TrPoint,4,ALTERNATE);
SetWindowRgn(hwnd,hggn,TRUE);
DeleteObject(hggn);
end;function TForm1.xinhanshu(jubing, xiaoxi, canshu1, canshu2: Integer): Integer;
begin
if xiaoxi=WM_SETFOCUS then Result:=1;
if jubing=GetFocus() then
begin
huasibian(jubing);
Result:=CallWindowProc(hanshu1.yuanhanshu,jubing,xiaoxi,canshu1,canshu2);
end;
end;end.
void __fastcall TForm1::WndProc(TMessage& msg)
{
TForm::WndProc(msg);
switch(msg.Msg) {
case WM_SIZING:
//你的代碼
break;
case xxx:
//......
//break;
//.......
default: break;
}
}適用於得到windows發給自己的消息,而不能接受任何消息,如果要想這樣,必須使用hook,msdn裡有詳細的原代碼,自己看吧
xinhanshu是个类的成员函数 且调用约定不是StdCall
一般 Api 回调函数的基本要求就是 调用 约定是 StdCall 且不能是成员函数
unit Unit6;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type trec=record
x: integer;
y: integer;
end; hanshu=record
jubing:Integer;
yuanhanshu:Integer;
end;
TForm1 = class(TForm)
button1: TButton;
procedure FormDestroy(Sender: TObject);
procedure FormCreate(Sender: TObject);
private procedure huasibian(hwnd: Integer);
procedure sibian(hwnd: Integer);
{ Private declarations }
public
{ Public declarations }
end; function xinhanshu(jubing, xiaoxi, canshu1, canshu2: Integer): Integer; stdcall;var
Form1: TForm1;
hanshu1:hanshu;
implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
begin
hanshu1.yuanhanshu:=SetWindowLongA(Button1.Handle,-4,Integer(@xinhanshu));
hanshu1.jubing:=Button1.Handle;
end;procedure TForm1.FormDestroy(Sender: TObject);
begin
if hanshu1.jubing <> 0 then
SetWindowLongA(Button1.Handle,-4,Integer(hanshu1.yuanhanshu));
end;procedure TForm1.huasibian(hwnd: Integer);
var
hDC,hPen,nWidth,nHeight,hBrush:Integer;
rect2:TRect;
PAINTSTRUCT:TPAINTSTRUCT;
TrPoint:array [1..4] of trec;
begin
GetWindowRect (hwnd, rect2);
nWidth:=rect2.Right-rect2.Left;
nHeight:=rect2.Bottom-rect2.Top;
hdc:=GetDC(hwnd);
hpen:=createpen(2,1,0);
SelectObject (hDC, hPen);
hBrush:=GetStockObject (5);
SelectObject (hDC, hBrush);
SetBkMode (hDC, 1);
TrPoint[1].x:=nHeight div 2 +2;
TrPoint[1].y:=2;
TrPoint[2].x:=nWidth-4;
TrPoint[2].y:=2;
TrPoint[3].x:=nWidth-nHeight div 2 -2;
TrPoint[3].y:=nHeight-4;
TrPoint[4].x:=4;
TrPoint[4].y:=nHeight-4;
Polygon (hDC, TrPoint, 4);
DeleteObject (hPen);
DeleteObject (hBrush);
ReleaseDC (hwnd, hDC);
end;procedure TForm1.sibian(hwnd: Integer);
var
hggn:THandle;
nWidth,nHeight:Integer;
Rcet2:TRect;
TrPoint:array [1..4] of trec;
begin
GetWindowRect(hwnd,Rcet2);
nWidth:=Rcet2.Right-Rcet2.Left;
TrPoint[1].x:=nHeight div 2;
TrPoint[1].y:=0;
TrPoint[2].x:=nWidth;
TrPoint[2].y:=0;
TrPoint[3].x:=nWidth-nHeight div 2;
TrPoint[3].y:=nHeight;
TrPoint[4].x:=0;
TrPoint[4].y:=nHeight;
hggn := CreatePolygonRgn(TrPoint,4,ALTERNATE);
SetWindowRgn(hwnd,hggn,TRUE);
DeleteObject(hggn);
end;function xinhanshu(jubing, xiaoxi, canshu1, canshu2: Integer): Integer;
begin
if xiaoxi=WM_SETFOCUS then Result:=1;
if jubing=GetFocus() then
begin
Form1.huasibian(jubing);
Result:=CallWindowProc(Pointer(hanshu1.yuanhanshu),jubing,xiaoxi,canshu1,canshu2);
end;
end;end.