[原创]DIY自己的AllocateHWnd函数
Classes单元的AllocateHWnd函数是需要传入一个处理消息的类的方法的作为参数的,原型:
function AllocateHWnd(Method: TWndMethod): HWND;
type TWndMethod = procedure(var Message: TMessage) of object;
type TMyWndProc = procedure(AObject: TObject; var Message: TMessage);
function MyAllocateHWnd(Proc: TMyWndProc): HWND;asm push 0//AObject push Proc//Message call AllocateHWndend;
var H: HWND;procedure MyWndProc(AObject: TObject; var Message: TMessage);begin if Message.Msg = WM_USER + 111 then ShowMessage('') else Message.Result := DefWindowProc(H, Message.Msg, Message.WParam, Message.LParam)end;procedure TForm1.FormCreate(Sender: TObject);begin H := MyAllocateHWnd(MyWndProc)end;procedure TForm1.FormDestroy(Sender: TObject);begin DeallocateHWnd(H);end;procedure TForm1.Button1Click(Sender: TObject);begin SendMessage(H, WM_USER + 111, 0, 0)end;