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

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

编程打开我的电脑

发布: 2007-7-01 20:40 | 作者: admin | 来源: | 查看: 13次 | 进入软件测试论坛讨论

领测软件测试网

编程打开我的电脑

许多工具类软件都有一些方便用户操作电脑的功能,如点个按钮或按一下热键

就实现关机功能,或更改墙纸,或缩定机器,等等.

这类软件一般会有一个浮动工具条,象金山快译的那种,或停在系统托盘里,

大大方便了用户.

但是,有些功能虽然没有什么技术难度,却难以从一般的资料中找到,如编程打开我的电脑,下面我就给出实现该功能的代码.

Visual Basic的代码用了一种比较繁琐的过程,

不过如果你想执行更多的相关功能,有时就非次不可啦!

Const SW_SHOWNORMAL = 1

Public Const CSIDL_DESKTOP = &H0                 ´{desktop}
Public Const CSIDL_INTERNET = &H1                ´Inte.net Explorer (icon on desktop)
Public Const CSIDL_PROGRAMS = &H2                ´Start Menu\Programs
Public Const CSIDL_CONTROLS = &H3                ´My Computer\Control Panel
Public Const CSIDL_PRINTERS = &H4                ´My Computer\Printers
Public Const CSIDL_PERSONAL = &H5                ´My Documents
Public Const CSIDL_FAVORITES = &H6               ´{user name}\Favorites
Public Const CSIDL_STARTUP = &H7                 ´Start Menu\Programs\Startup
Public Const CSIDL_RECENT = &H8                  ´{user name}\Recent
Public Const CSIDL_SENDTO = &H9                  ´{user name}\SendTo
Public Const CSIDL_BITBUCKET = &HA               ´{desktop}\Recycle Bin
Public Const CSIDL_STARTMENU = &HB               ´{user name}\Start Menu
Public Const CSIDL_DESKTOPDIRECTORY = &H10       ´{user name}\Desktop
Public Const CSIDL_DRIVES = &H11                 ´My Computer
Public Const CSIDL_NETWORK = &H12                ´Network Neighborhood
Public Const CSIDL_WINDOWS = &H24                 ´GetWindowsDirectory()
Public Const CSIDL_SYSTEM = &H25                  ´GetSystemDirectory()
Public Const CSIDL_PROGRAM_FILES = &H26           ´C:\Program Files

Public Const MAX_PATH = 260
Public Const S_OK = 0

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

Public Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias
"SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long

Public Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" (ByVal
hwndOwner As Long, ByVal nFolder As Long, pidl As Long) As Long

Public Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal pv As Long)

--
´ got from website:
Private Function GetSpecialFolderLocation(CSIDL As Long) As String

     Dim sPath As String
     Dim pidl As Long

    ´fill the idl structure with the specified folder item
     If SHGetSpecialFolderLocation(0, CSIDL, pidl) = S_OK Then

       ´if the pidl is returned, initialize
       ´and get the path from the id list
        sPath = Space$(MAX_PATH)

        If SHGetPathFromIDList(ByVal pidl, ByVal sPath) Then

          ´return the path
           GetSpecialFolderLocation = Left(sPath, InStr(sPath, Chr$(0)) - 1)

        End If

       ´free the pidl
        Call CoTaskMemFree(pidl)

      End If

  End Function

Sub ShellExecuteDemo()
´
ShellExecute 0, "explore", "", "", GetSpecialFolderLocation(CSIDL_DRIVES),
SW_SHOWNORMAL

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认证国际软件测试工程师认证领测软件测试网