• VC 打开目录 打开上次打开目录


    //DirBrowser.h

    #pragma once

    class CDirBrowser
    {
    public:
    CDirBrowser (
    bool fRecent = false, const TCHAR* pszTitle = TEXT( "选择目录" ) );
    ~CDirBrowser( void );

    TCHAR
    * Show( void );
    private:

    BOOL m_fRecent;
    BROWSEINFO m_bi;
    LPITEMIDLIST m_pidl;
    LPMALLOC m_pMalloc;

    static INT CALLBACK BrowseCallbackProc(HWND hwnd,
    UINT uMsg,
    LPARAM lp,
    LPARAM pData);
    };
    // DirBrowser.cpp


    #include
    "StdAfx.h"

    #include
    <shlobj.h>
    #include
    "DirBrowser.h"

    TCHAR s_szRecent[ MAX_PATH ]
    = { 0 };


    CDirBrowser::
    CDirBrowser(
    bool fRecent /* = false */,
    const TCHAR* pszTitle /* = 选择目录 */
    )
    {
    m_fRecent
    = fRecent;
    memset( (
    void* )&m_bi, 0, sizeof( BROWSEINFO ) );
    m_pidl
    = NULL;
    m_pMalloc
    = NULL;

    m_bi.hwndOwner
    = NULL;
    m_bi.pszDisplayName
    = 0;
    m_bi.lpszTitle
    = pszTitle;
    m_bi.pidlRoot
    = 0;
    m_bi.ulFlags
    = BIF_RETURNONLYFSDIRS | BIF_STATUSTEXT;
    m_bi.lpfn
    = fRecent ? BrowseCallbackProc : NULL;
    }



    CDirBrowser::
    ~CDirBrowser(
    void
    )
    {
    if ( m_pMalloc != NULL ) {
    if ( m_pidl != NULL ) {
    m_pMalloc
    ->Free( m_pidl );
    }
    m_pMalloc
    ->Release( );
    }
    }




    INT
    CALLBACK
    CDirBrowser::
    BrowseCallbackProc(HWND hwnd,
    UINT uMsg,
    LPARAM lp,
    LPARAM pData
    )
    {
    if (uMsg == BFFM_INITIALIZED)
    {
    // WParam is TRUE since you are passing a path.
    // It would be FALSE if you were passing a pidl.
    SendMessage( hwnd, BFFM_SETSELECTION, TRUE, (LPARAM)s_szRecent );
    }
    return 0;
    }


    TCHAR
    *
    CDirBrowser::
    Show(
    void
    )
    {
    if ( SUCCEEDED( SHGetMalloc( &m_pMalloc ) ) )
    {
    m_pidl
    = SHBrowseForFolder( &m_bi );
    if ( m_pidl == NULL ) {
    return NULL;
    }

    TCHAR m_szPath[ MAX_PATH ]
    = { 0 };
    SHGetPathFromIDList( m_pidl, m_szPath );
    lstrcpy( s_szRecent, m_szPath );
    }

    return s_szRecent;
    }
  • 相关阅读:
    Ubuntu 12.04和MySQL5.5安装
    ORACLE DBA 常用命令
    ORACLE 常见错误及解决方法集锦
    oracle中imp命令详解
    iframe自适应高度 兼容所有
    Linux Oracle 11g dataguard物理standby的配置
    LINUX 常用命令
    【CF】【Dijkstra】E. Buy and Delete
    【网络流】对于拆点的一点思考
    【PTA】最小堆
  • 原文地址:https://www.cnblogs.com/lin1270/p/2024806.html
Copyright © 2020-2023  润新知