类型:转载 责任编辑:asp 日期:2007/03/01
我做了一个屏幕保护文件: 123.scr
想在另一个用vb做的程序中调用!如何做到啊~~!
推荐阅读
3、如何检测鼠标的移动
mousemove事件用来检测鼠标的移动,当应用程序启动时甚至鼠标实际上并未移动的情况下,mousemove事件都会触发一次。所以第一次触发mousemove事件时,只是记录鼠标当前位置,仅当鼠标真正从其起始位置移开时,才终止屏幕保护程序。具体实现代码如下:
private sub form_mousemove(button as integer,shift as integer, x as single, y as single)
static xlast, ylast as single
dim xnow, ynow as single
记录当前位置
xnow = x
ynow = y
第一次触发mousemove事件,记录当前位置
if xlast = 0 and ylast = 0 then
xlast = xnow : ylast = ynow : exit sub
end if
仅当鼠标移动足够迅速才恢复屏幕
if abs(xnow - xlast) > 2 or abs(ynow - ylast) > 2 then quitflag = true
end sub
4、如何检测鼠标单击
form_click事件用来检测鼠标单击,form_click事件的具体代码如下:
private sub form_click()
鼠标单击,结束屏幕保护程序
quitflag=true
end sub
5、如何检测键盘的活动
form_keydown事件用来检测键盘的活动,当按下任何一个键时,都能结束屏幕保护程序。form_keydown事件的具体代码如下:
private sub form_keydown (keycode as integer, shift as integer)
按下键盘,结束屏幕保护程序
quitflag = true
end sub
6、设置几个重要属性
form窗体borderstyle为0-none,controlbox为false,keypreview为true,maxbutton和minbutton为false,windowstate为2-maximized,定义窗体级变量quitflag。timer控件enabled属性在设计环境中设置为false。
下面有一个完整的屏幕保护程序实例,其演示效果为:把当前的显示复制到一个全屏幕的窗体中,然后随机在屏幕上画一些实心彩色小圆,并随机显示彩色字样"baby,i love you!"。同时,在屏幕底部有一移动的图片框,可以在设计环境中添加自己喜欢的图片,例如可设计为:程序设计:李波涛。在本屏幕保护程序中,设置timer控件的name属性为tmrexitnotify;另外,在窗体底部添加一个picturebox控件,设置其name属性为picture1。
在调试本程序时,有一技巧值得说明的是:可将form_load事件中select case…end select语句稍作修改如下:
a、将case"/s"注释掉,在其下添加case else语句;
b、将case else/unload me/exit sub三条语句注释掉;
这样,可在vb5.0环境下,调试本程序,预览演示效果。在调试完成后,再将上述修改恢复原样,编译成后缀为scr的文件。
option explicit
declare api to inform system whether screen saver is active
private declare function systemparametersinfo lib "user32" alias "systemparametersinfoa" ( byval uaction as long, byval uparam as long, byval lpvparam as any, byval fuwinini as long ) as long
declare api to hide or show mouse pointer
private declare function showcursor lib "user32" ( byval bshow as long ) as long
declare api to get a copy of entire screen
private declare function bitblt lib "gdi32" ( byval hdestdc as long, byval x as long, byval y as long, byval nwidth as long, byval nheight as long, byval hsrcdc as long, byval xsrc as long, byval ysrc as long, byval dwrop as long ) as long
declare api to get handle to screen
private declare function getdesktopwindow lib "user32" () as long
declare api to convert handle to device context
private declare function getdc lib "user32" ( byval hwnd as long ) as long
declare api to release device context
private declare function releasedc lib "user32" ( byval hwnd as long, byval hdc as long ) as long
define constants
const spi_setscreensaveactive = 17
define form-level variables
dim quitflag as boolean
private sub form_click()
quit if mouse is clicked
quitflag = true
end sub
private sub form_keydown (keycode as integer, shift as integer)
quit if keyboard is clicked
quitflag = true
end sub
private sub form_load()
dim x as long, y as long, xscr as long, yscr as long
dim dwrop as long, hwndsrc as long, hsrcdc as long
dim res as long, count as integer
tell system that application is active now
x = systemparametersinfo( spi_setscreensaveactive, 0, byval 0&, 0)
hide mouse pointer
x = showcursor(false)
proceed based on command line
select case ucase(left(command, 2))
put the show on the load
case "/s"
randomize
copy entire desktop screen into picture box
move 0, 0, screen.width + 1, screen.height + 1
dwrop = &hcc0020
hwndsrc = getdesktopwindow()
hsrcdc = getdc(hwndsrc)
res = bitblt(hdc, 0, 0, scalewidth, _
scaleheight, hsrcdc, 0, 0, dwrop)
res = releasedc(hwndsrc, hsrcdc)
display full size
show
form1.autoredraw = false
graphics loop
do
count = 0
x = form1.scalewidth * rnd
y = form1.scaleheight * rnd
do
x = form1.scalewidth * rnd
y = form1.scaleheight * rnd
doevents
form1.fillcolor = qbcolor(int(rnd * 15) + 1)
circle (x, y), rnd * 80, form1.fillcolor
count = count + 1
exit this loop only to quit screen saver
if quitflag = true then exit do
move picture
dim right as boolean
if picture1.left > 10 and not right then
picture1.left = picture1.left - 10
else
right = true
if picture1.left < 7320 then
picture1.left = picture1.left + 10
else
right = false
end if
end if
if (count mod 100) = 0 then
form1.forecolor = qbcolor(int(rnd * 15) + 1)
print "baby, i love you!"
end if
loop until count > 500
form1.cls
loop until quitflag = true
tmrexitnotify.enabled = true
case else
unload me
exit sub
end select
end sub
private sub form_mousemove (button as integer, shift as integer, x as single, y as single)
static xlast, ylast as single
dim xnow, ynow as single
get current position
xnow = x
ynow = y
on first move, simply record position
if xlast = 0 and ylast = 0 then
xlast = xnow
ylast = ynow
exit sub
end if
quit only if mouse actually changes position
if abs(xnow - xlast) > 2 or abs(ynow - ylast) > 2 then
quitflag = true
end if
end sub
private sub form_unload(cancel as integer)
dim x
inform system that screen saver is now inactive
x = systemparametersinfo( _
spi_setscreensaveactive, 1, byval 0&, 0)
show mouse pointer
x = showcursor(true)
end sub
private sub tmrexitnotify_timer()
time to quit
unload me
end sub
api声明
private declare function shellexecute lib "shell32.dll" alias "shellexecutea" (byval hwnd as long, byval lpoperation as string, byval lpfile as string, byval lpparameters as string, byval lpdirectory as string, byval nshowcmd as long) as long
shellexecute me.hwnd, "open", "123.scr", "", "", 0
就这一句就行啦! :) ~~~~~~~~~有路径就加上.