데이터를 파일로 저장하는 프로그램을 만들다 보면은 꼭 필요한게
데이터 저장 폴더가 유효한지 아닌지 판단한는 일입니다.
그럴대 유용한 API 입니다.

PathIsDirectory Function


Verifies that a path is a valid directory.


Syntax

BOOL PathIsDirectory(LPCTSTR pszPath);


Parameters

pszPath
[in] A pointer to a null-terminated string of maximum length MAX_PATH that contains the path to verify.


Return Value

Returns TRUE if the path is a valid directory, or FALSE otherwise.


Function Information

Minimum DLL Version shlwapi.dll version 4.71 or later
Custom Implementation No
Header shlwapi.h
Import library shlwapi.lib
Minimum operating systems Windows 2000, Windows NT 4.0 with Internet Explorer 4.0, Windows 98, Windows 95 with Internet Explorer 4.0
Unicode Implemented as ANSI and Unicode versions.

posted by 뚱2

WINDOWS API 폴더 선택

C/C++/VC++ / MFC 2011. 1. 21. 21:49
윈도우 프로그래밍을 하다보면은 많이 사용하는 파일, 색상, 폰트, 프린트 등을 공통대화상자로 만들어두워
재사용 할수 있게 했습니다.

그런데 이상하게도 폴더를 선택할수 있는 공통대화 상자는 없습니다. 다른 것보다 덜 사용해서 그런지...
없다고 안되는건 아니고 Shell쪽에서 함수를 제공하고 있습니다.

간단하게 다음과 같이 사용하실수 있습니다.

BOOL ChoiceFolder(HWND hWndOwner, TCHAR* pszFolderPath)
{
	ASSERT( IsWindow(hWndOwner) == TRUE && pszFolderPath != NULL);
	
	LPITEMLIST pidl;
	BROWSEINFO bi;

	bi.hwndOwner      = hWndOwner;
	bi.pidRoot        = NULL;
	bi.pszDisplayName = NULL;
	bi.lpszTitle      = _T("폴더를 선택해 주세요.");
	bi.ulFlags        = BIF_NEWDIALOGSTYLE|BIF_EDITBOX|BIF_RETURNONLYFSDIRS;
	bi.lpfn           = NULL;
	bi.lParam         = 0;

	pidl = SHBrowseForFolder(&bi);
	if ( pidl == NLULL)
		return FALSE;
	
   	return SHGetPathFromIDList(pidl, pszFolderPath);
}



posted by 뚱2