用GlobalFindAtom()使程序中只运行一次BUG,各位DFW你们根本没注意的问题,不信请看!!!(100分)

  • 主题发起人 主题发起人 panzichan
  • 开始时间 开始时间
P

panzichan

Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br>&nbsp; Dialogs;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; procedure FormCreate(Sender: TObject);<br>&nbsp; &nbsp; procedure FormDestroy(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; &nbsp; atom:WORD;<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br><br>implementation<br><br>{$R *.dfm}<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br>&nbsp; &nbsp; if GlobalFindAtom('myexe')=0 then<br>&nbsp; &nbsp; &nbsp; &nbsp;atom:=GlobalAddATom('myexe')<br>&nbsp; &nbsp; else<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp;showmessage('Program is running');<br>&nbsp; &nbsp; &nbsp; &nbsp;Halt;<br>&nbsp; &nbsp; end; &nbsp; &nbsp; &nbsp;<br>end;<br><br>procedure TForm1.FormDestroy(Sender: TObject);<br>begin<br>&nbsp; &nbsp; &nbsp;GlobalDeleteAtom(atom);<br>end;<br><br>end.<br>&nbsp;不知各位注意了没有,如果按Alt+Ctrl+Del用任务管理器的进程杀掉,这程序由于没有悉放atom而不能再运行,<br>该如何解决呢???
 
这种判断程序是不是只有一份拷贝的方法好像不严谨<br>最好的方法应该是&lt;&lt;程序序指南5.0&gt;&gt;中的方法<br>
 
52free:<br>&nbsp; &nbsp; &nbsp; 能不能把代码贴出来,行的话马上给你分!!!哈哈哈..
 
我在网吧中,你可以找找好像很多网站上都有这本书的电子版
 
unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br>&nbsp; Dialogs, AppEvnts, StdCtrls;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; procedure FormCreate(Sender: TObject);<br>&nbsp; &nbsp; procedure FormDestroy(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; &nbsp; atom: WORD;<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br><br>var<br>&nbsp; Form1: TForm1;<br><br><br>implementation<br><br>{$R *.dfm}<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>const<br>&nbsp; &nbsp;ACaption = 'TheCaption';<br>begin<br>&nbsp; showMessage(IntToStr(FindWindow(nil, ACaption)));<br>&nbsp; showMessage(IntToStr(GlobalFindAtom('myexe')));<br>&nbsp; if (GlobalFindAtom('myexe') = 0) &nbsp;then<br>&nbsp; &nbsp; atom := GlobalAddATom('myexe')<br>&nbsp; else<br>&nbsp; &nbsp; if (GlobalFindAtom('myexe') &lt;&gt; 0) and (FindWindow(nil, ACaption) = 0) &nbsp;then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; ShowMessage('Here');<br>&nbsp; &nbsp; end<br>&nbsp; &nbsp; else<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; showmessage('Program is running');<br>&nbsp; &nbsp; &nbsp; Application.Terminate;<br>&nbsp; &nbsp; end;<br>&nbsp; Form1.Caption := ACaption;<br>end;<br><br>procedure TForm1.FormDestroy(Sender: TObject);<br>begin<br>&nbsp; GlobalDeleteAtom(atom);<br>end;<br><br>end.<br>//此方法适合大多数有Window程序, 遇到无Window程序, 只要把FindowWindow( )找类名就<br>可以了, 当然自己程序的类名要设得鬼老一点, 以免同类名.[8D]<br>
 
感谢 大富翁WW!!!<br>&nbsp; &nbsp; 请问你能留下你的EMAIL给我吗?<br>&nbsp; &nbsp; 诚挚的等候你的回复.
 
因为水平比较菜, 事情比较忙, 所以就不留Email了; 实在有什么问题可以在线呼叫<br>大富翁里的众多高手[:)]
 
后退
顶部