Created
October 20, 2011 18:46
-
-
Save blladnar/1301940 to your computer and use it in GitHub Desktop.
Save To Desktop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BOOL QuickSavePic( Bitmap* pBitmap, const CString& strFilename ) | |
{ | |
CString strExt = strFilename.Mid( strFilename.ReverseFind( NEVER_TRANSLATE('.') ) + 1 ); | |
strExt.MakeUpper(); | |
CString strFormat; | |
if ( strExt == NEVER_TRANSLATE("JPG") ) strFormat = NEVER_TRANSLATE("image/jpeg"); | |
if ( strExt == NEVER_TRANSLATE("JPEG") ) strFormat = NEVER_TRANSLATE("image/jpeg"); | |
if ( strExt == NEVER_TRANSLATE("GIF") ) strFormat = NEVER_TRANSLATE("image/gif"); | |
if ( strExt == NEVER_TRANSLATE("PNG") ) strFormat = NEVER_TRANSLATE("image/png"); | |
if ( strExt == NEVER_TRANSLATE("BMP") ) strFormat = NEVER_TRANSLATE("image/bmp"); | |
CLSID clsid; | |
if ( GetEncoderClsid( CStringW( strFormat ), &clsid ) == -1 ) | |
return FALSE; | |
if ( pBitmap->Save( CStringW( strFilename ), &clsid ) != Ok ) | |
return FALSE; | |
return TRUE; | |
} | |
void SaveToDesktop( Bitmap* bitmap ) | |
{ | |
CString desktopDir; | |
SHGetSpecialFolderPath( 0, desktopDir.GetBuffer( MAX_PATH ), CSIDL_DESKTOPDIRECTORY, FALSE ); | |
desktopDir.ReleaseBuffer(); | |
CString time; | |
SYSTEMTIME st; | |
GetLocalTime(&st); | |
time.Format( NEVER_TRANSLATE("%02d;%02d;%02d"), st.wHour, st.wMinute, st.wSecond ); | |
CString filename; | |
filename.Format( NEVER_TRANSLATE("%s\\%s.png"), desktopDir, time ); | |
QuickSavePic( bitmap, filename ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment