您的位置:程序门 -> vb ->



帮我看下代码,关于shgetidlistfrompath,比较少见,不懂回答看了赚点知识也不错。


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


帮我看下代码,关于shgetidlistfrompath,比较少见,不懂回答看了赚点知识也不错。[已结贴,结贴人:jinder]
发表于:2007-06-23 10:17:57 楼主
private   declare   function   shgetidlistfrompath   lib   "shell32.dll "   alias   "#162 "   (byval   szpath   as   string)   as   long

private   sub   command1_click()
    rootdir   =   "c:\windows "
    idlistroot   =   1

    if   rootdir   =   " "   then
        idlistroot   =   0
    else
        if   dir(rootdir,   vbdirectory)   <>   " "   then
            idlistroot   =   shgetidlistfrompath(rootdir)   '将路径转为标识符
        end   if
    end   if
    debug.print   idlistroot
end   sub

为什么不管rootdir的路径赋予什么,idlistroot返回的值总是0,而我所给的路径系统里也都有,用逐句运行的方法测试看着它走过“idlistroot   =   shgetidlistfrompath(rootdir)”后idlistroot还是为0,是不是我哪里错了呢?
在网上搜过这函数,中文网站是寥寥无几的,只有在google里一些外国网站上提起过,可看了他们的应用也跟我差不多啊,但我的就是不行,直接复制他们的也不行,不解啊?????
发表于:2007-06-23 10:41:461楼 得分:100
private   declare   function   shgetidlistfrompath   lib   "shell32.dll "   alias   "#162 "   (byval   szpath   as   string)   as   long

private   sub   command1_click()
rootdir   =   "c:\windows "
idlistroot   =   1

if   rootdir   =   " "   then
idlistroot   =   0
else
if   dir(rootdir,   vbdirectory)   <>   " "   then
idlistroot   =   shgetidlistfrompath(strconv(rootdir,   vbunicode))  
end   if
end   if
debug.print   idlistroot
end   sub
发表于:2007-06-23 10:42:282楼 得分:0
shgetidlistfrompath(strconv(rootdir,   vbunicode))
发表于:2007-06-23 11:05:023楼 得分:0
若问题解决,请立即结帖。谢谢。
发表于:2007-06-23 21:39:064楼 得分:0
1楼给你解决了啊
发表于:2007-06-24 07:23:535楼 得分:0
楼主什么系统啊,我在中文xp   sp2   下测试没有问题

可以考虑先提升一下权限
发表于:2007-06-24 07:32:166楼 得分:0
'in   form:>

option   explicit

dim   m_sfolder                       as   string   'path   of   folder/file   returned   from   browseforfolder   dialog.
dim   m_sdisplayname             as   string   'item   text   returned   from   browseforfolder   dialog.

private   sub   cmdbrowse_click()
      dim   sfolder                     as   string

      m_sfolder   =   "d:\ "

      sfolder   =   browse(me.hwnd,   _
            bif_browseincludefiles   or   bif_statustext   or   bif_usenewui,   _
            m_sfolder,   _
            m_sdisplayname,   _
            "title: ",   _
            "dialog   title:   ",   _
            " ")

      debug.print   sfolder   &   vbcrlf   &   _
            "displayname:   "   &   m_sdisplayname

end   sub

'----------------------------
'in   module:

option   explicit

private   const   wm_user       as   long   =   &h400&

'   message   from   browser
private   const   bffm_initialized   as   long   =   1
private   const   bffm_selchanged   as   long   =   2
private   const   bffm_setstatustexta   as   long   =   (wm_user   +   100)
private   const   bffm_setselectiona   as   long   =   (wm_user   +   102)

private   const   max_path     as   long   =   260

private   type   browseinfoa
      howner                               as   long
      pidlroot                           as   long
      pszdisplayname               as   string
      lpsztitle                         as   string
      ulflags                             as   long
      lpfn                                   as   long
      lparam                               as   long
      iimage                               as   long
end   type

public   enum   bif
      bif_returnonlyfsdirs   =   &h1                 '   for   finding   a   folder   to   start   document   searching
      bif_dontgobelowdomain   =   &h2               '   for   starting   the   find   computer
      bif_statustext   =   &h4                             '   top   of   the   dialog   has   2   lines   of   text   for   browseinfo.lpsztitle   and   one   line   if
      '   this   flag   is   set.     passing   the   message   bffm_setstatustexta   to   the   hwnd   can   set   the
      '   rest   of   the   text.     this   is   not   used   with   bif_usenewui   and   browseinfo.lpsztitle   gets
      '   all   three   lines   of   text.
      bif_returnfsancestors   =   &h8
      bif_editbox   =   &h10                                 '   add   an   editbox   to   the   dialog
      bif_validate   =   &h20                               '   insist   on   valid   result   (or   cancel)

      bif_newdialogstyle   =   &h40                   '   use   the   new   dialog   layout   with   the   ability   to   resize
      '   caller   needs   to   call   oleinitialize()   before   using   this   api

      bif_usenewui   =   (bif_newdialogstyle   or   bif_editbox)
      bif_browseincludeurls   =   &h80             '   allow   urls   to   be   displayed   or   entered.   (requires   bif_usenewui)
      bif_uahint   =   &h100                                 '   add   a   ua   hint   to   the   dialog,   in   place   of   the   edit   box.   may   not   be   combined   with   bif_editbox
      bif_nonewfolderbutton   =   &h200           '   do   not   add   the   "new   folder "   button   to   the   dialog.     only   applicable   with   bif_newdialogstyle.
      bif_notranslatetargets   =   &h400         '   don 't   traverse   target   as   shortcut
      bif_browseforcomputer   =   &h1000         '   browsing   for   computers.
      bif_browseforprinter   =   &h2000           '   browsing   for   printers
      bif_browseincludefiles   =   &h4000       '   browsing   for   everything
      bif_shareable   =   &h8000                         '   sharable   resources   displayed   (remote   shares,   requires   bif_usenewui)
end   enum

private   declare   function   shbrowseforfoldera   lib   "shell32 "   (lpbrowseinfo   as   browseinfoa)   as   long
private   declare   function   shgetidlistfrompath   lib   "shell32 "   alias   "#162 "   (byval   szpath   as   string)   as   long
private   declare   function   shgetpathfromidlista   lib   "shell32 "   (byval   pidl   as   long,   byval   pszpath   as   string)   as   long
private   declare   function   sendmessage   lib   "user32 "   alias   "sendmessagea "   (byval   hwnd   as   long,   byval   wmsg   as   long,   byval   wparam   as   long,   byval   lparam   as   string)   as   long
private   declare   function   setwindowtexta   lib   "user32 "   (byval   hwnd   as   long,   byval   lpstring   as   string)   as   long
private   declare   sub   cotaskmemfree   lib   "ole32 "   (byval   pv   as   long)

private   buffer                     as   string   *   max_path
private   m_dialogtitle       as   string

private   m_startdir             as   string
private   m_bnewui                 as   boolean

public   function   browse(byval   hwnd   as   long,   optional   ulflags   as   bif   =   bif_returnonlyfsdirs,   optional   byval   sstartdir   as   string,   optional   byref   sdisplayname   as   string,   optional   byval   stitle   as   string,   optional   byval   sdialogtitle   as   string,   optional   byval   srootdir   as   string)   as   string

      dim   bia                             as   browseinfoa
      dim   pidl                           as   long

      m_startdir   =   sstartdir
      m_dialogtitle   =   sdialogtitle
      m_bnewui   =   (ulflags   and   bif_newdialogstyle)   =   bif_newdialogstyle

      with   bia   'fill   the   browseinfo   structure.
            .howner   =   hwnd     'getdesktopwindow()   'can   be   application   or   desktop   hwnd

            if   lenb(srootdir)   then   'get   pidl   of   root   folder
                  .pidlroot   =   shgetidlistfrompath(strconv(srootdir,   vbunicode))
            else
                  .pidlroot   =   0&   'desktop   folder   is   used
            end   if

            .pszdisplayname   =   buffer           'display   name

            if   lenb(stitle)   then
                  .lpsztitle   =   stitle       'title   text
            end   if

            .ulflags   =   ulflags   'dialog   type.

            .lpfn   =   getaddressoffunction(addressof   browsecallbackproc)   'callback
      end   with

      pidl   =   shbrowseforfoldera(bia)     'show   the   dialog
      sdisplayname   =   stripnull(bia.pszdisplayname)

      browse   =   shgetpathfromidlist(pidl,   buffer)

end   function

private   function   browsecallbackproc(byval   hwnd   as   long,   byval   umsg   as   long,   byval   lp   as   long,   byval   pdata   as   long)   as   long
      dim   sbuffer                     as   string

      on   error   resume   next     'suggested   by   ms   to   prevent   an   error   from
      'propagating   back   into   the   calling   process.

      select   case   umsg
            case   bffm_initialized
                  sendmessage   hwnd,   bffm_setselectiona,   1,   m_startdir
                  setwindowtexta   hwnd,   m_dialogtitle

            case   bffm_selchanged
                  sbuffer   =   space$(max_path)

                  if   shgetpathfromidlista(byval   lp,   sbuffer)   =   1   then
                        call   sendmessage(hwnd,   bffm_setstatustexta,   0,   sbuffer)
                  end   if

      end   select

      browsecallbackproc   =   0

end   function

'   this   function   allows   you   to   assign   a   function   pointer   to   a   vaiable.
private   function   getaddressoffunction(add   as   long)   as   long
      getaddressoffunction   =   add
end   function

private   function   shgetpathfromidlist(byval   pidl   as   long,   byval   pszpath   as   string)   as   string
      if   pidl   =   0   then   exit   function

      if   shgetpathfromidlista(byval   pidl,   pszpath)   then
            shgetpathfromidlist   =   stripnull(pszpath)
      end   if

      cotaskmemfree   pidl

end   function

private   function   stripnull(byval   strin   as   string)   as   string
      dim   nul                             as   long
      '   truncate   input   string   at   first   null.
      '   if   no   nulls,   perform   ordinary   trim.
      nul   =   instr(1,   strin,   vbnullchar,   vbbinarycompare)
      select   case   nul
            case   is   >   1
                  stripnull   =   left$(strin,   nul   -   1)
            case   1
                  stripnull   =   " "
            case   0
                  stripnull   =   trim$(strin)
      end   select
end   function

'----------------------
发表于:2007-06-24 07:53:257楼 得分:0
...............................
发表于:2007-06-24 12:50:478楼 得分:0
.........................
发表于:2007-06-24 13:01:339楼 得分:0
rainstormmaster(暴风雨   v2.0)   抄的code好像没用到shgetidlistfrompath,请仔细看看lz的问题。
发表于:2007-06-24 13:12:2410楼 得分:0
shgetidlistfrompath   api一般用在调用打开指定文件夹的对话框中,赋值于browseinfoa结构的pidlroot参数。
if   lenb(srootdir)   then   '得到指定文件夹的pidl
        .pidlroot   =   shgetidlistfrompath(strconv(srootdir,   vbunicode))     'unicode   string
else
        .pidlroot   =   0&   '否则用桌面文件夹
end   if
发表于:2007-06-24 13:30:3411楼 得分:0
哎呀,真不好意思啊,前天发了贴后这两天刚好比较忙,没来看,一楼就已经解决问题了,谢谢啊,原来还要加上这个东东的,虽然后边的朋友也都答对,不过分还是给一楼的朋友吧,谢谢你们咯,呵呵。(要是能加分的话我就都给你们加)
发表于:2007-06-24 13:44:5412楼 得分:0
非常奇怪,在管理的地方能看到100分全部给你了,可在这里却看到0分,不解。
发表于:2007-06-24 13:46:5313楼 得分:0
不知你收到了没有。。。
发表于:2007-06-25 08:54:5714楼 得分:0
//rainstormmaster(暴风雨   v2.0)   抄的code好像没用到shgetidlistfrompath,请仔细看看lz的问题。

在这里:

with   bia   'fill   the   browseinfo   structure.
.howner   =   hwnd   'getdesktopwindow()   'can   be   application   or   desktop   hwnd

if   lenb(srootdir)   then   'get   pidl   of   root   folder
.pidlroot   =   shgetidlistfrompath(strconv(srootdir,   vbunicode))
else
.pidlroot   =   0&   'desktop   folder   is   used
end   if
发表于:2007-10-11 13:10:1015楼 得分:0
谢谢各位,都说得很好。


快速检索

最新资讯
热门点击