vb基础 vb实例教程 api调用 控件使用 经验技巧 数据库操作 算法及技术 vb源码下载
  杀毒频道 | 短信频道 | 网络电视 | 论文中心 | 学上网 | 学软件 | 网页特效 | 电脑基础 | 返回首页  
  NCRE | 软考 | CET | 职称英语 | 司法考试 | 报关员 | 公务员 | CATTI | CPA考试  
  Html教程 | Css教程 | Xml教程 | Asp教程 | Asp.net | Php教程 | Jsp教程 | Linux教程 | QQ技巧  
Photoshop Illustrator ImageReady Maya教程 3D Max教程 Lightscape Coredraw教程 Authorware Autocad教程 Freehand教程
Access教程 Mysql教程 Sql server Oracle教程 Word教程 Excel教程 Powerpoint Frontpage Asp.net源码 Php源代码
Flash教程 Fireworks Dreamweaver C#教程 outlook教程 系统安装 vbscript教程 Javascript Jsp源代码 Asp源代码
您的位置:首页 >> vb教程

Windows未公开函数揭密 之二

  上一次我向大家介绍了如何利用Windows未公开函数实现关闭或重新启动Windows的功能。在这一期内我要向大家介绍如何使用Windows未公开函数实现调用Windows系统中的一些对话框的功能。其中包括如何调用系统的“运行程序“对话框、”查找文件“对话框、更改与文件相关联的图标对话框等等。
  首先在VB中建立一个新的工程文件,然后在Form1中加入五个CommandButton控件,不要改变它们的属性,然后在Form1的代码窗口中加入以下代码:

Option Explicit

Private Type BrowseInfo
hwndOwner As Long
pIDLRoot As Long
pszDisplayName As Long
lpszTitle As Long
ulFlags As Long
lpfnCallback As Long
lParam As Long
iImage As Long
End Type

Const BIF_RETURNONLYFSDIRS = 1
Const MAX_PATH = 260

Private Declare Function SHObjectProperties Lib "Shell32" Alias "#178" _
(ByVal hwndOwner As Long, _
ByVal uFlags As Long, _
ByVal lpstrName As String, _
ByVal lpstrPar As String) As Long

Private Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal hMem As Long)
Private Declare Function SHBrowseForFolder Lib "Shell32" (lpbi _
As BrowseInfo) As Long
Private Declare Function SHFindFiles Lib "Shell32" Alias "#90" _
(ByVal pIDLRoot As Long, _
ByVal pidlSavedSearch As Long) As Long

Private Declare Function GetFileNameFromBrowse Lib "Shell32" Alias "#63" ( _
ByVal hwndOwner As Long, _
ByVal lpstrFile As String, _
ByVal nMaxFile As Long, _
ByVal lpstrInitDir As String, _
ByVal lpstrDefExt As String, _
ByVal lpstrFilter As String, _
ByVal lpstrTitle As String) As Long

Private Declare Sub PickIconDlg Lib "Shell32" Alias "#62" (ByVal hwndOwner As Long, _
ByVal lpstrFile As String, ByVal nMaxFile As Long, lpdwIconIndex As Long)

Private Declare Function SHRunFileDlg Lib "Shell32" Alias "#61" _
(ByVal hOwner As Long, _
ByVal hIcon As Long, _
ByVal lpstrDirectory As String, _
ByVal szTitle As String, _
ByVal szPrompt As String, _
ByVal uFlags As Long) As Long

Private Sub Command1_Click()
SHRunFileDlg Form1.hWnd, Form1.Icon.Handle, "c:\windows", "运行程序演示", _
"在文本框中输入程序名或按浏览键查找程序", 0
End Sub

Private Sub Command2_Click()
Dim a As Long
Dim astr As String

astr = "c:\windows\notepad.exe"
PickIconDlg Form1.hWnd, astr, 1, a
End Sub

Private Sub Command3_Click()
Dim astr As String * 256
Dim bstr As String

bstr = "c:\windows"
GetFileNameFromBrowse Form1.hWnd, astr, 256, bstr, "*.txt", _
"文本文件 *.txt", "Open Sample"
Debug.Print astr
End Sub

Private Sub Command4_Click()
Dim lpIDList As Long
Dim udtBI As BrowseInfo

'初试化udtBI结构
With udtBI
.hwndOwner = Form1.hWnd
.ulFlags = BIF_RETURNONLYFSDIRS
End With

'弹出文件夹查看窗口
lpIDList = SHBrowseForFolder(udtBI)

If lpIDList Then
'查找文件
SHFindFiles lpIDList, 0
Call CoTaskMemFree(lpIDList)
End If
End Sub

Private Sub Command5_Click()
SHObjectProperties Form1.hWnd, 2, "c:\windows\notepad.exe", "Samples"
End Sub

Private Sub Form_Load()
Command1.Caption = "运行程序"
Command2.Caption = "更改图标"
Command3.Caption = "打开文件"
Command4.Caption = "查找文件"
Command5.Caption = "显示文件属性"
End Sub

运行程序,分别点击不同的按钮,就可以看到不同的按钮实现了对不同的系统对话框的调用

[返回]

编程语言 web开发 数据库 网络技术 操作系统 服务器 网页设计 图形设计 办公软件 常用软件 学电脑

Copyright© www.bianceng.cn Powered by 编程入门网 All Rights Reserved.
关于本站 | 版权声明 | 联系我们 | 友情链接 |
编程入门网 版权所有