游戏开发论坛

 找回密码
 立即注册
搜索
查看: 2894|回复: 0

浏览对话框

[复制链接]

38

主题

96

帖子

148

积分

注册会员

Rank: 2

积分
148
发表于 2004-2-13 12:59:00 | 显示全部楼层 |阅读模式
//代码名称: 浏览对话框
//类别:       控件 公用对话框
//关健字:    对话框 浏览
//作者:       EasySL
//编译器:    VC
//操作系统: windows

#include <windows.h>
#include <tchar.h>
#include <shlobj.h>

char *BrowseBox( HWND hWnd, char *s, int length )
{
    if( length < MAX_PATH )
        return NULL;

    //char processdir[MAX_PATH];
    HWND hwndOwner = hWnd;
    LPCSTR  lpszTitle = "BrowseBox";
    //CString strSelIniDir;
    //CString strDirPathSelected;
    char strSelIniDir[MAX_PATH] = "";
    char strDirPathSelected[MAX_PATH] = "";

    /* Work's only if we're 95 capable or up*/
    BOOL bRe = FALSE;

    LPMALLOC pMalloc;

    BROWSEINFO bi;
    TCHAR pszBuffer[MAX_PATH];

    LPITEMIDLIST pidl = NULL;
    LPITEMIDLIST pidlIni = NULL;

    LPSHELLFOLDER ppshf = NULL;

    OLECHAR szOleChar[MAX_PATH];
    ULONG ulEaten, ulAttribs;

    //if(strSelIniDir.IsEmpty() == FALSE)
    {
        /* Get's the Shell's default allocator */
        if (SHGetMalloc(&pMalloc) != NOERROR)
        {
            goto crash;
        }
        // Get's the Shell's desktop folder Interface
        if(! SUCCEEDED(SHGetDesktopFolder(&ppshf)) )
        {
            goto crash;
        }
        // Conver to UNICODE string
        MultiByteToWideChar(CP_ACP,
            MB_PRECOMPOSED,
            strSelIniDir,
            -1,
            szOleChar,
            sizeof(szOleChar));
        //
        if(! SUCCEEDED(ppshf-&gtarseDisplayName(hwndOwner,NULL,szOleChar,
            &ulEaten,&pidlIni,&ulAttribs)))
            goto crash;
    }

    // Get help on BROWSEINFO struct - it's got all the bit settings
    bi.hwndOwner = hwndOwner;
    bi.pidlRoot = pidlIni;
    bi.pszDisplayName = pszBuffer;
    bi.lpszTitle = lpszTitle;
    bi.ulFlags = BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS
        | BIF_RETURNONLYFSDIRS ;
    bi.lpfn = NULL; bi.lParam = 0;

    // This next call issues the dialog box
    if ((pidl = SHBrowseForFolder(&bi)) != NULL)
    {
        if (SHGetPathFromIDList(pidl, pszBuffer))
        {
            //At this point pszBuffer contains the selected path

            //strDirPathSelected = pszBuffer;
            strcpy( strDirPathSelected, pszBuffer );
            strcpy(s,pszBuffer);
            strcat(s,"\\");
        }

        bRe = TRUE;
    }

    return s;
crash:
    return NULL;
}
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2025-2-25 05:57

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表