본문 바로가기

컴퓨터 과학 & 영상처리 관련/C / C++

C언어 바탕화면 경로 가져오는 함수 (레지스트리 이용)

http://cboard.cprogramming.com/windows-programming/11473-desktop-path.html


char* getDesktopFolderName()     //c:\Users\UserName\Desktop\ 반환

{

ULONG ulDataType;

HKEY hKey;

DWORD dwToRead = 100;

static char strPath[100];

char strKey[] = "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders";


//cannot use in unicode, use multi-byte code  http://blog.naver.com/stormor/70171786787

RegOpenKeyEx(HKEY_CURRENT_USER,

strKey,   //여기 unicode 안됨

 0,KEY_READ,&hKey);

RegQueryValueEx(hKey,"Desktop",NULL,

&ulDataType,(LPBYTE)strPath,&dwToRead);

strPath[dwToRead] = '\0';

RegCloseKey(hKey);


return strPath;


//http://cboard.cprogramming.com/windows-programming/11473-desktop-path.html

}




이거 말고도 MFC 방법으로 있긴 함





char* getDesktopFolderName()     //c:\Users\UserName\Desktop\ 반환

{

//http://stackoverflow.com/questions/17933917/get-the-users-desktop-folder-using-windows-api

//mfc함수이고 CSIDL_로 보면 경로들이 존나많다

//멀티 바이트로 안하면 (LPWSTR)desktopPath 해야됨..근데 멀티바이트 아니면 결과 안나옴

SHGetSpecialFolderPath(HWND_DESKTOP,myPathArray,CSIDL_DESKTOP,0);

//SHGetSpecialFolderPath(HWND_DESKTOP,(LPWSTR)desktopPath,CSIDL_DESKTOP,0);


return myPathArray;

}