{"id":217189,"date":"2014-03-26T16:38:03","date_gmt":"2014-03-26T12:38:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=217189"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=217189","title":{"rendered":"<span class=\"post_title\">\u041d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0430\u0442\u043e\u043c\u043e\u0432 \u0438 \u0442\u0440\u0443\u0434\u043d\u043e\u0443\u043b\u043e\u0432\u0438\u043c\u0430\u044f \u0431\u0430\u0433\u0430 \u0432 VCL<\/span>"},"content":{"rendered":"<div class=\"content html_format\">   \t<img decoding=\"async\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/126\/f63\/314\/126f633143ba7a5cb18e518876963848.gif\" alt=\"image\" align=\"left\"\/>  <\/p>\n<h4>\u041f\u043e\u0438\u0441\u043a \u0431\u0430\u0433\u0430<\/h4>\n<p>  \u041c\u0443\u0447\u0438\u043b\u0430 \u043c\u0435\u043d\u044f \u0434\u043e\u043b\u0433\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u0431\u0430\u0433\u0430, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u0430\u044f \u0441 \u043d\u0435\u0430\u0434\u0435\u043a\u0432\u0430\u0442\u043d\u044b\u043c \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435\u043c \u0434\u0435\u043b\u044c\u0444\u0438\u0439\u0441\u043a\u0438\u0445 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043e\u0432 \u043f\u043e\u0441\u043b\u0435 \u0434\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0430\u043f\u0442\u0430\u0439\u043c\u0430 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0438 \u0438\u043d\u0442\u0435\u043d\u0441\u0438\u0432\u043d\u043e\u0439 \u043e\u0442\u043b\u0430\u0434\u043a\u0438. \u0421\u043f\u0438\u0441\u043a\u0438 \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u0432\u0430\u043b\u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c\u0441\u044f, \u043a\u043d\u043e\u043f\u043a\u0438 \u043d\u0430\u0436\u0438\u043c\u0430\u0442\u044c\u0441\u044f, \u043f\u043e\u043b\u044f \u0432\u0432\u043e\u0434\u0430 \u0442\u0435\u0440\u044f\u0442\u044c \u0444\u043e\u043a\u0443\u0441. \u0418 \u0432\u0441\u0435 \u0431\u044b\u043b\u043e \u043f\u0435\u0447\u0430\u043b\u044c\u043d\u043e, \u0438 \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a IDE \u043d\u0435 \u043f\u043e\u043c\u043e\u0433\u0430\u043b. \u0411\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e, \u043f\u043e\u0441\u043b\u0435 \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a\u0430 IDE \u2014 \u043e\u043d\u0430 \u0441\u0430\u043c\u0430 \u043d\u0430\u0447\u0438\u043d\u0430\u043b\u0430 \u0442\u0430\u043a \u0436\u0435 \u0433\u043b\u044e\u0447\u0438\u0442\u044c. \u041f\u0440\u0438\u0445\u043e\u0434\u0438\u043b\u043e\u0441\u044c \u043f\u0435\u0440\u0435\u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0442\u044c\u0441\u044f.<br \/>  \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u043c\u0435\u043d\u044f \u044d\u0442\u043e \u0434\u043e\u0441\u0442\u0430\u043b\u043e, \u0438 \u044f \u043f\u0440\u0438\u043d\u044f\u043b\u0441\u044f \u0435\u0451 \u0438\u0441\u043a\u0430\u0442\u044c. \u041d\u0430\u0434\u043e \u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043d\u0435 \u0431\u0435\u0437\u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043d\u043e.<br \/>  \u0417\u0430\u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u0432 \u043e\u043a\u043e\u043d\u043d\u044b\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u044f \u0441\u0442\u0430\u043b \u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0447\u0442\u043e \u0436\u0435 \u043f\u043e\u0448\u043b\u043e \u043d\u0435 \u0442\u0430\u043a.<a name=\"habracut\"><\/a><br \/>  \u0412\u044b\u044f\u0441\u043d\u0438\u043b\u043e\u0441\u044c, \u0447\u0442\u043e \u0432 \u043c\u043e\u0434\u0443\u043b\u0435 Control.pas \u0435\u0441\u0442\u044c \u0442\u0430\u043a\u0438\u0435 \u0441\u0442\u0440\u043e\u043a\u0438:  <\/p>\n<pre><code class=\"delphi\">function FindControl(Handle: HWnd): TWinControl; var   OwningProcess: DWORD; begin   Result := nil;   if (Handle &lt;&gt; 0) and (GetWindowThreadProcessID(Handle, OwningProcess) &lt;&gt; 0) and      (OwningProcess = GetCurrentProcessId) then   begin     if GlobalFindAtom(PChar(ControlAtomString)) = ControlAtom then       Result := Pointer(GetProp(Handle, MakeIntAtom(ControlAtom)))     else       Result := ObjectFromHWnd(Handle);   end; end;<\/code><\/pre>\n<p>  \u0438 <i>GetProp(Handle, MakeIntAtom(ControlAtom))<\/i> \u0432\u0441\u0435\u0433\u0434\u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 0. \u0422\u0443\u0442 \u0436\u0435 \u0432\u044b\u044f\u0441\u043d\u0438\u043b\u043e\u0441\u044c \u0447\u0442\u043e <i>ControlAtom<\/i> \u043f\u043e\u0447\u0435\u043c\u0443 \u0442\u043e 0, \u0438 <i>GlobalFindAtom(PChar(ControlAtomString))<\/i> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0442\u043e\u0436\u0435 0.<br \/>  \u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u044e\u0442\u0441\u044f <i>ControlAtomString<\/i> \u0438 <i>ControlAtom<\/i> \u0432 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0435 <i>InitControls<\/i>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u0441\u0435\u043a\u0446\u0438\u0438 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u043e\u0434\u0443\u043b\u044f:  <\/p>\n<pre><code class=\"delphi\">procedure InitControls; var   UserHandle: HMODULE; begin {$IF NOT DEFINED(CLR)}   WindowAtomString := Format('Delphi%.8X',[GetCurrentProcessID]);   WindowAtom := GlobalAddAtom(PChar(WindowAtomString));   ControlAtomString := Format('ControlOfs%.8X%.8X', [HInstance, GetCurrentThreadID]);   ControlAtom := GlobalAddAtom(PChar(ControlAtomString));   RM_GetObjectInstance := RegisterWindowMessage(PChar(ControlAtomString)); {$IFEND}<\/code><\/pre>\n<p>  <i>ControlAtomString<\/i> \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e, \u0430 \u0432\u043e\u0442 <i>ControlAtom<\/i> \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043d\u0443\u043b\u0435\u043c. \u041f\u0440\u043e\u0432\u0435\u0440\u043e\u043a \u043d\u0430 \u043e\u0448\u0438\u0431\u043a\u0438 \u0442\u0443\u0442 \u043d\u0435\u0442, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u044d\u0442\u043e \u0430\u0443\u043a\u043d\u0443\u043b\u043e\u0441\u044c \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u043f\u043e\u0437\u0436\u0435, \u0443\u0432\u044b. \u0415\u0441\u043b\u0438 \u0432\u0441\u0442\u0430\u0432\u0438\u0442\u044c <i>GetLastError<\/i> \u043f\u043e\u0441\u043b\u0435 <i>GlobalAddAtom<\/i>, \u0442\u043e \u043e\u043d \u0432\u0435\u0440\u043d\u0435\u0442 <i>ERROR_NOT_ENOUGH_MEMORY<\/i>. \u0410 \u0435\u0441\u043b\u0438 \u0435\u0449\u0435 \u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0440\u0435\u043c\u0430\u0440\u043a\u0443 \u043d\u0430 MSDN \u043a <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/ms649060(v=vs.85).aspx\">GlobalAddAtom<\/a>, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c:  <\/p>\n<blockquote><p>Global atoms are not deleted automatically when the application terminates. For every call to the GlobalAddAtom function, there must be a corresponding call to the GlobalDeleteAtom function.<\/p><\/blockquote>\n<p>  \u0412\u0441\u0435 \u0441\u0440\u0430\u0437\u0443 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043f\u043e\u043d\u044f\u0442\u043d\u043e. \u0415\u0441\u043b\u0438 \u043d\u0435\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u2014 \u0442\u043e \u0443\u0442\u0435\u043a\u0443\u0442 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0435 \u0430\u0442\u043e\u043c\u044b. \u0410 \u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0430\u0442\u043e\u043c\u043e\u0432 \u0443 \u043d\u0430\u0441 \u043a\u043e\u0442 \u043d\u0430\u043f\u043b\u0430\u043a\u0430\u043b: 0xC000-0xFFFF, \u0442\u043e \u0435\u0441\u0442\u044c \u0432\u0441\u0435\u0433\u043e 4 \u0442\u044b\u0441\u044f\u0447\u0438. \u0422.\u0435. \u043a\u0430\u0436\u0434\u0430\u044f dll, \u0438 \u043a\u0430\u0436\u0434\u044b\u0439 exe-\u0448\u043d\u0438\u043a \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u043d\u0430 Delphi \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c VCL \u043f\u0440\u0438 \u043d\u0435\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u043c \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0438 \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043f\u043e\u0441\u043b\u0435 \u0441\u0435\u0431\u044f \u0443\u0442\u0435\u043a\u0448\u0438\u0435 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0435 \u0430\u0442\u043e\u043c\u044b. \u0415\u0441\u043b\u0438 \u0431\u044b\u0442\u044c \u0442\u043e\u0447\u043d\u0435\u0435 \u2014 \u0442\u043e \u043f\u043e 2-3 \u0430\u0442\u043e\u043c\u0430 \u043d\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u043d\u0441\u0442\u0430\u043d\u0441:<br \/>  <b>ControlAtom<\/b> \u0438 <b>WindowAtom<\/b> \u0432 Controls.pas, \u0438 <b>WndProcPtrAtom<\/b> \u0432 Dialogs.pas<\/p>\n<h4>Workaround<\/h4>\n<p>  \u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0435 \u0430\u0442\u043e\u043c\u044b \u043d\u0435 \u0441\u043e\u0441\u0442\u0430\u0432\u0438\u0442 \u0442\u0440\u0443\u0434\u0430. \u0412\u043e\u0442 \u043a\u043e\u0434 \u043f\u0440\u043e\u0441\u0442\u0435\u043d\u044c\u043a\u043e\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u044f\u044e\u0449\u0435\u0433\u043e \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0435 \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u044b\u0435 \u0430\u0442\u043e\u043c\u044b:  <\/p>\n<pre><code class=\"delphi\">program EnumAtomsSample;  {$APPTYPE CONSOLE}  uses   Windows,   SysUtils;  function GetAtomName(nAtom: TAtom): string; var n: Integer;     tmpstr: array [0..255] of Char; begin   n := GlobalGetAtomName(nAtom, PChar(@tmpstr[0]), 256);   if n = 0 then     Result := ''   else     Result := tmpstr; end;  procedure EnumAtoms; var i: Integer;     s: string; begin   for i := MAXINTATOM to MAXWORD do     begin       s := GetAtomName(i);       if (s &lt;&gt; '') then WriteLn(s);     end; end;  begin   try     EnumAtoms;     ReadLn;   except     on E: Exception do       Writeln(E.ClassName, ': ', E.Message);   end; end.<\/code><\/pre>\n<p>  \u041c\u043e\u0436\u043d\u043e \u0443\u0431\u0435\u0434\u0438\u0442\u0441\u044f \u0447\u0442\u043e \u0430\u0442\u043e\u043c\u044b \u0442\u0435\u043a\u0443\u0442 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0432 \u043b\u044e\u0431\u043e\u0439 VCL \u043f\u0440\u043e\u0435\u043a\u0442, \u0438 \u043f\u0440\u0438\u0431\u0438\u0432 \u0435\u0433\u043e \u0447\u0435\u0440\u0435\u0437 \u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440 \u0437\u0430\u0434\u0430\u0447.<\/p>\n<p>  \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0430\u0442\u043e\u043c\u044b \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0435, \u0442\u043e \u043c\u044b \u0438\u0445 \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u0438\u0431\u0438\u0432\u0430\u0442\u044c \u0432\u043d\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0442\u043e\u0433\u043e \u043a\u0435\u043c \u043e\u043d\u0438 \u0431\u044b\u043b\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u044b. \u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u043a\u0430\u043a-\u0442\u043e \u043d\u0430\u0443\u0447\u0438\u0442\u044c\u0441\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u0447\u0442\u043e \u0430\u0442\u043e\u043c \u0443\u0442\u0435\u043a\u0448\u0438\u0439.<br \/>  \u0415\u0441\u043b\u0438 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0438\u043c\u0435\u043d\u0430 \u0430\u0442\u043e\u043c\u043e\u0432, \u0442\u043e \u0434\u043b\u044f<br \/>  WndProcPtrAtom \u2014 \u044d\u0442\u043e WndProcPtr [HInstance] [ThreadID]<br \/>  ControlAtom \u2014 \u044d\u0442\u043e ControlOfs [HInstance] [ThreadID]<br \/>  WindowAtom \u2014 \u044d\u0442\u043e Delphi [ProcessID]<br \/>  \u0412\u043e \u0432\u0441\u0435\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043d\u044f\u0442\u044c \u0447\u0442\u043e \u0430\u0442\u043e\u043c \u0441\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u043d Delphi \u043f\u043e \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u043d\u043e\u043c\u0443 \u043f\u0440\u0435\u0444\u0438\u043a\u0441\u0443 + \u043e\u0434\u043d\u043e \u0438\u043b\u0438 \u0434\u0432\u0430 32-\u0445 \u0431\u0438\u0442\u043d\u044b\u0445 \u0447\u0438\u0441\u043b\u0430 \u0432 HEX-\u0435. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e \u0432 HEX \u0437\u0430\u043f\u0438\u0441\u0430\u043d \u043b\u0438\u0431\u043e ProcessID \u043b\u0438\u0431\u043e ThreadID. \u041c\u044b \u043b\u0435\u0433\u043a\u043e \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0435\u0441\u0442\u044c \u0442\u0430\u043a\u043e\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0438\u043b\u0438 \u043f\u043e\u0442\u043e\u043a \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0435. \u0415\u0441\u043b\u0438 \u043d\u0435\u0442 \u2014 \u0442\u043e \u0443 \u043d\u0430\u0441 \u044f\u0432\u043d\u043e \u0443\u0442\u0435\u043a\u0448\u0438\u0439 \u0430\u0442\u043e\u043c, \u0438 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0440\u0438\u0441\u043a\u043d\u0443\u0442\u044c \u0435\u0433\u043e \u043e\u0441\u0432\u043e\u0431\u043e\u0434\u0438\u0442\u044c. \u0414\u0430 \u0434\u0430, \u0438\u043c\u0435\u043d\u043d\u043e \u0440\u0438\u0441\u043a\u043d\u0443\u0442\u044c. \u0414\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e \u043a\u0430\u043a \u043c\u044b \u0443\u0431\u0435\u0434\u0438\u043b\u0438\u0441\u044c \u0447\u0442\u043e \u043f\u043e\u0442\u043e\u043a\u0430\/\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u0441 \u0442\u0430\u043a\u0438\u043c ID \u043d\u0435\u0442, \u0438 \u0441\u043e\u0431\u0440\u0430\u043b\u0438\u0441\u044c \u0443\u0434\u0430\u043b\u044f\u0442\u044c \u0430\u0442\u043e\u043c \u2014 \u044d\u0442\u043e\u0442 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u044f\u0432\u0438\u0442\u044c\u0441\u044f, \u0441 \u0440\u043e\u0432\u043d\u043e \u0442\u0430\u043a\u0438\u043c \u0436\u0435 ID, \u0438 \u043e\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u043c Delphi. \u0415\u0441\u043b\u0438 \u0432 \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u043a \u043c\u0435\u0436\u0434\u0443 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u043e\u0439 \u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435\u043c \u0442\u0430\u043a\u043e\u0435 \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0434\u0435\u0442 \u2014 \u0442\u043e \u043c\u044b \u043f\u0440\u0438\u0431\u044c\u0435\u043c \u0430\u0442\u043e\u043c \u0443 \u0432\u0430\u043b\u0438\u0434\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u0421\u0438\u0442\u0443\u0430\u0446\u0438\u044f \u043a\u0440\u0430\u0439\u043d\u0435 \u043c\u0430\u043b\u043e\u0432\u0435\u0440\u043e\u044f\u0442\u043d\u0430, \u0438\u0431\u043e \u0432 \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u043a \u043c\u0435\u0436\u0434\u0443 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u043e\u0439 \u0434\u043e\u043b\u0436\u0435\u043d \u0441\u043e\u0437\u0434\u0430\u0442\u044c\u0441\u044f \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u0435\u043b\u044c\u0444\u0438\u0439\u0441\u043a\u0438\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441, \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u043e\u0432\u043d\u043e \u043f\u043e \u0442\u043e\u043c\u0443 \u0436\u0435 ID, \u0438 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0443\u0441\u043f\u0435\u0442\u044c \u043f\u0440\u043e\u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0432\u043e\u0438 \u0430\u0442\u043e\u043c\u044b. \u0414\u0440\u0443\u0433\u0438\u0445 workaround-\u043e\u0432 (\u0431\u0435\u0437 \u043f\u0440\u0430\u0432\u043a\u0438 VCL \u043a\u043e\u0434\u0430) \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u044f \u043d\u0435 \u0432\u0438\u0436\u0443.<\/p>\n<p>  \u042f \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u043a\u043e\u043d\u0441\u043e\u043b\u044c\u043d\u0443\u044e \u0442\u0443\u043b\u0437\u0443, \u0434\u043b\u044f \u0447\u0438\u0441\u0442\u043a\u0438 \u0442\u0430\u043a\u0438\u0445 \u0443\u0442\u0435\u043a\u0448\u0438\u0445 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0445 \u0430\u0442\u043e\u043c\u043e\u0432. <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0412\u043e\u0442 \u043a\u043e\u0434 \u0434\u0430\u043d\u043d\u043e\u0439 \u0442\u0443\u043b\u0437\u044b:<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"delphi\">program AtomCleaner;  {$APPTYPE CONSOLE}  uses   Windows,   SysUtils;  const   THREAD_QUERY_INFORMATION = $0040;  function OpenThread(dwDesiredAccess: DWORD; bInheritHandle: BOOL; dwThreadId: DWORD): THandle; stdcall; external kernel32;  function ThreadExists(const ThreadID: Cardinal): Boolean; var h: THandle; begin   h := OpenThread(THREAD_QUERY_INFORMATION, False, ThreadID);   if h = 0 then   begin     Result := False;   end   else   begin     Result := True;     CloseHandle(h);   end; end;  function TryHexChar(c: Char; out b: Byte): Boolean; begin   Result := True;   case c of     '0'..'9':  b := Byte(c) - Byte('0');     'a'..'f':  b := (Byte(c) - Byte('a')) + 10;     'A'..'F':  b := (Byte(c) - Byte('A')) + 10;   else     Result := False;   end; end;  function TryHexToInt(const s: string; out value: Cardinal): Boolean; var i: Integer;     chval: Byte; begin   Result := True;   value := 0;   for i := 1 to Length(s) do   begin     if not TryHexChar(s[i], chval) then       begin         Result := False;         Exit;       end;     value := value shl 4;     value := value + chval;   end; end;  function GetAtomName(nAtom: TAtom): string; var n: Integer;     tmpstr: array [0..255] of Char; begin   n := GlobalGetAtomName(nAtom, PChar(@tmpstr[0]), 256);   if n = 0 then     Result := ''   else     Result := tmpstr; end;   function CloseAtom(nAtom: TAtom): Boolean; var n: Integer;     s: string; begin   Result := False;   s := GetAtomName(nAtom);   if s = '' then Exit;   WriteLn('Closing atom: ', IntToHex(nAtom, 4), ' ', s);   GlobalDeleteAtom(nAtom);   Result := True; end;  function ProcessAtom(nAtom: TAtom): Boolean; var s: string;     n: Integer;     id: Cardinal; begin   Result := False;   s := GetAtomName(nAtom);    n := Pos('ControlOfs', s);   if n = 1 then   begin     Delete(s, 1, Length('ControlOfs'));     if Length(s) &lt;&gt; 16 then Exit;     Delete(s, 1, 8);     if not TryHexToInt(s, id) then Exit;     if not ThreadExists(id) then         Exit(CloseAtom(nAtom));     Exit;   end;    n := Pos('WndProcPtr', s);   if n = 1 then   begin     Delete(s, 1, Length('WndProcPtr'));     if Length(s) &lt;&gt; 16 then Exit;     Delete(s, 1, 8);     if not TryHexToInt(s, id) then Exit;     if not ThreadExists(id) then         Exit(CloseAtom(nAtom));     Exit;   end;    n := Pos('Delphi', s);   if n = 1 then   begin     Delete(s, 1, Length('Delphi'));     if Length(s) &lt;&gt; 8 then Exit;     if not TryHexToInt(s, id) then Exit;     if GetProcessVersion(id) = 0 then       if GetLastError = ERROR_INVALID_PARAMETER then         Exit(CloseAtom(nAtom));     Exit;   end; end;  procedure EnumAndCloseAtoms; var i: Integer; begin   i := MAXINTATOM;   while i &lt;= MAXWORD do   begin     if not ProcessAtom(i) then         Inc(i);   end; end;  begin   try     EnumAndCloseAtoms;   except     on E: Exception do       Writeln(E.ClassName, ': ', E.Message);   end; end.<\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u041f\u0440\u043e\u0441\u0442\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c, \u0443\u0442\u0435\u043a\u0448\u0438\u0435 \u0430\u0442\u043e\u043c\u044b \u0447\u0438\u0441\u0442\u044f\u0442\u0441\u044f. \u041f\u0440\u043e\u0432\u0435\u0440\u044c\u0442\u0435\u0441\u044c, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043f\u0440\u044f\u043c\u043e \u0441\u0435\u0439\u0447\u0430\u0441 \u0443 \u0432\u0430\u0441 \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0435 \u0443\u0436\u0435 \u0435\u0441\u0442\u044c \u0443\u0442\u0435\u043a\u0448\u0438\u0435 \u0430\u0442\u043e\u043c\u044b.<\/p>\n<h4>\u0412 \u0437\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h4>\n<p>  \u0418\u043d\u0441\u043f\u0435\u043a\u0446\u0438\u044f \u043a\u043e\u0434\u0430 \u043f\u043e\u043a\u0430\u0437\u0430\u043b\u0430, \u0447\u0442\u043e \u0434\u0430\u043d\u043d\u044b\u0435 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0435 \u0430\u0442\u043e\u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f <i>SetProp<\/i> \u0438 <i>GetProp<\/i> \u0444\u0443\u043d\u043a\u0446\u0438\u0439. \u0421\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e \u043d\u0435\u043f\u043e\u043d\u044f\u0442\u043d\u043e \u043f\u043e\u0447\u0435\u043c\u0443 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 Delphi \u0440\u0435\u0448\u0438\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0430\u0442\u043e\u043c\u044b. \u0412\u0435\u0434\u044c \u043e\u0431\u0435 \u044d\u0442\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u0440\u0435\u043a\u0440\u0430\u0441\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0441 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f\u043c\u0438 \u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0438. \u0414\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u0430\u043c\u0430 \u043f\u043e \u0441\u0435\u0431\u0435 \u0443\u0436\u0435 \u0435\u0441\u0442\u044c, \u0432\u0435\u0434\u044c \u0441 \u043d\u0435\u0439 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0430\u0442\u043e\u043c.<br \/>  \u0422\u0430\u043a \u0436\u0435 \u043d\u0435\u043f\u043e\u043d\u044f\u0442\u043d\u0430 \u043b\u043e\u0433\u0438\u043a\u0430 \u0432\u043e\u0442 \u0442\u0430\u043a\u0438\u0445 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0439 \u0432 VCL \u043a\u043e\u0434\u0435:<br \/>  <i>if GlobalFindAtom(PChar(ControlAtomString)) = ControlAtom then<\/i><br \/>  \u041e\u0431\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0432 \u043e\u0434\u043d\u043e\u043c \u043c\u0435\u0441\u0442\u0435. \u0421\u0442\u0440\u043e\u043a\u0430 \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u0442\u0441\u044f \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u043e\u0439 (\u0438\u0437 HInstance \u0438 ThreadID). \u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0432\u0441\u0435\u0433\u0434\u0430 \u0431\u0443\u0434\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c True. \u0423\u0432\u044b, Delphi \u0441\u0435\u0439\u0447\u0430\u0441 \u043f\u0440\u043e\u0434\u0432\u0438\u0433\u0430\u0435\u0442 \u043d\u043e\u0432\u044b\u0435 \u0444\u0438\u0447\u0438, FMX-\u044b \u0432\u0441\u044f\u043a\u0438\u0435. \u0412\u0440\u044f\u0434 \u043b\u0438 \u043e\u043d\u0438 \u0431\u0443\u0434\u0443\u0442 \u0444\u0438\u043a\u0441\u0438\u0442\u044c \u044d\u0442\u0443 \u0431\u0430\u0433\u0443. \u041b\u0438\u0447\u043d\u043e \u0443 \u043c\u0435\u043d\u044f \u0434\u0430\u0436\u0435 \u0436\u0435\u043b\u0430\u043d\u0438\u044f \u043d\u0430 QC \u0440\u0435\u043f\u043e\u0440\u0442\u0438\u0442\u044c \u043d\u0435\u0442, \u0437\u043d\u0430\u044f \u043a\u0430\u043a \u043e\u043d\u043e \u0444\u0438\u043a\u0441\u0438\u0442\u0441\u044f. \u041d\u043e \u0436\u0438\u0442\u044c \u0441 \u044d\u0442\u0438\u043c \u043a\u0430\u043a-\u0442\u043e \u043d\u0430\u0434\u043e. \u0416\u0435\u043b\u0430\u044e\u0449\u0438\u0435 \u043c\u043e\u0433\u0443\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043a\u043e\u0434 \u0432\u044b\u0448\u0435\u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u0439 \u0442\u0443\u043b\u0437\u044b \u043f\u0440\u0438 \u0441\u0442\u0430\u0440\u0442\u0435 \u0441\u0432\u043e\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u041d\u0430 \u043c\u043e\u0439 \u0432\u0437\u0433\u043b\u044f\u0434 \u044d\u0442\u043e \u0432\u0441\u044f\u043a\u043e \u043b\u0443\u0447\u0448\u0435, \u0447\u0435\u043c \u0434\u043e\u0436\u0438\u0434\u0430\u0442\u044c\u0441\u044f \u0443\u0442\u0435\u043a\u0448\u0438\u0445 \u0430\u0442\u043e\u043c\u043e\u0432.<br \/>  \u041d\u0443 \u0438 \u0432 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0430\u0445 \u043d\u0443\u0436\u043d\u043e \u0441\u0442\u0430\u0440\u0430\u0442\u044c\u0441\u044f \u0438\u0437\u0431\u0435\u0433\u0430\u0442\u044c \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0445 \u0430\u0442\u043e\u043c\u043e\u0432, \u0438\u0431\u043e \u041e\u0421 \u043d\u0435 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u0443\u0435\u0442 \u0438\u0445 \u0443\u0442\u0435\u0447\u043a\u0438.<\/p>\n<p>  <a href=\"http:\/\/screenup.org\/habr\/atom_projects.zip\">\u0422\u0443\u043b\u0437\u044b + \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0438<\/a>    \t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/217189\/\"> http:\/\/habrahabr.ru\/post\/217189\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">   \t<img decoding=\"async\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/126\/f63\/314\/126f633143ba7a5cb18e518876963848.gif\" alt=\"image\" align=\"left\"\/>  <\/p>\n<h4>\u041f\u043e\u0438\u0441\u043a \u0431\u0430\u0433\u0430<\/h4>\n<p>  \u041c\u0443\u0447\u0438\u043b\u0430 \u043c\u0435\u043d\u044f \u0434\u043e\u043b\u0433\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u0431\u0430\u0433\u0430, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u0430\u044f \u0441 \u043d\u0435\u0430\u0434\u0435\u043a\u0432\u0430\u0442\u043d\u044b\u043c \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435\u043c \u0434\u0435\u043b\u044c\u0444\u0438\u0439\u0441\u043a\u0438\u0445 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043e\u0432 \u043f\u043e\u0441\u043b\u0435 \u0434\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0430\u043f\u0442\u0430\u0439\u043c\u0430 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0438 \u0438\u043d\u0442\u0435\u043d\u0441\u0438\u0432\u043d\u043e\u0439 \u043e\u0442\u043b\u0430\u0434\u043a\u0438. \u0421\u043f\u0438\u0441\u043a\u0438 \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u0432\u0430\u043b\u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c\u0441\u044f, \u043a\u043d\u043e\u043f\u043a\u0438 \u043d\u0430\u0436\u0438\u043c\u0430\u0442\u044c\u0441\u044f, \u043f\u043e\u043b\u044f \u0432\u0432\u043e\u0434\u0430 \u0442\u0435\u0440\u044f\u0442\u044c \u0444\u043e\u043a\u0443\u0441. \u0418 \u0432\u0441\u0435 \u0431\u044b\u043b\u043e \u043f\u0435\u0447\u0430\u043b\u044c\u043d\u043e, \u0438 \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a IDE \u043d\u0435 \u043f\u043e\u043c\u043e\u0433\u0430\u043b. \u0411\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e, \u043f\u043e\u0441\u043b\u0435 \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a\u0430 IDE \u2014 \u043e\u043d\u0430 \u0441\u0430\u043c\u0430 \u043d\u0430\u0447\u0438\u043d\u0430\u043b\u0430 \u0442\u0430\u043a \u0436\u0435 \u0433\u043b\u044e\u0447\u0438\u0442\u044c. \u041f\u0440\u0438\u0445\u043e\u0434\u0438\u043b\u043e\u0441\u044c \u043f\u0435\u0440\u0435\u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0442\u044c\u0441\u044f.<br \/>  \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u043c\u0435\u043d\u044f \u044d\u0442\u043e \u0434\u043e\u0441\u0442\u0430\u043b\u043e, \u0438 \u044f \u043f\u0440\u0438\u043d\u044f\u043b\u0441\u044f \u0435\u0451 \u0438\u0441\u043a\u0430\u0442\u044c. \u041d\u0430\u0434\u043e \u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043d\u0435 \u0431\u0435\u0437\u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043d\u043e.<br \/>  \u0417\u0430\u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u0432 \u043e\u043a\u043e\u043d\u043d\u044b\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u044f \u0441\u0442\u0430\u043b \u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0447\u0442\u043e \u0436\u0435 \u043f\u043e\u0448\u043b\u043e \u043d\u0435 \u0442\u0430\u043a.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-217189","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/217189","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=217189"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/217189\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=217189"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=217189"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=217189"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}