选择显示字体大小

利用windows api获得系统高级功能


  vb无疑是最先进的编程工具之一,但在涉及windows 32位系统的核心编程方面——譬如一些高级功能的实现上,它仍然显得有些力不从心,这需要我们充分利用vb的强大的windows api函数调用能力来弥补。以下代码将向您展示如何利用windows api控制系统托盘(图标)区、开始菜单、任务栏以及禁用/起用ctrl-alt-del、退出网络登录、立即关机、重新启动等系统高级功能。

  启动vb6,建立一个标准exe工程,添加14个command按钮,caption属性依次为 “隐藏开始菜单”、“显示开始菜单”、“隐藏系统托盘”、“显示系统托盘”、“禁用 ctrl-alt-del”、“起用 ctrl-alt-del”、“隐藏任务栏”、“显示任务栏”、“立即重新启动”、“关机”、“退出网络登陆”、“显示关机对话框”,调整上述控件到适当位置,双击窗体,写入以下代码:

 


option explicit

private declare function findwindow lib "user32" alias "findwindowa" (byval lpclassname as string, byval lpwindowname as string) as long
'寻找窗口列表中第一个符合指定条件的顶级窗口
'lpclassname指向包含了窗口类名的空中止(c语言)字串的指针;或设为零,'表示接收任何类
'lpwindowname指向包含了窗口文本(或标签)的空中止(c语言)字串的指针;'或设为零,表示接收任何窗口标题



private declare function showwindow lib "user32" (byval hwnd as long, byval ncmdshow as long) as long
'控制窗口的可见性
'hwnd窗口句柄,要向这个窗口应用由ncmdshow指定的命令
'ncmdshow为窗口指定可视性方面的一个命令


 
private declare function findwindowex lib "user32" alias "findwindowexa" (byval hwnd1 as long, byval hwnd2 as long, byval lpsz1 as string, byval lpsz2 as string) as long
'在窗口列表中寻找与指定条件相符的第一个子窗口
'hwnd1在其中查找子的父窗口
'hwnd2从这个窗口后开始查找。这样便可利用对findwindowex的多次调用找到符合条件的所有子窗口。如设为零,表示从第一个子窗口开始搜索



private declare function exitwindowsex lib "user32" (byval uflags as long, byval dwreserved as long)
'退出windows,并用特定的选项重新启动



private declare function systemparametersinfo lib "user32" alias "systemparametersinfoa" (byval uaction as long, byval uparam as long, byref lpvparam as any, byval fuwinini as long) as long
'允许获取和设置数量众多的windows系统参数
'uaction指定要设置的参数



private const ewx_logoff = 0'中止进程,然后注销
private const ewx_shutdown = 1'关掉系统电源
private const ewx_reboot = 2'重新引导系统
private const ewx_force = 4'强迫中止没有响应的进程
private const spi_screensaverrunning = 97


private sub command1_click() '隐藏开始菜单
dim handle as long, findclass as long
findclass = findwindow("shell_traywnd", "")
handle = findwindowex(findclass, 0, "button", vbnullstring)
showwindow handle, 0
end sub



private sub command11_click() '起用 ctrl-alt-del
dim ret as integer
dim pold as boolean
ret = systemparametersinfo(spi_screensaverrunning, true, pold, 0)
end sub



private sub command12_click() '禁用 ctrl-alt-del
dim ret as integer
dim pold as boolean
ret = systemparametersinfo(spi_screensaverrunning, false, pold, 0)
end sub



private sub command13_click() '立即重新启动
exitwindowsex ewx_reboot, 0
end sub


private sub command14_click() '关机
exitwindowsex ewx_shutdown, 0
end sub


private sub command15_click() '退出网络登陆
exitwindowsex ewx_logoff, 0
end sub


private sub command16_click() '显示关机对话框
exitwindowsex ewx_force, 0
end sub


private sub command2_click() '显示开始菜单
dim handle as long, findclass as long
findclass = findwindow("shell_traywnd", "")
handle = findwindowex(findclass, 0, "button", vbnullstring)
showwindow handle, 1
end sub


private sub command5_click() '隐藏系统托盘
dim findclass as long, handle as long
findclass = findwindow("shell_traywnd", "")
handle = findwindowex(findclass, 0, "traynotifywnd", vbnullstring)
showwindow handle, 0
end sub


private sub command6_click() '显示系统托盘
dim findclass as long, handle as long
findclass = findwindow("shell_traywnd", "")
handle = findwindowex(findclass, 0, "traynotifywnd", vbnullstring)
showwindow handle, 1
end sub


private sub command7_click() '显示任务栏
dim findclass as long, findclass2 as long, parent as long, handle as long
findclass = findwindow("shell_traywnd", "")
findclass2 = findwindowex(findclass, 0, "rebarwindow32", vbnullstring)
parent = findwindowex(findclass2, 0, "mstaskswwclass", vbnullstring)
handle = findwindowex(parent, 0, "systabcontrol32", vbnullstring)
showwindow handle, 0
end sub


private sub command8_click() '隐藏任务栏
dim findclass as long, findclass2 as long, parent as long, handle as long
findclass = findwindow("shell_traywnd", "")
findclass2 = findwindowex(findclass, 0, "rebarwindow32", vbnullstring)
parent = findwindowex(findclass2, 0, "mstaskswwclass", vbnullstring)
handle = findwindowex(parent, 0, "systabcontrol32", vbnullstring)
showwindow handle, 1
end sub


private sub form_queryunload(cancel as integer, unloadmode as integer)
end
end sub


  本文中的部分api函数及其相应的常数较少用到,希望编程爱好者能够有所借鉴和斧正,如果有问题欢迎与我联系zouhero@china.com。


 


关键字 本文所属关键字

相关 与本文相关文章

分类 所有文章关键字导航

源码编程相关

Java   Asp   PHP   .Net   XML   C/C++   CGI   VB   Jsp   J2ee   J2se   J2me   EJB   Servlet   Tomcat   Resin   Struts   Weblogic   Eclipse   ANT   GUI   JMS   Web servise   IDEA   Webphere   Hibernate   Spring   Jboss   Applet   Swing   Socket   Javamail   Perl   Ajax   P2P   安全   模式   框架   测试   开源   游戏

SQL数据库相关

My-SQL   Ms-SQL   Access   DB2   Oracle   Sybase   SQLserver   索引   存储过程   加密   数据库   分页   视图  

手机无线相关

3G   Wap   CDMA   GRPS   GSM   IVR   彩信   短信   无线   增值业务

网页设计制作相关

HTML   CSS   网页配色   网页特效   Javascript   VBscript   Dreamweaver   Frontpage   JS   Web   网站设计

网站建设推广相关

建站经验   网站优化   网站排名   推广   Alexa

操作系统/服务器相关

Windows XP   Windows 2000   Windows 2003   Windows Me   Windows 9.x   Linux   UNIX   注册表   操作系统   服务器   应用服务器

图形图像多媒体相关

Photoshop   Fireworks   Flash   Coreldraw   Illustrator   Freehand   Photoimpact   多媒体   图形图像

标准 网站致力的规范

Valid CSS!

无不良内容,无不良广告,无恶意代码

Valid XHTML 1.0 Transitional

creativecommons