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, but he lived in Belgrade, Serbia. Now he is doing a PhD in natural language processing at the University of Manchester. Great enthusiast of AI, natural language processing, machine learning, web application security (founder of OWASP local chapter in Serbia, currently one of the leaders of OWASP Manchester chapter and OWASP Seraphimdroid project), open source, mobile and web technologies. Looking forward to create future. Nikola wants to teach machines to feel and understand. Always finding way for dreams to come true.

Twitter LinkedIn Google+ YouTube Xing  

email

Leave a Reply

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