win32comutils.cpp

来自「这是VCF框架的代码」· C++ 代码 · 共 1,149 行 · 第 1/2 页

CPP
1,149
字号
				if ( i > 0 ) {					data += "\n";				}				data += fp;			}			result->addSupportedDataType( dataType, new BinaryPersistable( (const unsigned char*)data.c_str(), data.size_in_bytes() ) );		}	}	else {		result = new VCF::DataObject();		result->addSupportedDataType( dataType, new BinaryPersistable( (unsigned char*)rawGlobalMem, memSize ) );	}	::GlobalUnlock( stg.hGlobal );	return result;}VCF::Persistable* COMUtils_createPersistableFromHGlobal( STGMEDIUM& stg, const VCF::String& dataType ){	VCF::Persistable* result = NULL;	char* rawGlobalMem = (char*)::GlobalLock( stg.hGlobal );	ulong32 memSize = GlobalSize( stg.hGlobal );	if ( (dataType == L"image/bmp" ) || (dataType == IMAGE_DATA_TYPE) ) {		BasicInputStream bis( rawGlobalMem, memSize );		Image* image = GraphicsToolkit::createImage(1,1);		result = dynamic_cast<VCF::Persistable*>(image);		bis >> result;	}	else if ( dataType == FILE_DATA_TYPE ) {		ulong32 count = DragQueryFile((HDROP)stg.hGlobal, (UINT)-1, NULL, 0);		if ( count > 0 ) {			String data;			FilePath fp;			bool unicodeEnabled = System::isUnicodeEnabled();			for ( int i=0;i<count;i++ ) {				if ( unicodeEnabled ) {					VCFChar tmp[MAX_PATH];					DragQueryFileW((HDROP)stg.hGlobal, i, tmp, MAX_PATH-1 );					fp = String(tmp);				}				else {					char tmp[MAX_PATH];					DragQueryFileA((HDROP)stg.hGlobal, i, tmp, MAX_PATH-1 );					fp = String(tmp);				}				if ( i > 0 ) {					data += "\n";				}				data += fp;			}			result = new BinaryPersistable( (const unsigned char*)data.c_str(), data.size_in_bytes() );		}	}	else {		result = new BinaryPersistable( (unsigned char*)rawGlobalMem, memSize );	}	::GlobalUnlock( stg.hGlobal );	return result;}//#define MAP_PIX_TO_LOGHIM(x,ppli)   ( (HIMETRIC_PER_INCH*(x) + ((ppli)>>1)) / (ppli) )//#define MAP_LOGHIM_TO_PIX(x,ppli)   ( ((ppli)*(x) + HIMETRIC_PER_INCH/2) / HIMETRIC_PER_INCH )void COMUtils_HiMetricToPixel( const SIZE& sizeInHiMetric, SIZE& sizeInPix ){	const int HIMETRIC_PER_INCH = 2540;	HDC hDCScreen = GetDC(::GetDesktopWindow());	// Pixels per logical inch along width	int pixelsPerInchX = GetDeviceCaps(hDCScreen, LOGPIXELSX);	// Pixels per logical inch along height	int pixelsPerInchY = GetDeviceCaps(hDCScreen, LOGPIXELSY);	ReleaseDC(::GetDesktopWindow(), hDCScreen);	sizeInPix.cx = (pixelsPerInchX * sizeInHiMetric.cx + (HIMETRIC_PER_INCH/2)) / HIMETRIC_PER_INCH;	sizeInPix.cy = (pixelsPerInchY * sizeInHiMetric.cy + (HIMETRIC_PER_INCH/2)) / HIMETRIC_PER_INCH;}VCF::Persistable* COMUtils::getPersistableFromOLEDataObject( const VCF::String dataType, IDataObject* oleDataObject, FORMATETC* fmtETC ){	VCF::Persistable* result = NULL;	HRESULT hr = oleDataObject->QueryGetData( fmtETC );	if ( SUCCEEDED(hr) ) {		STGMEDIUM stg;		memset( &stg, 0, sizeof(STGMEDIUM) );		hr = oleDataObject->GetData( fmtETC, &stg );		if ( SUCCEEDED(hr) ) {			switch( stg.tymed ) {				case TYMED_HGLOBAL : {					result = COMUtils_createPersistableFromHGlobal( stg, dataType );				}				break;				case TYMED_GDI : {					BITMAP bmp;					memset( &bmp, 0, sizeof(BITMAP) );					int err = ::GetObject( stg.hBitmap, sizeof(BITMAP), &bmp );					if ( 0 == err ) {						//throw an exception - failed top get bitmap info					}					Image* image = GraphicsToolkit::createImage( bmp.bmWidth, bmp.bmHeight );					Win32Image* win32Image = dynamic_cast<Win32Image*>( image );					HDC dc = win32Image->getDC();					HDC tmpDC = ::CreateCompatibleDC( NULL );					HBITMAP oldBMP = (HBITMAP)::SelectObject( tmpDC, stg.hBitmap );					err = ::BitBlt( dc, 0, 0, bmp.bmWidth, bmp.bmHeight, tmpDC, 0, 0, SRCCOPY );					::SelectObject( tmpDC, oldBMP );					::DeleteDC( tmpDC );					result = dynamic_cast<Persistable*>( image );				}				break;				case TYMED_MFPICT : {					METAFILEPICT* metaFilePict = (METAFILEPICT*) GlobalLock( stg.hGlobal );					SIZE sz = { metaFilePict->xExt, metaFilePict->yExt };					SIZE sz2;					COMUtils_HiMetricToPixel( sz, sz2 );					Image* image = GraphicsToolkit::createImage( sz2.cx, sz2.cy );					Win32Image* win32Image = dynamic_cast<Win32Image*>( image );					HDC bmpDC = win32Image->getDC();					UINT oldMM = ::SetMapMode( bmpDC, metaFilePict->mm );					POINT pt = {0,0};					::SetViewportOrgEx( bmpDC, 0, 0, &pt );					SIZE viewPtExt = {0,0};					::SetViewportExtEx( bmpDC, sz2.cx, sz2.cy, &viewPtExt );					int err = PlayMetaFile( bmpDC, metaFilePict->hMF );					::SetMapMode( bmpDC, oldMM );					::SetViewportOrgEx( bmpDC, pt.x, pt.y, NULL );					::SetViewportExtEx( bmpDC, viewPtExt.cx, viewPtExt.cy, NULL );					if ( err ) {						result = dynamic_cast<Persistable*>( image );					}					else {						err = ::GetLastError();					}					::GlobalUnlock( stg.hGlobal );				}				break;				case TYMED_ENHMF : {					ENHMETAHEADER metaHdr;					memset( &metaHdr, 0, sizeof(ENHMETAHEADER) );					int err = GetEnhMetaFileHeader( stg.hEnhMetaFile, sizeof(ENHMETAHEADER), &metaHdr );					SIZE sz = {metaHdr.rclFrame.right-metaHdr.rclFrame.left,								metaHdr.rclFrame.bottom - metaHdr.rclFrame.top};					SIZE sz2;					COMUtils_HiMetricToPixel( sz, sz2 );					Image* image = GraphicsToolkit::createImage( sz2.cx, sz2.cy );					Win32Image* win32Image = dynamic_cast<Win32Image*>( image );					HDC bmpDC = win32Image->getDC();					UINT oldMM = ::SetMapMode( bmpDC, MM_TEXT );					POINT pt = {0,0};					::SetViewportOrgEx( bmpDC, 0, 0, &pt );					SIZE viewPtExt = {0,0};					::SetViewportExtEx( bmpDC, sz2.cx, sz2.cy, &viewPtExt );					err = PlayEnhMetaFile( bmpDC, stg.hEnhMetaFile, (RECT *)&metaHdr.rclBounds );					::SetMapMode( bmpDC, oldMM );					::SetViewportOrgEx( bmpDC, pt.x, pt.y, NULL );					::SetViewportExtEx( bmpDC, viewPtExt.cx, viewPtExt.cy, NULL );					if ( FALSE != err ) {						result = dynamic_cast<Persistable*>( image );					}				}				break;				case TYMED_ISTREAM : {				}				break;				case TYMED_ISTORAGE : {				}				break;			}			ReleaseStgMedium( &stg );		}	}	return result;}VCF::DataObject* COMUtils::getDataObjectFromOLEDataObject( const VCF::String dataType, IDataObject* oleDataObject, FORMATETC* fmtETC ){	VCF::DataObject* result = NULL;	HRESULT hr = oleDataObject->QueryGetData( fmtETC );	if ( SUCCEEDED(hr) ) {		STGMEDIUM stg;		memset( &stg, 0, sizeof(STGMEDIUM) );		hr = oleDataObject->GetData( fmtETC, &stg );		if ( SUCCEEDED(hr) ) {			switch( stg.tymed ) {				case TYMED_HGLOBAL : {					result = COMUtils_createFromHGlobal( stg, dataType );				}				break;				case TYMED_GDI : {					BITMAP bmp;					memset( &bmp, 0, sizeof(BITMAP) );					int err = ::GetObject( stg.hBitmap, sizeof(BITMAP), &bmp );					if ( 0 == err ) {						//throw an exception - failed top get bitmap info					}					Image* image = GraphicsToolkit::createImage( bmp.bmWidth, bmp.bmHeight );					Win32Image* win32Image = dynamic_cast<Win32Image*>( image );					HDC dc = win32Image->getDC();					HDC tmpDC = ::CreateCompatibleDC( NULL );					HBITMAP oldBMP = (HBITMAP)::SelectObject( tmpDC, stg.hBitmap );					err = ::BitBlt( dc, 0, 0, bmp.bmWidth, bmp.bmHeight, tmpDC, 0, 0, SRCCOPY );					::SelectObject( tmpDC, oldBMP );					::DeleteDC( tmpDC );					result = new ImageDataObject( image );					delete image;				}				break;				case TYMED_MFPICT : {					METAFILEPICT* metaFilePict = (METAFILEPICT*) GlobalLock( stg.hGlobal );					SIZE sz = { metaFilePict->xExt, metaFilePict->yExt };					SIZE sz2;					COMUtils_HiMetricToPixel( sz, sz2 );					Image* image = GraphicsToolkit::createImage( sz2.cx, sz2.cy );					Win32Image* win32Image = dynamic_cast<Win32Image*>( image );					HDC bmpDC = win32Image->getDC();					UINT oldMM = ::SetMapMode( bmpDC, metaFilePict->mm );					POINT pt = {0,0};					::SetViewportOrgEx( bmpDC, 0, 0, &pt );					SIZE viewPtExt = {0,0};					::SetViewportExtEx( bmpDC, sz2.cx, sz2.cy, &viewPtExt );					int err = PlayMetaFile( bmpDC, metaFilePict->hMF );					::SetMapMode( bmpDC, oldMM );					::SetViewportOrgEx( bmpDC, pt.x, pt.y, NULL );					::SetViewportExtEx( bmpDC, viewPtExt.cx, viewPtExt.cy, NULL );					if ( err ) {						result = new ImageDataObject( image );					}					else {						delete image;						err = ::GetLastError();					}					::GlobalUnlock( stg.hGlobal );				}				break;				case TYMED_ENHMF : {					ENHMETAHEADER metaHdr;					memset( &metaHdr, 0, sizeof(ENHMETAHEADER) );					int err = GetEnhMetaFileHeader( stg.hEnhMetaFile, sizeof(ENHMETAHEADER), &metaHdr );					SIZE sz = {metaHdr.rclFrame.right-metaHdr.rclFrame.left,								metaHdr.rclFrame.bottom - metaHdr.rclFrame.top};					SIZE sz2;					COMUtils_HiMetricToPixel( sz, sz2 );					Image* image = GraphicsToolkit::createImage( sz2.cx, sz2.cy );					Win32Image* win32Image = dynamic_cast<Win32Image*>( image );					HDC bmpDC = win32Image->getDC();					UINT oldMM = ::SetMapMode( bmpDC, MM_TEXT );					POINT pt = {0,0};					::SetViewportOrgEx( bmpDC, 0, 0, &pt );					SIZE viewPtExt = {0,0};					::SetViewportExtEx( bmpDC, sz2.cx, sz2.cy, &viewPtExt );					err = PlayEnhMetaFile( bmpDC, stg.hEnhMetaFile, (RECT *)&metaHdr.rclBounds );					::SetMapMode( bmpDC, oldMM );					::SetViewportOrgEx( bmpDC, pt.x, pt.y, NULL );					::SetViewportExtEx( bmpDC, viewPtExt.cx, viewPtExt.cy, NULL );					if ( FALSE != err ) {						result = new ImageDataObject( image );					}					delete image;				}				break;				case TYMED_ISTREAM : {				}				break;				case TYMED_ISTORAGE : {				}				break;			}			ReleaseStgMedium( &stg );		}	}	return result;}void COMUtils::registerDataTypes(){#if defined(VCF_CW) && defined(UNICODE)	VCFCOM::COMUtils::standardWin32DataTypes[STRING_DATA_TYPE] = CF_TEXT;	VCFCOM::COMUtils::standardWin32DataTypes[INTEGER_DATA_TYPE] = ::RegisterClipboardFormat( L"text/x-vcf-integer" );	VCFCOM::COMUtils::standardWin32DataTypes[OBJECT_DATA_TYPE] = ::RegisterClipboardFormat( L"application/x-vcf-object" );	VCFCOM::COMUtils::standardWin32DataTypes[FILE_DATA_TYPE] = CF_HDROP;	VCFCOM::COMUtils::standardWin32DataTypes[BYTE_STREAM_DATA_TYPE] = ::RegisterClipboardFormat( L"application/octet-stream" );	VCFCOM::COMUtils::standardWin32DataTypes[IMAGE_DATA_TYPE] = ::RegisterClipboardFormat( L"image/x-vcf-image" );	VCFCOM::COMUtils::standardWin32DataTypes["image/application-x-wmf"] = CF_METAFILEPICT;	VCFCOM::COMUtils::standardWin32DataTypes["image/application-x-emf"] = CF_ENHMETAFILE;	VCFCOM::COMUtils::standardWin32DataTypes["image/bmp"] = CF_BITMAP;	VCFCOM::COMUtils::standardWin32DataTypes[COMPONENT_DATA_TYPE] = ::RegisterClipboardFormat( L"text/x-vcf-vff" );#else	VCFCOM::COMUtils::standardWin32DataTypes[STRING_DATA_TYPE] = CF_TEXT;	VCFCOM::COMUtils::standardWin32DataTypes[INTEGER_DATA_TYPE] = ::RegisterClipboardFormat( "text/x-vcf-integer" );	VCFCOM::COMUtils::standardWin32DataTypes[OBJECT_DATA_TYPE] = ::RegisterClipboardFormat( "application/x-vcf-object" );	VCFCOM::COMUtils::standardWin32DataTypes[FILE_DATA_TYPE] = CF_HDROP;	VCFCOM::COMUtils::standardWin32DataTypes[BYTE_STREAM_DATA_TYPE] = ::RegisterClipboardFormat( "application/octet-stream" );	VCFCOM::COMUtils::standardWin32DataTypes[IMAGE_DATA_TYPE] = ::RegisterClipboardFormat( "image/x-vcf-image" );	VCFCOM::COMUtils::standardWin32DataTypes["image/application-x-wmf"] = CF_METAFILEPICT;	VCFCOM::COMUtils::standardWin32DataTypes["image/application-x-emf"] = CF_ENHMETAFILE;	VCFCOM::COMUtils::standardWin32DataTypes["image/bmp"] = CF_BITMAP;	VCFCOM::COMUtils::standardWin32DataTypes[COMPONENT_DATA_TYPE] = ::RegisterClipboardFormat( "text/x-vcf-vff" );#endif}/***CVS Log info*$Log$*Revision 1.2  2006/04/07 02:35:26  ddiego*initial checkin of merge from 0.6.9 dev branch.**Revision 1.1.2.2  2006/03/04 18:03:08  kiklop74*Last minute fixes**Revision 1.1.2.1  2006/02/19 19:38:12  ddiego*adjusted some comet code to make it compile again. renamed some of the COM utility files to have a Win32 prefix.**Revision 1.3.2.6  2006/02/15 18:35:42  iamfraggle*added comet/interface.h #include (so uuidof gets defined from comet rather than somewhere else...)**Revision 1.3.2.5  2006/02/09 04:54:02  ddiego*added missing lib tiff project for vc80. Also removed*ATL dependency and comdef.h dependency. We are now using comet for*basic COM types, and I have a new chunk of code that implements the*basics for hosting the browser.**Revision 1.3.2.4  2005/12/08 21:09:18  kiklop74*fixes for borland compiler**Revision 1.3.2.3  2005/11/04 17:56:17  ddiego*fixed bugs in some win32 code to better handle unicode - ansi functionality.**Revision 1.3.2.2  2005/10/07 19:31:53  ddiego*merged patch 1315995 and 1315991 into dev repos.**Revision 1.3.2.1  2005/08/12 03:13:44  ddiego*minor changes**Revision 1.3  2005/07/09 23:14:51  ddiego*merging in changes from devmain-0-6-7 branch.**Revision 1.2.4.4  2005/04/13 00:57:01  iamfraggle*Enable Unicode in CodeWarrior**Revision 1.2.4.3  2005/04/11 17:04:50  iamfraggle*Changes allowing compilation of Win32 port under CodeWarrior**Revision 1.2.4.2  2005/04/09 17:20:35  marcelloptr*bugfix [ 1179853 ] memory fixes around memset. Documentation. DocumentManager::saveAs and DocumentManager::reload**Revision 1.2.4.1  2005/02/23 03:53:31  ddiego*fixed a bug in the com translation of file names.**Revision 1.2  2004/08/07 02:49:05  ddiego*merged in the devmain-0-6-5 branch to stable**Revision 1.1.2.2  2004/04/29 03:43:12  marcelloptr*reformatting of source files: macros and csvlog and copyright sections**Revision 1.1.2.1  2004/04/28 00:28:14  ddiego*migration towards new directory structure**Revision 1.3.4.1  2004/04/21 02:17:25  ddiego*checking in change to FoundationKit, GraphicsKit and Application*Kit to support unicode in Win32**Revision 1.3  2003/12/18 05:16:01  ddiego*merge from devmain-0-6-2 branch into the stable branch**Revision 1.2.2.4  2003/10/28 20:23:26  ddiego*minor header changes**Revision 1.2.2.3  2003/10/04 20:14:59  ddiego*aaddec changes to support compiling on GCC 3.3.1, which is much more*picky than some of the previous versions.**Revision 1.2.2.2  2003/09/02 02:11:14  ddiego*fixed some glitches in drag drop. also cleaned up the drag drop event*classes. Began some fixes to the html browser implementation on Win32**Revision 1.2.2.1  2003/08/27 20:11:49  ddiego*adjustments to how hte DataObject class work and copy/paste**Revision 1.2  2003/08/09 02:56:46  ddiego*merge over from the devmain-0-6-1 branch*Changes*Features:*-Added additional implementation to better support the MVC architecture in*the VCF**-Added a Document/View architecure that is similar to MFC's or NextSteps's*Doc/View architectures**-Integrated the Anti Grain Graphics library into the GraphicsKit. There is*now basic support for it in terms of drawing vector shapes*(fills and strokes). Image support will come in the next release**-Added several documented graphics tutorials**Bugfixes:**[ 775744 ] wrong buttons on a dialog*[ 585239 ] Painting weirdness in a modal dialog ?*[ 585238 ] Modal dialog which makes a modal Dialog*[ 509004 ] Opening a modal Dialog causes flicker*[ 524878 ] onDropped not called for MLTcontrol**Plus an issue with some focus and getting the right popup window to activate*has also been fixed**Revision 1.1.2.3  2003/06/27 03:10:59  ddiego*got rid of some redundant junk in the Clipboard and DataObject*classes. Instead of a rather dippy use of the DataType calss, we now simply*use pure mime-types to identify the various "flavours" of data.**Revision 1.1.2.2  2003/05/25 20:01:08  ddiego*oops - missed some #include changes from moving the files from one directory to*the other! This fixes that (related to the drag-drop bug fixing and clean up)**Revision 1.1.2.1  2003/05/25 19:07:13  ddiego*fixed bug [ 524878 ] onDropped not called for MLTcontrol. This*was due to errors in the drag-drop implementation for WIn32 and is*now fixed.*Also cleaned up the drag-drop implementation and moved/deleted a number of*irrelevant files for COM support. The vcf/include/com and vcf/src/COM*directories are now gotten rid of.**Revision 1.10  2003/05/17 20:37:17  ddiego*this is the checkin for the 0.6.1 release - represents the merge over from*the devmain-0-6-0 branch plus a few minor bug fixes**Revision 1.9.2.1  2003/03/23 03:23:53  marcelloptr*3 empty lines at the end of the files**Revision 1.9  2003/02/26 04:30:45  ddiego*merge of code in the devmain-0-5-9 branch into the current tree.*most additions are in the area of the current linux port, but the major*addition to this release is the addition of a Condition class (currently*still under development) and the change over to using the Delegate class*exclusively from the older event handler macros.**Revision 1.8.8.3  2003/01/08 00:19:49  marcelloptr*mispellings and newlines at the end of all source files**Revision 1.8.8.2  2002/12/27 23:04:45  marcelloptr*Improved macros for automatic import/export of libraries. - Warning fixes. - Other Minor Changes.**Revision 1.8.8.1  2002/12/02 00:38:35  ddiego*more fixes to get the ApplicationKit to compile under mingw. Everything now*compiles OK at this point.**Revision 1.8  2002/09/12 03:26:05  ddiego*merged over the changes from the devmain-0-5-5b branch**Revision 1.7.6.1  2002/06/28 17:45:30  ddiego*migrated over lucki's changes (from his branch) for drag drop*compiles OK, made chages to control and UIToolkit as neccessary*still testing though.**Revision 1.7  2002/05/09 03:10:44  ddiego*merged over code from development branch devmain-0-5-1a into the main CVS trunk**Revision 1.6.4.2  2002/04/27 15:52:21  ddiego*Changed a bunch of files include and made it a bit faster and added better include*guards in the common headers**Revision 1.6.4.1  2002/04/08 20:55:29  zzack*changed include style**Revision 1.6  2002/01/24 01:46:49  ddiego*added a cvs "log" comment to the top of all files in vcf/src and vcf/include*to facilitate change tracking**/

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?