{"id":277,"date":"2008-05-11T14:16:07","date_gmt":"2008-05-11T14:16:07","guid":{"rendered":"http:\/\/6teen.ru\/?p=223"},"modified":"2008-05-11T14:16:07","modified_gmt":"2008-05-11T14:16:07","slug":"2215","status":"publish","type":"post","link":"http:\/\/pblog.ru\/lab\/?p=277","title":{"rendered":"\u041a\u0430\u043a \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e\u0433\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043c\u043e\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f"},"content":{"rendered":"<p>\u041a\u0430\u043a \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e\u0433\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043c\u043e\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f<br \/>\n<!--more--><\/p>\n<pre class=\"alt2\" style=\"margin:0px; padding:6px; border:1px inset; width:580px; height:320px; overflow:auto\"><div>\u041a\u0430\u043a \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e\u0433\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043c\u043e\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\n\n=== \u0412\u0430\u0440\u0438\u0430\u043d\u0442 N 1 ===\n\ntype\n  TForm1 = class(TForm)\n    Memo1: TMemo;\n    procedure FormCreate(Sender: TObject);\n  private\n    { Private declarations }\n    procedure WMCopyData(var msg: TMessage); message WM_COPYDATA;\n  public\n    { Public declarations }\n  end;\n\nvar\n  Form1: TForm1;\n\nimplementation\n\n{$R *.DFM}\n\nuses\n  checkinst;\n\nprocedure TForm1.FormCreate(Sender: TObject);\nvar\n  h : HWND;\nbegin\n  h := SetUniqueUID(Handle, 123456); \/\/ \u043d\u0430\u0437\u043d\u0430\u0447\u0430\u0435\u043c \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\n  if h <> Handle then\n    begin\n      SendString(h, GetCommandLineStr, Handle, 0);\n      ActivatePrevInstance(h);\n      Halt;\n    end;\nend;\n\nprocedure TForm1.WMCopyData;\nbegin\n   Memo1.Lines.CommaText := PChar(PCopyDataStruct(msg.LParam).lpData);\nend;\n\n--------------------------checkinst.pas-------------------------\nunit checkinst;\n\ninterface\n\nuses\n  Windows,\n  Messages,\n  Sysutils;\n\nfunction SetUniqueUID(ahwnd: HWND; uid: DWord): HWND;\nprocedure ActivatePrevInstance(ahwnd: HWND);\nprocedure SendString(ahwnd:HWND; const s: String; aWParam: WParam;\ndwData:DWord);\nfunction GetCommandLineStr: String;\n\nimplementation\n\nfunction SetUniqueUID(ahwnd: HWND; uid: DWord): HWND;\nvar\n  ClassName: array [0..255] of Char;\nbegin\n  GetClassName(ahwnd, ClassName, SizeOf(classname));\n  Result := FindWindowEx(0, 0, ClassName, nil);\n  while (Result <> 0) do\n    if GetProp(Result, 'UID') = uid then\n      Exit\n    else\n      Result := FindWindowEx(0, Result, ClassName, nil);\n  SetProp(ahwnd, 'UID', uid);\n  Result := ahwnd;\nend;\n\nprocedure ActivatePrevInstance(ahwnd: HWND);\nvar\n  h : HWND;\nbegin\n  h := GetWindowLong(ahwnd, GWL_HWNDPARENT);\n  if IsIconic(h) then\n     ShowWindow(h, SW_RESTORE);\n  SetForegroundWindow(h);\nend;\n\nprocedure SendString(ahwnd:HWND; const s: String; aWParam: WParam;\ndwData:DWord);\nvar\n  cds: TCopyDataStruct;\nbegin\n  cds.cbData := Length(s)+1;\n  cds.lpData := Pointer(s);\n  cds.dwData := dwData;\n  SendMessage(ahwnd, WM_COPYDATA, aWParam, LParam(@cds));\nend;\n\nfunction GetCommandLineStr: String;\nvar\n  i : Integer;\nbegin\n  for i := 0 to ParamCount do\n    Result := Result + ' ' + AnsiQuotedStr(ParamStr(i), '\"');\nend;\n-------------------------EOF checkinst.pas---------------------\n\nLeonid Troyanovsky <lv.t@eco-pro.ru>\n\n++++++++++++++++++++++++++++++++++++\n\n=== \u0412\u0430\u0440\u0438\u0430\u043d\u0442 \u0441 \u041c\u044c\u044e\u0442\u0435\u043a\u0441\u043e\u043c ===\n\n\u0412 \u0444\u0430\u0439\u043b\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 (.dpr) \u043f\u0440\u044f\u043c\u043e \u043c\u043e\u0436\u0435\u0448\u044c \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0435\u0447\u0442\u043e \u0432\u0440\u043e\u0434\u0435:\nuses windows,...\nvar\n  H: THandle;\nbegin\n  H := CreateMutex(nil, True, '\u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u043e\u0435_\u0438\u043c\u044f_\u0434\u043b\u044f_\u0442\u0432\u043e\u0435\u0439_\u043f\u0440\u043e\u0433\u0438');\n  if GetLastError = ERROR_ALREADY_EXISTS then\n  begin\n    H := FindWindow(nil, '\u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430 \u043e\u043a\u043d\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b');\n    SetForegroundWindow(H);\n    Exit;\n  end;\n  Application.Initialize;\n  Application.Title := '\u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430 \u043e\u043a\u043d\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b';\n  Application.CreateForm(TAppData, AppData);\n  Application.CreateForm(TMain, Main);\n  Application.Run;\n  CloseHandle(H);\nend;\n\n********************************************************\n\n\u041c\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431.\n\nCheckEvent: TEvent;\n...\nprocedure TForm1.FormCreate(Sender: TObject);\nbegin\nCheckEvent:= TEvent.Create( nil, false, true, 'MYPROJECT_CHECKEXIST' );\nIf CheckEvent.WaitFor(10)<>wrSignaled then\nbegin\nShowMessage('\u0421\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u043e\u0434\u043d\u0443 \u0438 \u0442\u0443 \u0436\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 ?');\nHalt;\nend else\n...\n<\/div><\/pre>\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u041a\u0430\u043a \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e\u0433\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043c\u043e\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[431,440],"tags":[742,758,898,931],"_links":{"self":[{"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=\/wp\/v2\/posts\/277"}],"collection":[{"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=277"}],"version-history":[{"count":0,"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=\/wp\/v2\/posts\/277\/revisions"}],"wp:attachment":[{"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=277"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=277"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=277"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}