about uscontact

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.

ZEMNA.NET

Professional software development agency estalished in Indonesia. We offers website setup, web application development, fulfillment service, and etc.
Follow us
Follow us to get latest news and tutorials.
2022 - Copyright, All Rights Reserved, Made by ZEMNA.NET with ❤️
magnifiercrossmenu