Type | Description |
The EMF format is an extensible format, which means that a programmer can modify the original specification to add functionality or to meet specific needs. You can paste this format to Microsoft Word, Excel, Front Page, Microsoft Image Composer and any application that know to handle EMF formats.
The Copy method copies the control's header if it's visible, and all visible items. Use the CopyTo method to copy the control's view to an PNG, BMP, GIF, TIF, JPEG, EMF file. The items are not expanded, they are listed in the order as they are displayed on the screen. Use the HeaderVisible property to show or hide the control's header. Use the ExpandItem property to expand or collapse an item. The background of the copied control is transparent.
The following VB sample saves the control's content to a EMF file, when user presses the CTRL+C key:
Private Sub G2antt1_KeyDown(KeyCode As Integer, Shift As Integer) If (KeyCode = vbKeyC) And Shift = 2 Then Clipboard.Clear G2antt1.Copy SavePicture Clipboard.GetData(), App.Path & "\test.emf" End If End Sub
Now, you can open your MS Windows Word application, and you can insert the file using the Insert\Picture\From File menu, or by pressing the CTRL+V key to paste the clipboard.
The following C++ function saves the clipboard's data ( EMF format ) to a picture file:
BOOL saveEMFtoFile( LPCTSTR szFileName ) { BOOL bResult = FALSE; if ( ::OpenClipboard( NULL ) ) { CComPtrspPicture; PICTDESC pictDesc = {0}; pictDesc.cbSizeofstruct = sizeof(pictDesc); pictDesc.emf.hemf = (HENHMETAFILE)GetClipboardData( CF_ENHMETAFILE ); pictDesc.picType = PICTYPE_ENHMETAFILE; if ( SUCCEEDED( OleCreatePictureIndirect( &pictDesc, IID_IPicture, FALSE, (LPVOID*)&spPicture ) ) ) { HGLOBAL hGlobal = NULL; CComPtr spStream; if ( SUCCEEDED( CreateStreamOnHGlobal( hGlobal = GlobalAlloc( GPTR, 0 ), TRUE, &spStream ) ) ) { long dwSize = NULL; if ( SUCCEEDED( spPicture->SaveAsFile( spStream, TRUE, &dwSize ) ) ) { USES_CONVERSION; HANDLE hFile = CreateFile( szFileName, GENERIC_WRITE, NULL, NULL, CREATE_ALWAYS, NULL, NULL ); if ( hFile != INVALID_HANDLE_VALUE ) { LARGE_INTEGER l = {NULL}; spStream->Seek(l, STREAM_SEEK_SET, NULL); long dwWritten = NULL; while ( dwWritten < dwSize ) { unsigned long dwRead = NULL; BYTE b[10240] = {0}; spStream->Read( &b, 10240, &dwRead ); DWORD dwBWritten = NULL; WriteFile( hFile, b, dwRead, &dwBWritten, NULL ); dwWritten += dwBWritten; } CloseHandle( hFile ); bResult = TRUE; } } } } CloseClipboard(); } return bResult; }
The following VB.NET sample copies the control's content to the clipboard ( open the mspaint application and paste the clipboard, after running the following code ):
Clipboard.Clear() With AxG2antt1 .Copy() End With
The following C# sample copies the control's content to a file ( open the mspaint application and paste the clipboard, after running the following code ):
Clipboard.Clear; axG2antt1.Copy();