📄 bcjq050.txt
字号:
C++ Builder开发者:程序员之家
var how_many_ads = 3;
var now = new Date()
var sec = now.getSeconds()
var ad = sec % how_many_ads;
ad +=1;
首页
| 控件天堂 | 控件使用
| 编程技巧
| 源代码 | 编程工具 |
系统补丁 | 电子书籍 | 技术论坛
| 相关链接
if (ad==1) {document.write(''+'');}
if (ad==2) {document.write(''+'');}
if (ad==3) {document.write(''+'');}
var marqueecontents=''+scroll_text+''
if (document.all)
document.write(''+marqueecontents+'')
function regenerate(){
window.location.reload()
}
function regenerate2(){
if (document.layers){
setTimeout("window.onresize=regenerate",450)
intializemarquee()
}
}
function intializemarquee(){
document.cmarquee01.document.cmarquee02.document.write(marqueecontents)
document.cmarquee01.document.cmarquee02.document.close()
thelength=document.cmarquee01.document.cmarquee02.document.height
scrollit()
}
function scrollit(){
if (document.cmarquee01.document.cmarquee02.top>=thelength*(-1)){
document.cmarquee01.document.cmarquee02.top-=speed
setTimeout("scrollit()",100)
}
else{
document.cmarquee01.document.cmarquee02.top=marqueeheight
scrollit()
}
}
window.onload=regenerate2
当前位置
:
编程技巧
巧妙保证程序只有一个实例打开
Windows应用程序可以同时打开多个实例,有时候要限制用户只能打开应用程序的一个实例。最简单的方法是用
FindWindow函数检测有没有某个标题的窗口存在,但只这样无法处理标题栏自动改变的程序。有资料介绍了枚举
Windows任务列表的办法,但较为复杂。
----
一个巧妙的方法是用文件(或注册表)结合FindWindow函数来实现。其思路是:程序运行时在一个特定文件(或注册表中)做个"运行标记",同时记录窗口的标题,当窗口标题变化时同时修改记录的窗口标题,在退出删除"运行标记"或做个"结束标记",删除记录的窗口标题。这样,在程序运行时先检测特定文件(或注册表)中有没有"运行标记"。如果有"运行标记",再用FindWindow检测有没有所记录标题的窗口在运行。如果有则报警退出(或激活已经运行的实例窗口),如果没有则可能是程序上次不正常退出,提示用户并让用户决定是否运行。
---- 下面以C++Builder做示范:
启动时的检测可加在项目文件 Project1.cpp中:
#include < IniFiles.hpp >
//增加代码
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
TIniFile *RunFlag=new TIniFile("MyTest.ini");
//增加代码
AnsiString RunCaption[2]; //增加代码
try
{
Application- >Initialize();
//以下为增加代码
if(RunFlag->ReadInteger("Rec","RunFlag",0)==1)
{
RunCaption[0]=RunFlag- >ReadString("Rec","Caption","");
HWND PrevWindow=FindWindow
("TForm1",RunCaption[0].c_str());
if(PrevWindow)
{
ShowWindow(PrevWindow,SW_SHOW);
SetForegroundWindow(PrevWindow);
Application- >Terminate();
}
else
{
int button = Application- >MessageBox
("上次没有正常退出,要继续运行吗?",
"警告", MB_OKCANCEL);
if (button == IDCANCEL)
Application- >Terminate();
}
}
else
{ RunFlag- >WriteInteger("Rec","RunFlag",1);
RunFlag- >WriteString("Rec","Caption","Form1");
}
delete RunFlag;
//上面的为增加代码
Application- >CreateForm(__classid(TForm1), &Form1);
Application- >Run();
}
catch (Exception &exception)
{ Application- >ShowException(&exception);}
return 0;
}
----
每个退出程序的地方必须加上以下处理代码,如Form的OnClose事件处理函数中、使用exit()函数前:
TIniFile *RunFlag=new TIniFile("MyTest.ini");
RunFlag- >WriteInteger("Rec","RunFlag",0);
RunFlag- >WriteString("Rec","Caption","");
每当标题变化时(如变为"欢迎光临")必须加上以下处理代码:
RunFlag- >WriteString("Rec","Caption","欢迎光临");
牟建华
if (ad==1) {document.write(''+'');}
if (ad==2) {document.write(''+'');}
if (ad==3) {document.write(''+'');}
C++ Builder开发者®
2000年06月01日 站长:唐朝