Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Metafile output on Win98 problem

Metafile output on Win98 problem

Scheduled Pinned Locked Moved C / C++ / MFC
performancehelpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Chris Losinger
    wrote on last edited by
    #1

    I'm creating simple WMFs (Aldus and non-Aldus) by doing a simple StretchDIBits with a DIB i've created myself. i know the DIB is valid because a) if i draw it to the screen, it looks fine, and b) the code works on NT, Win2K and, i think, 95. when i create these metafiles in Win98, however, the image is shifted to the right 20 (i haven't measured) pixels or so - what should be the left edge of the image appears about 20 pixels from the displayed left edge, and, the colors are wrong on the part of the image to the right of the real left edge (the components are swapped, apparently). it sounds like the DIB is wrong, but i know it's not. also, i've tried doing this with an HBITMAP and BitBlt, with the same results. more info.... if i open these WMFs in PSP 6, they look fine. if i view them with ACDSee or the Win98 Explorer, they have the offset problem. if i read it into PSP6, then resave, the new WMF looks fine in ACDSee, Win98's Explorer and PSP. i'm stumped. are there tricks to saving WMFs that aren't documented????? any info is appreciated. -c // use the screen DC HDC dc = ::GetDC(NULL); if (dc!=NULL) { // calculate output rect.... .... HDC hMetaDC = ::CreateEnhMetaFile(dc, NULL, &rect, ""); if (hMetaDC!=NULL) { // map mode junk SetMapMode(hMetaDC, MM_ANISOTROPIC); SetWindowExtEx(hMetaDC, iDPIX, iDPIY, NULL); SetViewportExtEx(hMetaDC, iDPIX, iDPIY, NULL); BITMAPINFO bmInfo = *(LPBITMAPINFO)pDIB ; // this function uses generic 24bit DIBs, only. i know this // because i generate them myself. LPVOID lpDIBBits = (LPVOID)(pDIB + bmInfo.bmiHeader.biSize); UINT32 lines = ::StretchDIBits(hMetaDC, 0,0, width, height, 0,0, width, height, lpDIBBits, &bmInfo, DIB_RGB_COLORS, SRCCOPY); HENHMETAFILE hMeta = ::CloseEnhMetaFile(hMetaDC); // How big will the metafile bits be? UINT32 dwSize = GetWinMetaFileBits( hMeta, 0, NULL, MM_ANISOTROPIC, dc ); if (dwSize!=0) { // Allocate that much memory

    G 1 Reply Last reply
    0
    • C Chris Losinger

      I'm creating simple WMFs (Aldus and non-Aldus) by doing a simple StretchDIBits with a DIB i've created myself. i know the DIB is valid because a) if i draw it to the screen, it looks fine, and b) the code works on NT, Win2K and, i think, 95. when i create these metafiles in Win98, however, the image is shifted to the right 20 (i haven't measured) pixels or so - what should be the left edge of the image appears about 20 pixels from the displayed left edge, and, the colors are wrong on the part of the image to the right of the real left edge (the components are swapped, apparently). it sounds like the DIB is wrong, but i know it's not. also, i've tried doing this with an HBITMAP and BitBlt, with the same results. more info.... if i open these WMFs in PSP 6, they look fine. if i view them with ACDSee or the Win98 Explorer, they have the offset problem. if i read it into PSP6, then resave, the new WMF looks fine in ACDSee, Win98's Explorer and PSP. i'm stumped. are there tricks to saving WMFs that aren't documented????? any info is appreciated. -c // use the screen DC HDC dc = ::GetDC(NULL); if (dc!=NULL) { // calculate output rect.... .... HDC hMetaDC = ::CreateEnhMetaFile(dc, NULL, &rect, ""); if (hMetaDC!=NULL) { // map mode junk SetMapMode(hMetaDC, MM_ANISOTROPIC); SetWindowExtEx(hMetaDC, iDPIX, iDPIY, NULL); SetViewportExtEx(hMetaDC, iDPIX, iDPIY, NULL); BITMAPINFO bmInfo = *(LPBITMAPINFO)pDIB ; // this function uses generic 24bit DIBs, only. i know this // because i generate them myself. LPVOID lpDIBBits = (LPVOID)(pDIB + bmInfo.bmiHeader.biSize); UINT32 lines = ::StretchDIBits(hMetaDC, 0,0, width, height, 0,0, width, height, lpDIBBits, &bmInfo, DIB_RGB_COLORS, SRCCOPY); HENHMETAFILE hMeta = ::CloseEnhMetaFile(hMetaDC); // How big will the metafile bits be? UINT32 dwSize = GetWinMetaFileBits( hMeta, 0, NULL, MM_ANISOTROPIC, dc ); if (dwSize!=0) { // Allocate that much memory

      G Offline
      G Offline
      Gert Boddaert
      wrote on last edited by
      #2

      Chris, Had the same problem. It's a memory alignment thing. (prints fine on NT but had a problem on 95/98) Sorry to mail a bulk of code like this. Cheers, GBO. --- // Try something like this: // excerpt from my GO++ extension code. // I do not load the MetaFile from file, but from memory // (it is embedded in my DLLs) BOOL CGoSchemeMetaPict::DrawObject(CDC* pDC) //:draw this metafile { if (!CGoObject::IsVisible()) return TRUE; // allow for the MetaFileName() function to be overriden and actually // change the name behind our backs! if (myResID == 0) { TRACE0("CGoMetaFile with no ResourceID\n"); CGoObject::DrawObject(pDC); // call the base class default draw return TRUE; } CGoAppMixIn* theApp = (CGoAppMixIn*) AfxGetApp(); CGoView* pView; if (m_pDocument) pView = m_pDocument->GetCurrentDrawView(); else pView = m_pView; int nScale = 100; if (pView) nScale = pView->GetScale(); // only use the bitmap cache if the scale factor is 1:1 or smaller. If we are // scaling things larger, draw the metafile directly. CRect devRect = GetBoundingRect(); /* if (bPrintPreview) { CDC* pATC = CDC::FromHandle(pDC->m_hAttribDC); pATC->LPtoDP(&devRect); } else { pDC->LPtoDP(&devRect); } */ //GBO: does not work now ?? // for Win32 functions HDC hDCDrawSurf = pDC->GetSafeHdc( ); LPENHMETAHEADER pemh; if (hEnhMetaFile == NULL) { HRSRC HResourceInfo = ::FindResource( HCallingModule, // module handle MAKEINTRESOURCE(myResID), // pointer to resource name (LPCSTR) "WMFRES" // pointer to resource type ); if (HResourceInfo == NULL) { DWORD error = ::GetLastError(); _ASSERT(NULL); AfxMessageBox("HResourceInfo == NULL for MetaFileResource!"); return FALSE; } HGLOBAL HData = LoadResource( HCallingModule, // resource-module handle HResourceInfo // resource handle ); if (HData == NULL) { DWORD error = ::GetLastError(); _ASSERT(NULL); AfxMessageBox("HData == NULL for MetaFileResource!"); return FALSE; } void* pMapFile = HData; pemh = (LPENHMETAHEADER) HData; DWORD uiSize = 0; // CHECK FOR WMF FORMAT // // If it has an ALDUS header skip it // Notice: APMSIZE is used because the HANDLE and RECT of the structure // depends on the environment // if (*((LPDWORD)pemh) == ALDUS_ID) { AL

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups