{
You can perform communication between your application using Windows messages
exchange mechanism. We can use HWND_BROADCAST value for first parameter for
SendMessage function for suppressing finding of forms" in other applications HANDLE.
For using HWND_BROADCAST we should register our messages in Windows.
In example below we will inform about our form"s top position)
Das Beispiel zeigt, wie zwischen zwei Applikationen eine Meldung (Message)
verschickt werden kann. Die Meldung mit wird mit SendMessage verschickt.
Der erst Parameter ist HWND_BROADCAST, beim zweite ist unsere Message.
Das untenstehende Beispiel informiert z.B uber die Top-Position unserer Form}// 1. Define type of your message structure, it could be something like this: // 1. Definiere eine eigene Message Struktur: type
TWMMYMessage = record
Msg: Cardinal; // ( first is the message ID )
Handle: HWND; // ( this is the wParam, Handle of sender)
Info: Longint; // ( this is lParam, pointer to our data)
Result: Longint;
end;
// 2. Override your form""s DefaultHandler method and add // method for handling your message, like this // 2. Die DefaultHandler Methode zu uberschreiben
TForm1 = class(TForm)
...public{ Public declarations }
...procedure DefaultHandler(varMessage); override;
procedure WMMYMessage(var Msg: TWMMYMessage);
...end;
// 3. Declare message variable: // 3. Die Message-Variablen deklarieren: var
WM_OURMESSAGE: DWORD;
// 4. Insert realisation of DefaultHandler and our message handler methods: // 4. DefaultHandler Implementation: procedure TForm1.DefaultHandler(varMessage);
var
ee: TWMMYMessage;
beginwith TMessage(Message) dobeginif (Msg = WM_OURMESSAGE) thenbegin
ee.Msg := Msg;
ee.Handle := wParam;
ee.Info := lParam;
// Checking if this message is not from us if ee.Handle <> Handle then
WMMYMessage(ee);
endelseinherited DefaultHandler(Message);
end;
end;
procedure TForm1.WMMYMessage(var Msg: TWMMYMessage);
begin
label1.Caption := Format("Our another form handle :%d", [Msg.Handle]);
Label2.Caption := Format("Our another form top :%d", [Msg.Info]);
end;
// 5. Add registration of your message that you could // handle the HWND_BROADCAST messages: // 5. Die Message registrieren. initialization
WM_OURMESSAGE := RegisterWindowMessage("Our broadcast message");
// 6. Add the message sending somewhere: procedure TForm1.Button1Click(Sender: TObject);
begin
SendMessage(HWND_BROADCAST, WM_OURMESSAGE, Handle, Top);
end;
Если Вас заинтересовала или понравилась информация по разработке на Delph - "Связь между приложениями", Вы можете поставить закладку в социальной сети или в своём блоге на данную страницу: Так же Вы можете задать вопрос по работе этого модуля или примера через форму обратной связи, в сообщение обязательно указывайте название или ссылку на статью!