• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

Windows未公开函数揭密——之二

发布: 2007-6-21 21:57 | 作者:   | 来源:   | 查看: 15次 | 进入软件测试论坛讨论

领测软件测试网

   
  Windows未公开函数揭密——之二

http://www.applevb.com

上一次我向大家介绍了如何利用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 otepad.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 otepad.exe", "Samples"
End Sub

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

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

延伸阅读

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备10010545号-5
技术支持和业务联系:info@testage.com.cn 电话:010-51297073

软件测试 | 领测国际ISTQBISTQB官网TMMiTMMi认证国际软件测试工程师认证领测软件测试网