PB开发的程序如何不显示在任务栏
假设pb开发的程序的主窗口为w_main,如果需要在程序运行时,使w_main的标题不显示在操作系统的任务栏上,可以这样处理:(1)建立一个visible 属性为false 的main! 类型窗口,假设为w_hide。
(2)在application的open事件中,写:
[cpp]
open(w_hide)
open(w_main, w_hide)
然后在w_main 的close 事件中写:
[cpp]
if isvalid(w_hide) then close(w_hide)
这样一来,运行后的pb程序就不会在任务栏上显示了,不过通过按Alt + Tab 快捷键切换程序时,还是可以看到该pb程序。 如果需要使得pb程序在按Alt + Tab 快捷键切换程序时不可见,则要加上以下几个步骤:
(3)建立如下自定义不可视对象nvo_hideprocess (将以下内容保存为本地文件nvo_hideprocess.sru ,然后导入pbl中)
[cpp]
$PBExportHeader$nvo_hideprocess.sru
forward
global type nvo_hideprocess from nonvisualobject
end type
end forward
global type nvo_hideprocess from nonvisualobject autoinstantiate
end type
type prototypes
FUNCTION long GetWindowLong(ulong hwnd,long nIndex) LIBRARY "user32.dll" ALIAS FOR "GetWindowLongA"
FUNCTION long SetWindowlong(ulong hwnd,long nIndex,long dwNewLong) LIBRARY "user32.dll" ALIAS FOR "SetWindowLongA"
end prototypes
forward prototypes
public subroutine of_hideprocess (long ahwd)
public function boolean of_is_in (long al_in, long al_all)
end prototypes
public subroutine of_hideprocess (long ahwd);//隐藏进程
constant long WS_EX_TOOLWINDOW = 128
Constant long WS_EX_LAYERED = 524288
Constant long WS_EX_APPWINDOW = 262144
Constant long GWL_EXSTYLE = - 20
constant long WS_EX_PALETTEWINDOW=392
long dwExStyle
dwExStyle = GetWindowLong(ahwd, GWL_EXSTYLE)
if not of_is_in(WS_EX_TOOLWINDOW, dwExStyle) then dwExStyle += WS_EX_TOOLWINDOW
SetWindowLong(ahwd, GWL_EXSTYLE, dwExStyle)
end subroutine
public function boolean of_is_in (long al_in, long al_all);
//====================================================================
// 判断数字al_in是不是包含在数字al_all中
// al_all是1、2、4、8、16、32、64...等数字中的若干个的和
// al_in 是1、2、4、8、16、32、64...等数字中的某一个
//====================================================================
dec ld
ld = log(al_in) / log(2)
if int(ld) <> ld then return false
long n, m
m = al_in + int(al_all / (al_in * 2)) * (2 * al_in)
if al_all >= m and al_all < m + al_in then return true
return false
end function
on nvo_hideprocess.create
call super::create
TriggerEvent( this, "constructor" )
end on
on nvo_hideprocess.destroy
TriggerEvent( this, "destructor" )
call super::destroy
end on
(4)在w_hide 的open 事件中加上:
[cpp]
//Alt + Tab 时,如果不隐藏程序,则屏蔽以下代码
nvo_hideprocess ln
ln.of_hideprocess(handle(this))
摘自 yyoinge的专栏