파일 존재 유무/ Size 알아오기 VC++ 2007/10/08 14:19 |
//AnimatedCursor로그하기
HCURSORLoadCursorFromResource(HINSTANCEinstance,DWORDresourceId,constchar*resourceType)
{
HRSRChResource=FindResource(instance,MAKEINTRESOURCE(resourceId),resourceType);
if(!hResource)
returnNULL;
HGLOBALhGlobal=LoadResource(instance,hResource);
if(!hGlobal)
returnNULL;
LPBYTElockedBytes=reinterpret_cast<LPBYTE>(LockResource(hGlobal));
if(!lockedBytes)
returnNULL;
charpath[1024]={0,};
GetTempPath(ARRAYSIZE(path),path);
charfileName[1024]={0,};
GetTempFileName(path,"TempCursor",resourceId,fileName);
FILE*file=fopen(fileName,"wb");
if(!file)
returnNULL;
fwrite(lockedBytes,SizeofResource(instance,hResource),1,file);
fclose(file);
HCURSORhCursor=LoadCursorFromFile(fileName);
DeleteFile(fileName);
returnhCursor;
}
//파일존재체크
boolIsFileExist(constchar*path)
{
DWORDattr=GetFileAttributes(path);
return(attr!=INVALID_FILE_ATTRIBUTES)&&((attr&FILE_ATTRIBUTE_DIRECTORY)==0);
}
//디렉터리존재체크
boolIsDirectoryExist(constchar*path)
{
DWORDattr=GetFileAttributes(path);
return(attr!=INVALID_FILE_ATTRIBUTES)&&(attr&FILE_ATTRIBUTE_DIRECTORY);
}
//파일사이즈구하기
intGetFileSize(constchar*path)
{
WIN32_FILE_ATTRIBUTE_DATAfileInfo;
BOOLsucceeded=GetFileAttributesEx(
path,GetFileExInfoStandard,reinterpret_cast<void*>(&fileInfo));
if(!succeeded)
return-1;
Assert(0==fileInfo.nFileSizeHigh);
returnstatic_cast<int>(fileInfo.nFileSizeLow);
}
{
HANDLE hFile = ::CreateFile(szPath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile != INVALID_HANDLE_VALUE)
{
DWORD dwHighSize = 0;
DWORD dwLowSize = ::GetFileSize(hFile, &dwHighSize);
::CloseHandle(hFile);
if (dwLowSize != INVALID_FILE_SIZE)
{
return (dwHighSize * ((double)MAXDWORD + 1) + dwLowSize);
}
}
return 0;
}
//윈도우종료시키기
#include<Windows.h>
BOOLMySystemShutdown()
{
HANDLEhToken;
TOKEN_PRIVILEGEStkp;
//Getatokenforthisprocess.
if(!OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY,&hToken))
returnFALSE;
//GettheLUIDfortheshutdownprivilege.
LookupPrivilegeValue(
NULL,SE_SHUTDOWN_NAME,&tkp.Privileges[0].Luid);
tkp.PrivilegeCount=1;//oneprivilegetoset
tkp.Privileges[0].Attributes=SE_PRIVILEGE_ENABLED;
//Gettheshutdownprivilegeforthisprocess.
AdjustTokenPrivileges(
hToken,FALSE,&tkp,0,(PTOKEN_PRIVILEGES)NULL,0);
if(GetLastError()!=ERROR_SUCCESS)
returnFALSE;
//Shutdownthesystemandforceallapplicationstoclose.
if(!ExitWindowsEx(EWX_SHUTDOWN|EWX_FORCE,
SHTDN_REASON_MAJOR_OPERATINGSYSTEM|
SHTDN_REASON_MINOR_UPGRADE|
SHTDN_REASON_FLAG_PLANNED))
returnFALSE;
returnTRUE;
}
//폴더찾아보기다이얼로그띄우기
std::stringBrowseFolder(constchar*title=NULL,HWNDowner=NULL)
{
::OleInitialize(NULL);
BROWSEINFObi;
::ZeroMemory(&bi,sizeof(BROWSEINFO));
bi.ulFlags=BIF_USENEWUI;
bi.hwndOwner=owner;
bi.lpszTitle=title;
boolresult=false;
charpath[_MAX_PATH]={0,};
LPITEMIDLISTidl=::SHBrowseForFolder(&bi);
if(idl!=NULL)
{
result=::SHGetPathFromIDList(idl,path)!=0;
::CoTaskMemFree(idl);
}
::OleUninitialize();
returnresult?std::string(path):"";
}
'Borland' 카테고리의 다른 글
HOWTO: 파일을 Internet Information Server에 업로드하는 방법 (308) | 2008.01.17 |
---|---|
예제: POST로 많은 양의 데이터를 요청할 때 HttpSendRequestEx를 사용하는 방법 (0) | 2008.01.17 |
폴더내 파일을 모두 찾아 특정 이름으로 변경 (0) | 2008.01.16 |
C++ Dev Journal / HTML user interface (31) | 2007.11.29 |
ActionToolBar에서 버튼 추가는 어떻게 하나요? (0) | 2007.11.29 |