SHBrowseForFolder() Function

Category:
Author: zemna
Date: April 17, 2021
Share this:

SHBrowseForFolder() Function

//CALLBACK Function 원형 선언

static int CALLBACK BrowseCallback(HWND hWnd, UINT uMsg, LPARAM lParam, LPARAM lpData);

//CALLBACK Function 구현

int CALLBACK BrowseCallback(HWND hWnd, UINT uMsg, LPARAM lParam, LPARAM lpData)

{

switch(uMsg)

{

case BFFM_INITIALIZED:

::SendMessage(hWnd, BFFM_SETSELECTION, TRUE, lpData);

//::SendMessage(hWnd, BFFM_SETSELECTION, TRUE, (DWORD)"D:");

break;

}

return 0;

}

// 폴더선택 함수내에서 ...

{

#ifndef BIF_NEWDIALOGSTYLE //"New Folder" 버튼 생성을 위해서 선언

#define BIF_NEWDIALOGSTYLE 0x0040

#endif

char pszPathname[MAX_PATH]; // 폴더경로를 받아올 변수선언

LPMALLOC pBrowseSpace; //IDLIST 공간 할당 , 해제용 변수

ITEMIDLIST *pRootID, *pBrowseID;

BROWSEINFO BrInfo;

SHGetMalloc(&pBrowseSpace);

SHGetSpecialFolderLocation(this->m_hWnd,CSIDL_DESKTOP,&pRootID);

BrInfo.hwndOwner = GetSafeHwnd();

BrInfo.lpfn = BrowseCallback;

BrInfo.lpszTitle = "Select Folder";

BrInfo.pszDisplayName = pszPathname;

BrInfo.pidlRoot = pRootID;

BrInfo.ulFlags = BIF_NEWDIALOGSTYLE | BIF_RETURNONLYFSDIRS;

BrInfo.lParam = (LPARAM)"D:"; //lParam 값으로 기본폴더 지정 가능

pBrowseID = ::SHBrowseForFolder(&BrInfo);

if(pBrowseID != NULL)

SHGetPathFromIDList(pBrowseID,pszPathname);

MessageBox(pszPathname);

pBrowseSpace->Free(pBrowseID);

pBrowseSpace->Free(pRootID);

pBrowseSpace->Release();

}

Share this:

Leave a Reply

Your email address will not be published. Required fields are marked *

Let's connect and create
something awesome together!
2023 - Copyright, All Rights Reserved, Made by ZEMNA.NET with ❤️
crossmenu linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram