如何让一个小的程序,在同一时间内只运行一个?还有就是让窗口始终在最上层,怎么实现?

yangbig007 2002-02-28 07:08:45
先这些问题吧,帮帮我呀!!
...全文
94 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
llitcwl 2002-02-28
  • 打赏
  • 举报
回复
进管理中。
yangbig007 2002-02-28
  • 打赏
  • 举报
回复
此版本的大本营我找不到给分的地方了!帮我对你们有好处的呀!

谢谢你们先
zhuzhichao 2002-02-28
  • 打赏
  • 举报
回复
1. 如何使PB窗口总在最上层
通过SetWindowPos函数吧窗口的显示层次修改为HWND_TOPMOST,就可以使指定窗
口永远不会被其它窗口覆盖,该函数声明为:
Function Long SetWindowPos(Long hwnd, Long ord, Long x, Long y, Long
dx, Long dy, Long uflag) Library “user32.dll”
参数1为要顶层显示的窗口句柄,参数2指定显示的层次,参数7为附加选项,其余
参数指定窗口位置和大小,均可忽略。在窗口的Open或Activate事件中加入如下
函数调用:
SetWindowPos(Handle(This),-1,0,0,0,0,3)
参数2取-1表示在最顶层显示窗口,取1表示在最底层显示;最后一个参数若取1,
表示窗口大小保持不变,取2表示保持位置不变,因此,取3(=1+2)表示大小和
位置均保持不变,取0表示将窗口的大小和位置改变为指定值。
llitcwl 2002-02-28
  • 打赏
  • 举报
回复
1:FindWindowA找出窗口,如存在则说明主窗口已启动,就退出,这方法虽是偏方,但最可靠有效
首先在global external functions声明外部函数如下:

  FUNCTION long FindWindowA( ulong Winhandle, string wintitle ) Library ″user32″

  然后在application的 Open 事件中加入如下代码:

  ulong l_handle, lu_class

  string ls_name

  ls_name = ″我的系统″ // 此处ls_name为系统主窗口的标题Title

  l_handle = FindWindowA(lu_class, ls_name)

  if l_handle > 0 then

  MessageBox(″提示信息″, ″应用程序″ + This.AppName + ″已经运行,不能多次启动!″)

  Halt Close

  else

  open(w_main) // 此处为系统主窗口

  end if


2:SetWindowPos设置窗口位置
FUNCTION BOOLean SetWindowPos( ulong hWnd,ulong hWndInsertAfter, int X,int Y, int cx, int cy,UINT uFlags ) LIBRARY "user32.dll"

ulong ll_winhandle
//Bringwindowtotop
ll_winhandle=handle(this)
if ll_winhandle >0 then
SetWindowPos(ll_winhandle,- 1,0,0,0,0,1)
end if
zhuzhichao 2002-02-28
  • 打赏
  • 举报
回复
方法一:SDI应用(使用FindWindow函数)
//外部函数定义
function ulong FindWindowA(ref string classname,ref string windowname) library "user32.dll"
//应用Open事件
string ls_classname, ls_windowname
ulong ll_handle
ls_classname="FNWND350" ls_windowname="应用程序主窗口的标题" ll_handle=FindWindowA(ls_classname,ls_windowname)
if ll_handle<>0 then messagebox("注意", "程序已经运行!")
halt;
else
Open(w_main)
end if
方法二:SDI或者MDI应用(使用mutex对象)
//外部函数定义
function ulong CreateMutexA (ulong lpMutexAttributes,boolean bInitialOwner, ref string lpName) library "kernel32.dll"
function ulong GetLastError () library "kernel32.dll"
function ulong CloseHandle(ulong hMutex) library "kernel32.dll"
//应用Open事件
string ls_Name
//要创建的mutex名称
uint rc1,rc2
boolean lb_inherit
lb_inherit=false
ls_Name="ferryman12345"
rc1=CreateMutexA(0,lb_inherit,ls_Name)
rc2=getlasterror()
if rc2=183 then //mutex已经存在
CloseHandle(rc1)
messagebox("注意", "程序已经运行!")
halt;
else
open(w_mdi)
end if
方法三:SDI或者MDI应用(使用一个文件)在程序运行时打开一个文件,在程序结束时释放。这样如果系统要再次打开该文件将出错,通过这个判断程序是否运行。
integer FileNum
//应用Open事件
FileNum = FileOpen("app.ini")
if filenum = -1 then
messagebox("注意", "程序已经运行!")
halt;
else
open(w_mdi)
end if
//应用Close事件
FileClose(FileNum)
方法四:SDI或者MDI应用(使用Atom方法)
//外部函数定义 FUNCTION Integer GlobalDeleteAtom(Integer nAtom) LIBRARY "kernel32.dll"
FUNCTION Integer GlobalAddAtom(ref string lpString) LIBRARY "kernel32.dll" ALIAS FOR "GlobalAddAtomA"
FUNCTION Integer GlobalFindAtom(ref string lpString) LIBRARY "kernel32.dll" ALIAS FOR "GlobalFindAtomA"
//应用全局变量
uint gi_atom = 0
//应用Open事件
if (GlobalFindAtom( "ferryman12345" ) > 0) then
messagebox("注意", "程序已经运行!")
halt;
else
gi_atom = GlobalAddAtom( "ferryman12345" )
open(w_mdi)
end if
//应用Close事件
if (gi_atom > 0) then
GlobalDeleteAtom( gi_atom )
end if
abcn 2002-02-28
  • 打赏
  • 举报
回复
上面是‘该’而不是‘改’
abcn 2002-02-28
  • 打赏
  • 举报
回复
if invalid(windos) then
//改窗口忆已运行
else
//改窗口末运行
end if
始终最上层
window.setposition(topmost!)

401

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder 非技术版
社区管理员
  • 非技术版社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧