public function datetime of_get_file_createtime (string as_filename);/*函数作用:获取文件的创建时间
参数: as_filename string 文件名,需绝对文件路径 返回值:datetime */ long ll_code
datetime ldt_filedatetime long lul_date,lul_time
int lui_year,lui_month,lui_day,lui_hour,lui_minute,lui_second stc_find_data ls_file
ll_code=findfirstfile(as_filename,ls_file) findclose(ll_code)
ldt_filedatetime=datetime(ls_file.c_time) if ll_code=-1 then
setnull(ldt_filedatetime) else
filetimetodosdatetime (ls_file.c_time,lul_date,lul_time) lui_day=mod(lul_date,32)
lui_month=mod(lul_date,512)/32 if lui_month=0 then lui_month=1 end if
lui_year=lul_date/512+1980 lui_second=mod(lul_time,32)*2 lui_minute=mod(lul_time,2048)/32 lui_hour=(lul_time)/2048 + 8 if lui_hour>=24 then lui_hour=lui_hour - 24
ldt_filedatetime=datetime(relativedate(date(lui_year,lui_month,lui_day),1),time(lui_hour,lui_minute,lui_second)) else
ldt_filedatetime=datetime(date(lui_year,lui_month,lui_day),time(lui_hour,lui_minute,lui_second)) end if end if
return ldt_filedatetime end function
public function datetime of_get_file_accesstime (string as_filename);/*函数作用:获取文件的最后访问时间
参数: as_filename string 文件名,需绝对文件路径 返回值:datetime */ long ll_code
datetime ldt_filedatetime long lul_date,lul_time
int lui_year,lui_month,lui_day,lui_hour,lui_minute,lui_second
stc_find_data ls_file
ll_code=findfirstfile(as_filename,ls_file) findclose(ll_code)
ldt_filedatetime=datetime(ls_file.a_time) if ll_code=-1 then
setnull(ldt_filedatetime) else
filetimetodosdatetime (ls_file.a_time,lul_date,lul_time) lui_day=mod(lul_date,32)
lui_month=mod(lul_date,512)/32 if lui_month=0 then lui_month=1 end if
lui_year=lul_date/512+1980 lui_second=mod(lul_time,32)*2 lui_minute=mod(lul_time,2048)/32 lui_hour=(lul_time)/2048 + 8 if lui_hour>=24 then lui_hour=lui_hour - 24
ldt_filedatetime=datetime(relativedate(date(lui_year,lui_month,lui_day),1),time(lui_hour,lui_minute,lui_second)) else
ldt_filedatetime=datetime(date(lui_year,lui_month,lui_day),time(lui_hour,lui_minute,lui_second)) end if end if
return ldt_filedatetime end function
24、清除开始菜单中“我的文档”的列表文件 清除开始菜单中“我的文档”的列表文件
在“任务栏 属性”的“开始菜单程序”中有一个“清除”按钮,用于清除“我的文档”所列出的最近打开的文件列表。
在Powerbuilder应用程序中如何实现这一功能呢?
首先我们来理解Windows是通过什么方式在文档中添加列表文件的。
在Windows中,当我们打开某些类型的文件时,均在开始菜单的“我的文档”中添加以该文件名命名的快捷方式。其实这
调用了shell32.dll文件所提供的函数SHAddToRecentDocs。此函数顾名思义是专门用来往开始菜单中“我的文档”添加列
表文件的。Powerbuilder调用它的相应格式为: string NewFile
NewFile = \
SHAddToRecentDocs(2,NewFile) //注释:添加项目
如果我们反其道而行之,能不能让它清除列表文件而不是添加新项目呢。请看如下代码:
//注释:外部函数引用声明
Subroutine SHAddToRecentDocs(long uFlags,string pv ) Library \
//注释:给工程添加一个按钮,其单击事件的代码为: w_example.cb_1.clicked: string ls_temp setnull(ls_temp)
SHAddToRecentDocs(2,ls_temp)// 注释:清除
25、用Semaphore检测运行实例的个数
使用到的api函数解释:
CreateSemaphore(SECURITY_ATTRIBUTES lpSemaphoreAttributes , long lInitialCount, long lMaximumCount, string lpName )
该函数是Windows提供用来创建一个Semaphore信号的函数,其参数含义如下: lpSemaphoreAttributes:安全属性参数,是为Windows NT设置的,在Windows 95下可以忽略。但是在PowerBuilder中若如上述声明,则不能忽略,忽略后该函数有时不能正确执行,并返回0。此时,可以设置其为默认值,或者 改为long lpSemaphoreAttributes,然后再传入0。
lInitialCount:Semaphore的初始值,一般设为0或lMaxmumCount。 lMaximunCount:Semaphore信号的最大值。
lpName:该信号名,以便其他进程对其进行调用,若是相同进程可以设为Null。 函数成功时返回创建的Semaphore信号的句柄。该函数有一个特点,就是在要创建的信号已经创建了的情况下,它等同于函数OpenSemaphore(),仅仅是打开该Semaphore信号,并返回信号句柄。
ReleaseSemaphore(long hSemaphore, long lReleaseCount,long lpPreviousCount)
hSemaphore:函数CreateSemaphore()返回的Semaphore信号句柄; lReleaseCount: 当前信号值的改变量;
lpPreviousCount:返回的Semaphore信号被加之前的值,可用于跟踪测试。 如果Semaphore信号当前值加上lReleaseCount后不超过CreateSemaphore()中设定的最大值lMaximunCount,函数返回1(True),否则返回0(False),可用GetLastError()得到其失败的详细原因。
WaitForSingleObject(long hHandle , long dwMilliseconds) hHandle:等待对象的句柄; dwMilliseconds:等待时间。
该函数可以实现对一个可等待对象的等待操作,获取操作执行权。当等待的对象被释放时函数成功返回,同时使等待对象变为有信号状态,或者超时返回。 该函数用于等待Semaphore信号时,若Semaphore信号不为0,则函数成功返回,同时使Semaphore信号记数减1。 实现步骤: 定义结构:
Type SECURITY_ATTRIBUTES from structure long nLength
long lpSecurityDescriptor long bInheritHandle End Type
定义外部函数引用声明:
Function long ReleaseSemaphore (long hSemaphore, long
lReleaseCount ,long lpPreviousCount) Library \Function long CreateSemaphore(SECURITY_ATTRIBUTES
lpSemaphoreAttributes, long lInitialCount, long lMaximumCount , string lpName ) Library \Function long WaitForSingleObject (long hHandle, long dwMilliseconds) Library \
定义实例变量:
string Semaphore,
long Sema ,PrevSemaphore , Turn SECURITY_ATTRIBUTES Security 窗口w_example的open事件:
Security.bInheritHandle = True //注释:默认的安全值 Security.lpSecurityDescriptor = 0 Security.nLength = 96 Semaphore = \
//创建或打开一个Semaphore记数信号,设资源空闲使用量为4 Sema = CreateSemaphore(Security, 4, 4, Semaphore) //注释:申请一个权限,并立即返回
//Turn = WaitForSingleObject (Sema, 0)
//注释:如果不是正常返回,则表示没有申请到资源的使用权限 If Turn <> 0 Then
messagebox(\End If
窗口w_example的closequery事件:
//在当前值上加1,表示有一个程序退出,释放了一个权限,PrevSemaphore参数接收释放前的计数器的值
ReleaseSemaphore (Sema, 1, PrevSemaphore)
26、判断一个32位程序是否结束 实现步骤:
外部函数引用声明:
Function long OpenProcess(ref long dwDesiredaccess,ref
long bInherithandle, ref long dwProcessid) Library \