0

Message passing u svrsi otvaranja profila unutar jednog programa

Kako smo prošli put napravili asocijaciju fileova programu koji će otvarati i učitavati se u određenu aplikaciju, sada želimo da se svi ti profili učitaju u postojećem prozoru. Prvo treba odredititi initialization glavnog prozora (Delphi):

Privatne promenljive forme

mHandle: THandle;
PrevWindow : HWND;
S : string;
CData : TCopyDataStruct;

initialization
mHandle := CreateMutex(nil, true, 'MySimpleApp');
if (GetLastError = Error_Already_Exists) then
begin
PrevWindow:=FindWindow('TfrmMyForm', nil);
if IsWindow(PrevWindow) then
begin
SendMessage(PrevWindow, WM_SYSCOMMAND, SC_RESTORE, 0);
BringWindowToTop(PrevWindow);
SetForegroundWindow(PrevWindow);

if FileExists(ParamStr(1)) then
begin
S:=ParamStr(1);
CData.dwData:=0;
CData.lpData:=PChar(S);
CData.cbData:=1+Length(S);

SendMessage(PrevWindow, WM_COPYDATA, 0, DWORD(@CData) );
end;
end;
//   ShowMessage('          Already running!          ');
halt;
end;

 

Tako saljemo poruku. A potruka se prima u metodi:

procedure TfrmOnlineMonitor.ReceiveData_Handler(var msg: TWMCopyData);
begin
case MessageDlg('Do you want to save current profile:'+PChar(ProfilePath)+' before loading new profile: '+PChar(msg.CopyDataStruct.lpData), mtConfirmation, [mbYes,mbNo,mbCancel], 0) of
mrYes:
begin
SaveXML(PChar(ProfilePath));
LoadXML(PChar(msg.CopyDataStruct.lpData));
end;
mrNo:
LoadXML(PChar(msg.CopyDataStruct.lpData));
end;
end;

 

 

Nikola Milošević

Born in Bratislava, Slovakia, lived in Belgrade, Serbia, now living in Manchester, UK, and visitng the world. Nikola is a great enthusiast of AI, natural language processing, machine learning, web application security, open source, mobile and web technologies. Looking forward to create future. Nikola has done PhD in natural language processing and machine learning at the University of Manchester where he works at the moment.

Twitter LinkedIn Google+ YouTube Xing  

email
Liked it? Take a second to support Nikola Milošević on Patreon!

Leave a Reply

Your email address will not be published. Required fields are marked *