#include #include //#include //#include #include //#include //std::ofstream out; #include /* void DebugTrace( const char* fmt, ... ) { va_list args; va_start( args, fmt ); unsigned int iBuffer = _vscprintf( fmt, args ) + 1; char* szBuffer = new char[ iBuffer ]; int iReturn = _vsnprintf( szBuffer, iBuffer, fmt, args ); va_end( args ); OutputDebugString( szBuffer ); out << szBuffer; delete [] szBuffer; } void DebugError() { LPTSTR pszMessage = 0; DWORD dwLastError = GetLastError(); FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, dwLastError, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&pszMessage, 0, NULL ); std::stringstream ssError; if( dwLastError == 0 ) ssError << " No Windows Error\n"; else { ssError << " Windows Error: " << dwLastError; if( pszMessage != NULL ) ssError << ": " << pszMessage; } DebugTrace( ssError.str().c_str() ); LocalFree(pszMessage); SetLastError( 0 ); } */ bool SimplifyClipboard() { // DebugTrace( "SimplifyClipboard!\n" ); /* std::map tMap; tMap[CF_BITMAP] = "CF_BITMAP"; tMap[CF_DIB] = "CF_DIB"; tMap[CF_DIBV5] = "CF_DIBV5"; tMap[CF_DIF] = "CF_DIF"; tMap[CF_DSPBITMAP] = "CF_DSPBITMAP"; tMap[CF_DSPENHMETAFILE] = "CF_DSPENHMETAFILE"; tMap[CF_DSPMETAFILEPICT] = "CF_DSPMETAFILEPICT"; tMap[CF_DSPTEXT] = "CF_DSPTEXT"; tMap[CF_ENHMETAFILE] = "CF_ENHMETAFILE"; tMap[CF_HDROP] = "CF_HDROP"; tMap[CF_LOCALE] = "CF_LOCALE"; tMap[CF_METAFILEPICT] = "CF_METAFILEPICT"; tMap[CF_OEMTEXT] = "CF_OEMTEXT"; tMap[CF_OWNERDISPLAY] = "CF_OWNERDISPLAY"; tMap[CF_PALETTE] = "CF_PALETTE"; tMap[CF_PENDATA] = "CF_PENDATA"; tMap[CF_RIFF] = "CF_RIFF"; tMap[CF_SYLK] = "CF_SYLK"; tMap[CF_TEXT] = "CF_TEXT"; tMap[CF_WAVE] = "CF_WAVE"; tMap[CF_TIFF] = "CF_TIFF"; tMap[CF_UNICODETEXT] = "CF_UNICODETEXT"; tMap[CF_GDIOBJFIRST] = "CF_GDIOBJFIRST"; tMap[CF_GDIOBJLAST] = "CF_GDIOBJLAST"; tMap[CF_PRIVATEFIRST] = "CF_PRIVATEFIRST"; tMap[CF_PRIVATELAST] = "CF_PRIVATELAST"; */ bool bSuccess = true; if( !OpenClipboard( NULL ) ) return false; /* int iFormat = 0; while( iFormat = EnumClipboardFormats( iFormat ) ) { DebugTrace( "FORMAT: %s (%i)\n", tMap[iFormat].c_str(), iFormat ); } */ HANDLE hFiles = GetClipboardData( CF_HDROP ); if( hFiles ) { std::list tList; int iCount = DragQueryFile( (HDROP)hFiles, 0xFFFFFFFF, NULL, 0 ); for( int i=0; i=0; --j ) { if( strFile[j] == '/' || strFile[j] == '\\' ) break; } ++j; std::string strTmp = strFile.substr( j ); tList.push_back( strTmp ); } tList.sort(); std::string strText; for( std::list::iterator it = tList.begin(); it!=tList.end(); ++it ) { strText += (*it); strText += "\r\n"; } HGLOBAL hglbCopy = GlobalAlloc( GMEM_MOVEABLE, ( strText.length() + 1 ) * sizeof(TCHAR) ); if( !hglbCopy ) bSuccess = false; else if( !EmptyClipboard() ) bSuccess = false; else { LPSTR lptstrCopy = reinterpret_cast( GlobalLock( hglbCopy ) ); memcpy( lptstrCopy, strText.c_str(), strText.length() * sizeof(TCHAR)); lptstrCopy[strText.length()] = (TCHAR)0; GlobalUnlock( hglbCopy ); if( !SetClipboardData( CF_TEXT, hglbCopy ) ) bSuccess = false; } } else { HANDLE hData = GetClipboardData( CF_TEXT ); if( !hData ) bSuccess = false; else if( !EmptyClipboard() ) bSuccess = false; else if( !SetClipboardData( CF_TEXT, hData ) ) bSuccess = false; } if( !CloseClipboard() ) return false; return bSuccess; } int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow ) { // out.open( "output.txt", 'w' ); if( !SimplifyClipboard() ) return 1; return 0; }