//声明外部函数如下:限制应用程序只运行一次
FUNCTION uLong ShowWindow( ulong winhandle, int wincommand ) Library "user32" //显示窗口
FUNCTION uLong BringWindowToTop( ulong HWND ) Library "user32" //置前窗口唯一
FUNCTION long FindWindowA( ulong Winhandle, string wintitle ) Library "user32" //判断当前窗口是否为指定窗口
//限制应用程序只运行一次
long ll_winhandle
ll_winhandle = FindWindowA( 0, "某某窗口标题" )
If ll_winhandle > 0 Then
BringWindowToTop( ll_winhandle )
ShowWindow( ll_winhandle , 3 ) //数字不同窗口显示不同,3为原窗口样式,5为最大化
Return
End If
(2)获得路径判断参数路径同时赋值变动的程序路径
Function Long GetCurrentDirectoryA(long length,ref string path) LIBRARY "Kernel32"//获得当前程序路径
//(1)首先根据全局声明API的FUNCTION函数 当前程序的路径,为了以后菜单里数据库的操作
//Function Long GetCurrentDirectoryA(long length,ref string_path) LIBRARY "Kernel32"
//取得当前应用程序的路径
//首先给路径全局变量赋值地址存储空间(用空格填充)
str_directiry = Space(250)
//取得真实路径字符串的长度给全局变量lo_directory并且把路径字符串赋值给str_panth(如果没有够250长度则根据前面给得空格空间填充)
long lo_directory
lo_directory = GetCurrentDirectoryA(250,str_directiry)
IF lo_directory > 0 THEN
str_directiry = Left(str_directiry,lo_directory)
ELSE
Messagebox("错误!!","当前运行的程序的路径读取错误"+String(lo_directory)+"!!程序退出,请联系开发人员!!!")
return
END IF
//(2)核对是否路径和参数中的路径设置的一致,不一致提示更改
if str_directiry<>profilestring(str_directiry+"/modify.ini","DIRECTORY","PATH","") then
messagebox("提示窗口","当前程序路径和参数中设置的路径不一致,请维护!!!")
//打开从对话框选取主程序来获得路径
int in_value
string str_filename,str_pathname
in_value=getfileopenname("<< 选择主程序 >>",str_pathname,str_filename,"exe","Exe Files (*.exe),*.exe")
if in_value=1 and str_filename='main.exe' then
//成功获得,把路径赋值给参数
setprofilestring(left(str_pathname,len(str_pathname)-len(str_filename)-1)+"/modify.ini","DIRECTORY",&
"PATH",left(str_pathname,len(str_pathname)-len(str_filename)-1))
str_directiry=left(str_pathname,len(str_pathname)-len(str_filename)-1)
else
messagebox("提示窗口","您没有选择设置正确,程序退出!!!")
return
end if
end if
//(3)成功获得路径后开始连接数据库
SQLCA.DBMS = "ODBC"
SQLCA.AutoCommit = False
SQLCA.DBParm = "Connectstring='DSN=NewChufang'"
connect;
open(w_logon)
(3)其它函数声明
FUNCTION boolean CopyFileA(ref string cfrom, ref string cto, boolean flag) LIBRARY "Kernel32.dll"//声明COPY函数执行COPY行为
Function boolean CreateDirectoryA(string lpPathName,string lpSecurityAttributes) Library "kernel32.dll"//声明创建函数执行创建文件夹行为
SubRoutine Sleep(ulong milli) Library "Kernel32.dll"//定义延迟函数API