Skip to content

Instantly share code, notes, and snippets.

@blladnar
Created October 20, 2011 18:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blladnar/1301940 to your computer and use it in GitHub Desktop.
Save blladnar/1301940 to your computer and use it in GitHub Desktop.
Save To Desktop
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