20110518

[教學]DELPHI使用Windows Message簡易傳值

[教學]DELPHI使用Windows Message簡易傳值
[author] A.L.@20110518

[引用]
messages

[發送]
PostMessage(hWnd: HWND; Msg: UINT; wParam: WPARAM; lParam: LPARAM): BOOL;
SendMessage(hWnd: HWND; Msg: UINT; wParam: WPARAM; lParam: LPARAM): BOOL;
1.差異在於 PostMessage送後不理
2.wParam和lParam分別可簡單的送出兩個整數值

[接收]
1.定義 Msg接口:通常在上方定義常數值
2.可簡易接收兩個整數
3.也可以接收物件,那就需要更進一步的包裝了

[範例]
const
    WM_123= WM_USER+123
...
private
    procedure WM123(var Msg:Tmessage); message WM_123;
...
procedure TFormTest.Button1Click(Sender:TObject);
begin
    SendMessage(FindWindow('TFormTest',nil),WM_123,2,1);
end;

procedure TFormTest.WM123(var Msg:Tmessage);
begin
    showmessage(inttostr(Msg.WParam)+','+inttostr(Msg.WParam));
end;

//執行結果是按下按鈕後會彈跳訊息,內容為  2,1
#

0 意見:

張貼留言