GetWindowOrg fails..my metafile export is not working....
-
I have a CScrollView (my private class is U_W_SCROLL_VIEW) and try to draw it invisible to the screen and export the drawn picture into an enhanced metafile. The drawing is not right and I am getting various error or assertion failures in debug mode. Can anyone point me to anything that I might be missing or doing wrong?? Any help welcome. Here is the code
AB_BOOL U_W_SCROLL_VIEW::handle_metafile_save(const AB_Text& filename) { AB_Integer handler; MetaNode * pMetaNode; CMetaFileDC * pDCMetaFile; DWORD dwError; CMDIChildWnd* pChildFrame = (CMDIChildWnd*)GetParent(); pChildFrame->ShowWindow(SW_HIDE); // Clear any error given by another thred if( ::GetLastError() ) ::SetLastError(0); OnInitialUpdate(); if( dwError = ::GetLastError() ) goto failed; // Our memory managment. handler = request_create_metafile(); pMetaNode = (MetaNode*)handler.to_long(); pDCMetaFile = pMetaNode->pDCMetafile; // Save the handlers set_export_metafile(handler, filename); OnPrepareDC(pDCMetaFile, NULL); if( dwError = ::GetLastError() ) goto failed; OnDrawn(pDCMetafile); ......................... } void U_W_SCROLL_VIEW::OnInitialUpdate() { TEXTMETRIC tm; CRect clientRect; CClientDC dc(this); m_hDC = dc.GetSafeHdc(); if( abstract_logic->isExporting() ) { dc.SetWindowOrg(0, 0); } // get the size of a line of text CFont* pOldFont = dc.SelectObject(&m_font); dc.GetOutputTextMetrics(&tm); m_sizeLine.cx = tm.tmAveCharWidth; m_sizeLine.cy = tm.tmHeight + tm.tmExternalLeading; dc.SelectObject(pOldFont); // get the size of a page GetClientRect(clientRect); m_sizePage.cx = clientRect.Width(); m_sizePage.cy = clientRect.Height(); // ensure that the page size is always a // multiple of the line size int rem_x = m_sizePage.cx % m_sizeLine.cx; int rem_y = m_sizePage.cy % m_sizeLine.cy; m_sizePage.cx -= rem_x; m_sizePage.cy -= rem_y; // Remove the cursor associated with this window - if we don't do this // Windows will try to reset the cursor every time the mouse moves ::SetClassLong( this->m_hWnd, GCL_HCURSOR, NULL ); // Now set a default arrow cursor for the window m_hDefaultCursor = ::LoadCursor( NULL, IDC_ARROW ); m_hCursor = m_hDefaultCursor; ::SetCursor(m_hCursor); SetScrollSizes( MM_TEXT, m_sizeScroll, m_sizePa