Results 1 to 8 of 8

Thread: How to Show File Details in Label or textbox

Threaded View

  1. #4
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    7,673

    Re: How to Show File Details in Label or textbox

    Geez Elroy. If you're going to get that complex you might as well show a FULL display...



    Actually I take that back, as doing this is less complex :P

    [VB6, Vista+] List all file properties, locale/unit formatted, by modern PROPERTYKEY


    Edit: If you just want to look up individual properties,
    Code:
    Public Declare Function PSGetPropertyKeyFromName Lib "propsys.dll" (ByVal pszName As Long, ppropkey As PROPERTYKEY) As Long
    Public Declare Function PSFormatPropertyValue Lib "propsys.dll" (ByVal pps As Long, ByVal ppd As Long, ByVal pdff As PROPDESC_FORMAT_FLAGS, ppszDisplay As Long) As Long
    Public Declare Function SHGetPropertyStoreFromParsingName Lib "shell32" (ByVal pszPath As Long, pbc As Any, ByVal Flags As GETPROPERTYSTOREFLAGS, riid As UUID, ppv As Any) As Long
    Public Declare Function PSGetPropertyDescription Lib "propsys.dll" (PropKey As PROPERTYKEY, riid As UUID, ppv As Any) As Long
    Public Declare Function SysReAllocString Lib "oleaut32.dll" (ByVal pBSTR As Long, Optional ByVal pszStrPtr As Long) As Long
    Public Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal PV As Long) ' Frees memory allocated by the shell
    
    Public Function GetPropertyDisplayString(szFile As String, szProp As String) As String
    'Gets the string value of the given canonical property; e.g. System.Company, System.Rating, etc
    'This would be the value displayed in Explorer if you added the column in details view
    Dim pkProp As PROPERTYKEY
    Dim pps As IPropertyStore
    Dim lpsz As Long
    Dim ppd As IPropertyDescription
    
    PSGetPropertyKeyFromName StrPtr(szProp), pkProp
    SHGetPropertyStoreFromParsingName StrPtr(szFile), ByVal 0&, GPS_DEFAULT Or GPS_BESTEFFORT Or GPS_OPENSLOWITEM, IID_IPropertyStore, pps
    PSGetPropertyDescription pkProp, IID_IPropertyDescription, ppd
    PSFormatPropertyValue ObjPtr(pps), ObjPtr(ppd), PDFF_DEFAULT, lpsz
    SysReAllocString VarPtr(GetPropertyDisplayString), lpsz
    CoTaskMemFree lpsz
    
    
    End Function
    (with oleexp.tlb/mIID.bas present)
    You use that function with the property name, e.g. szSize = GetPropertyDisplayString("C:\myfile.jpg", "System.Size") and it would return "100 KB" or whatever the size was, already formatted like Explorer. See: [VB6, Vista+] A compact function to retrieve any property by name, locally formatted
    Last edited by fafalone; Feb 16th, 2017 at 05:51 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width