HDC QuerySaveEMFFile(const TCHAR * description, const RECT * rcFrame, TCHAR szFileName[]) { KFileDialog fd; if ( fd.GetSaveFileName(NULL, _T("emf"), _T("Enhanced Metafiles")) ) { if ( szFileName ) _tcscpy(szFileName, fd.m_TitleName); return CreateEnhMetaFile(NULL, fd.m_TitleName, rcFrame, description); } else return NULL; }
BOOL SaveDIBToFile(const TCHAR * pFileName, const BITMAPINFO * pBMI, const void * pBits) { KFileDialog fi; if ( pFileName==NULL ) { if ( ! fi.GetSaveFileName(NULL, _T("bmp"), _T("Bitmap Files")) ) return FALSE; pFileName = fi.m_TitleName; } HANDLE handle = CreateFile(pFileName, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL); if ( handle == INVALID_HANDLE_VALUE ) return FALSE; BITMAPFILEHEADER bmFH; int nHeadSize = sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * GetDIBColorCount(pBMI->bmiHeader); bmFH.bfType = 0x4D42; bmFH.bfSize = nHeadSize + GetDIBPixelSize(pBMI->bmiHeader); bmFH.bfReserved1 = 0; bmFH.bfReserved2 = 0; bmFH.bfOffBits = nHeadSize + sizeof(BITMAPFILEHEADER); DWORD dwRead = 0; WriteFile(handle, & bmFH, sizeof(bmFH), & dwRead, NULL); if ( pBits==NULL ) // packed DIB pBits = (BYTE *) pBMI + nHeadSize; WriteFile(handle, pBMI, nHeadSize, & dwRead, NULL); WriteFile(handle, pBits, GetDIBPixelSize(pBMI->bmiHeader), & dwRead, NULL); CloseHandle(handle); return TRUE; }
LRESULT KEMFView::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch( uMsg ) { case WM_CREATE: m_hWnd = hWnd; m_hViewMenu = LoadMenu(m_hInst, MAKEINTRESOURCE(IDR_VIEWER)); { RECT rect; GetClientRect(m_hWnd, & rect); m_emftree.Create(hWnd, 101, 0, 0, m_nDivision, rect.bottom, m_hInst); m_emfpanel.CreateEx(WS_EX_CLIENTEDGE, "EMFPanel", NULL, WS_VISIBLE | WS_BORDER | WS_CHILD, m_nDivision+3, 0, rect.right - m_nDivision+3, rect.bottom, hWnd, NULL, m_hInst); { KEmfDC emfdc; if ( m_emfpanel.m_hEmf ) emfdc.DeCompile(NULL, m_emfpanel.m_hEmf, & m_emftree); else emfdc.DeCompile(NULL, m_FileName, & m_emftree, m_emfpanel.m_hEmf); } // palette message handling is in KWindow class, which needs m_hPalette to be set { HDC hDC = GetDC(hWnd); m_hPalette = GetEMFPalette(m_emfpanel.m_hEmf, hDC); m_emfpanel.m_hPalette = m_hPalette; ReleaseDC(hWnd, hDC); } } return 0; case WM_SIZE: MoveWindow( m_emftree.m_hWnd, 0, 0, m_nDivision, HIWORD(lParam), TRUE); MoveWindow(m_emfpanel.m_hWnd, m_nDivision+3, 0, LOWORD(lParam)-m_nDivision+3, HIWORD(lParam), TRUE); return 0; case WM_MOUSEMOVE: // handle split window adjustment if ( wParam & MK_LBUTTON ) { if ( GetCapture() != hWnd ) SetCapture(hWnd); RECT rect; GetClientRect(hWnd, & rect); m_nDivision = LOWORD(lParam); SendMessage(hWnd, WM_SIZE, 0, MAKELONG(rect.right, rect.bottom)); } else if ( GetCapture() == hWnd ) ReleaseCapture(); return 0; case WM_COMMAND: switch ( LOWORD(wParam) ) { case IDM_FILE_SAVETEXT: { KFileDialog fd; ofstream out; if ( fd.GetSaveFileName(NULL, "txt", "Text Files") ) { out.open(fd.m_TitleName); SimpleEnumerateEMF(m_emfpanel.m_hEmf, out); out.close(); } return 0; } case IDM_FILE_DECOMPILE: { KFileDialog fd; if ( fd.GetSaveFileName(NULL, "cpp", "C++ Programs") ) { KEmfDC dc; dc.DeCompile(fd.m_TitleName, m_emfpanel.m_hEmf, NULL); } } return 0; case IDM_FILE_FILTER: { KGrayEMF gray; HENHMETAFILE hEmf = FilterEMF(m_emfpanel.m_hEmf, gray); DeleteEnhMetaFile(hEmf); } break; case IDM_VIEW_DELAY: { m_emfpanel.m_mode = 1; m_emfpanel.SetZoom(0, true); } return 0; case IDM_VIEW_GRAY: { m_emfpanel.m_mode = 2; m_emfpanel.SetZoom(0, true); } return 0; case IDM_VIEW_TRACE: { m_emfpanel.m_mode = 3; m_emfpanel.SetZoom(0, true); } return 0; case IDM_VIEW_ZOOM50: m_emfpanel.SetZoom(50); return 0; case IDM_VIEW_ZOOM100: m_emfpanel.SetZoom(100); return 0; case IDM_VIEW_ZOOM200: m_emfpanel.SetZoom(200); return 0; } case WM_PALETTECHANGED: return OnPaletteChanged(hWnd, wParam); case WM_QUERYNEWPALETTE: return OnQueryNewPalette(); default: return CommonMDIChildProc(hWnd, uMsg, wParam, lParam, m_hViewMenu, 4); } }