Win95系统API函数大揭秘[2]

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 showman 的 blog

hwnd as long
lpverb as string
lpfile as string
lpparameters as string
lpdirectory as string
nshow as long
hinstapp as long
lpidlist as long
lpclass as string
hkeyclass as long
dwhotkey as long
hicon as long
hprocess as long
end type
public const see_mask_invokeidlist = &hc
public const see_mask_nocloseprocess = &h40
public const see_mask_flag_no_ui = &h400

declare function shellexecuteex lib "shell32.dll" alias "shellexecuteex" _
(sei as shellexecuteinfo) as long
public function showproperties(filename as string, ownerhwnd as long) as long
dim sei as shellexecuteinfo
dim r as long
with sei
.cbsize = len(sei)
.fmask = see_mask_nocloseprocess or see_mask_invokeidlist or see_mask_flag_no_ui
.hwnd = ownerhwnd
.lpverb = "properties"
.lpfile = filename
.lpparameters = vbnullchar
.lpdirectory = vbnullchar
.nshow = 0
.hinstapp = 0
.lpidlist = 0
end with
r = shellexecuteex(sei)
showproperties = sei.hinstapp
end function
? 设置墙纸
墙纸是显示在桌面的图片或图像,是win95的一个重要窗口。你可以通过改变列表中的文件来选择多
姿多采的墙纸。墙纸为win95蒙上了一披美丽的面纱,我们可以利用systemparametersinfo函数来揭开
它的“神秘面纱”并亲手为她营造异样的风采。
在窗体中增加list1控件,窗体加入如下代码:
option explicit
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
const spi_setdeskwallpaper = 20
const spif_updateinifile = &h1 'update win.ini constant
const spif_sendwininichange = &h2 'update win.ini and tell everyone
private sub form_load()
dim temp as string
temp = inputbox("please input a directory", "changer", "c:\windows\")
if temp = "" then end 'cancel clicked
if right$(temp, 1) <> "\" then temp = temp + "\"
list1.tag = temp
temp = temp + "*.bmp" 'set the file filter (path + *.bmp)
temp = dir$(temp)
do while temp$ <> ""
temp = dir$
    if temp = "" then exit do
list1.additem temp
loop
list1.additem "(none)"
show
list1.setfocus
list1.listindex = 0
end sub
private sub list1_dblclick()
dim temp as string
dim bmpfile as string
temp = tag
if list1.text = "(none)" then
bmpfile = "(none)"
else
bmpfile = temp + (list1)
end if
systemparametersinfo spi_setdeskwallpaper, 0, byval bmpfile, spif_updateinifile
end sub

private sub list1_keypress(keyascii as integer)
if keyascii = 13 then list1_dblclick
end sub
马上试试,当场把你的墙纸改变啦(不变不收钱)!爽吧!
? 建立快捷键
win95中快捷方式提供了对常用程序和文档的访问捷径,你可以为桌面或文件夹中的任何程序、文档
或打印机添加快捷方式。vb5中利用fcreateshelllink函数可以为常用程序和文档快速建立建立快捷键。
fcreateshelllink的声明为:
private declare function fcreateshelllink lib "stkit432.dll" (byval lpstrfoldername as string,
byval lpstrlinkname as string, byval lpstrlinkpath as string, byval lpstrlinkargs as string)
as long
lpstrfoldername设置快捷方式的文件夹名称,lpstrlinkname设置快捷方式的标题名称,lpstrlinkpath
设置快捷方式所指向的应用程序的目录及文件名。简而言之,如下格式:
fcreateshelllink(destinationpath, shortcutname, sourcepathappname, "")
    如下代码在“桌面”上为“d:\path\appname.exe”应用程序建立名为"shortcut title"的快捷方
式。
private declare function fcreateshelllink lib "stkit432.dll" (byval lpstrfoldername as string,
byval lpstrlinkname as string, byval lpstrlinkpath as string, byval lpstrlinkargs as string)
as long
private sub form_click()
lresult = fcreateshelllink("....\windows\desktop", "shortcut title", "d:\path\appname.exe",
"")
end sub
技巧:
如果想在“桌面”上建立快捷方式,则建立目标目录应该为“....\windows\desktop”; 如果想在
“开始”菜单中建立快捷方式,则建立目标目录应该为“....\windows\start menu”; 如果想在“程
序”菜单中建立快捷方式,则建立目标目录应该为相应的“....c:\windows\start menu\programs”中,
以此类推。
? 确定内存
我们经常要访问windows管理的内存。对应用程序性能影响最大的因素是可用的内存容量,访问系
统内存在处理类似于位图文件之类的大文件时非常有用,因为程序通过交换文件(swap)的方法,可以
获得比实际可用内存更大的内存。知道内存如何分配后,就可以读入内存值并操作大型数字文件。可以
用丰富的win32 api函数确定windows 的全局内存并操作数据文件,这些对于确定程序能否正常工作非
常有用。
dwlength                 数据结构的长度
dwmemoryload             内存使用百分比
dwtotalphys             实际内存总字节数
dwavailphys             可用的实际内存字节数
dwtotalpagefile        分页文件总字节数
dwavailpagefile        分页文件可用字节数
dwtotalvirtual             虚拟内存的总字节数
dwavailvirtual             可用的虚拟内存字节数
加入代码如下的模块:
type memorystatus
dwlength as long
dwmemoryload as long
dwtotalphys as long
dwavailphys as long
dwtotalpagefile as long
dwavailpagefile as long
dwtotalvirtual as long
dwavailvirtual as long
end type

本文关键:vb
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top