Click here to Skip to main content
15,894,106 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRelease Mode error Pin
aj16824-Feb-05 1:57
aj16824-Feb-05 1:57 
GeneralRe: Release Mode error Pin
Bob Ciora4-Feb-05 2:56
Bob Ciora4-Feb-05 2:56 
GeneralRelease Mode Errors Pin
aj16824-Feb-05 1:54
aj16824-Feb-05 1:54 
GeneralRe: Release Mode Errors Pin
Ravi Bhavnani4-Feb-05 8:00
professionalRavi Bhavnani4-Feb-05 8:00 
GeneralLDAP Pin
Anthony_Yio4-Feb-05 1:06
Anthony_Yio4-Feb-05 1:06 
GeneralRe: LDAP Pin
Antony M Kancidrowski4-Feb-05 1:54
Antony M Kancidrowski4-Feb-05 1:54 
GeneralRe: LDAP Pin
Anthony_Yio4-Feb-05 17:01
Anthony_Yio4-Feb-05 17:01 
GeneralGetWindowOrg fails..my metafile export is not working.... Pin
Dimitris Vikeloudas4-Feb-05 0:25
Dimitris Vikeloudas4-Feb-05 0:25 
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<br />
U_W_SCROLL_VIEW::handle_metafile_save(const AB_Text& filename)<br />
{<br />
   AB_Integer    handler;<br />
   MetaNode    * pMetaNode;<br />
   CMetaFileDC * pDCMetaFile;<br />
   DWORD         dwError;<br />
<br />
    CMDIChildWnd* pChildFrame = (CMDIChildWnd*)GetParent();<br />
    pChildFrame->ShowWindow(SW_HIDE);<br />
<br />
     // Clear any error given by another thred<br />
   if( ::GetLastError() )<br />
     ::SetLastError(0);<br />
<br />
   OnInitialUpdate();<br />
<br />
   if( dwError = ::GetLastError() )<br />
     goto failed;<br />
<br />
      // Our memory managment.<br />
   handler = request_create_metafile();<br />
<br />
   pMetaNode   = (MetaNode*)handler.to_long();<br />
   pDCMetaFile = pMetaNode->pDCMetafile;<br />
<br />
     // Save the handlers<br />
   set_export_metafile(handler, filename);<br />
<br />
   OnPrepareDC(pDCMetaFile, NULL);<br />
   if( dwError = ::GetLastError() )<br />
     goto failed;<br />
<br />
   OnDrawn(pDCMetafile);<br />
<br />
    .........................<br />
}<br />
<br />
void<br />
U_W_SCROLL_VIEW::OnInitialUpdate()<br />
{<br />
    TEXTMETRIC tm;<br />
    CRect clientRect;<br />
    CClientDC dc(this);<br />
<br />
    m_hDC = dc.GetSafeHdc();<br />
<br />
    if( abstract_logic->isExporting() ) {<br />
       dc.SetWindowOrg(0, 0);<br />
    }<br />
<br />
    // get the size of a line of text<br />
    CFont* pOldFont = dc.SelectObject(&m_font);<br />
    dc.GetOutputTextMetrics(&tm);<br />
    m_sizeLine.cx = tm.tmAveCharWidth;<br />
    m_sizeLine.cy = tm.tmHeight + tm.tmExternalLeading;<br />
    dc.SelectObject(pOldFont);<br />
<br />
    // get the size of a page<br />
    GetClientRect(clientRect);<br />
    m_sizePage.cx = clientRect.Width();<br />
    m_sizePage.cy = clientRect.Height();<br />
<br />
    // ensure that the page size is always a<br />
    // multiple of the line size<br />
    int rem_x = m_sizePage.cx % m_sizeLine.cx;<br />
    int rem_y = m_sizePage.cy % m_sizeLine.cy;<br />
<br />
    m_sizePage.cx -= rem_x;<br />
    m_sizePage.cy -= rem_y;<br />
<br />
    // Remove the cursor associated with this window - if we don't do this<br />
    // Windows will try to reset the cursor every time the mouse moves<br />
    ::SetClassLong( this->m_hWnd, GCL_HCURSOR, NULL );<br />
<br />
    // Now set a default arrow cursor for the window<br />
    m_hDefaultCursor = ::LoadCursor( NULL, IDC_ARROW );<br />
    m_hCursor = m_hDefaultCursor;<br />
    ::SetCursor(m_hCursor);<br />
<br />
    SetScrollSizes( MM_TEXT, m_sizeScroll, m_sizePage, m_sizeLine );<br />
}<br />
<br />
void<br />
U_W_SCROLL_VIEW::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)<br />
{<br />
<br />
        // Remember the current GDI<br />
   HDC hAttribDC = this->m_hDC;<br />
<br />
        // Normal preparing for drawing.<br />
   metafiles.RemoveAll();<br />
<br />
          // Most likely this call will clear<br />
          // the current device context.<br />
   m_hDC = pDC->GetSafeHdc();<br />
<br />
         // This iterates the repository and<br />
         // draws its record into a metafile. Those<br />
         // metafiles are stored in the metafile collection<br />
         // object.<br />
   abstract_logic->handle_draw_persistent();<br />
<br />
         // what is the actual size of the display<br />
   AB_Integer left, top, right, bottom;<br />
<br />
        // Gets in logical coordinates the size of the<br />
        // picture already drawn<br />
   abstract_logic->get_view_total_size(left, top, right, bottom);<br />
<br />
         // If for any reason we cannot export it then return.<br />
   if( !request_begin_export_metafile(left, top, right, bottom) )<br />
     return;<br />
<br />
         // The pDC now holds the exported metafile.<br />
         // Update the membership function.<br />
   m_hDC = pDC->GetSafeHdc();<br />
<br />
   pDC->SetAttribDC(hAttribDC);<br />
<br />
<big>     /* On Debug mode I get an assertion error by the following call.<br />
        This comes from the following windows code:<br />
        _AFXWIN_INLINE CPoint CDC::GetWindowOrg() const<br />
	{<br />
		ASSERT(m_hAttribDC != NULL);<br />
		POINT point;<br />
		VERIFY(::GetWindowOrgEx(m_hAttribDC, &point));<br />
		return point;<br />
	}<br />
<br />
        However, the m_hAtrribDC is not null. It is the verify<br />
        statement that fails. Not sure why. The last error is<br />
        ERROR_INVALID_PARAMETER but not sure which parameter<br />
        is wrong.<br />
     */<br />
   CScrollView::OnPrepareDC(pDC, pInfo);<br />
<br />
</big>   pDC->SetMapMode(MM_TEXT);<br />
}<br />
<br />
<br />
AB_BOOL<br />
U_W_SCROLL_VIEW::request_begin_export_metafile(<br />
                          AB_Integer& left,<br />
                          AB_Integer& top,<br />
                          AB_Integer& right,<br />
                          AB_Integer& bottom )<br />
{<br />
    MetaNode    * pMetaNode   = (MetaNode*) m_hExporting.to_long();<br />
    CMetaFileDC * pDCMetaFile = pMetaNode->pDCMetafile;<br />
<br />
    CDC * pDC = GetDC();<br />
<br />
    int factor_x = ceil( (pDC->GetDeviceCaps(HORZSIZE) * 100.0)/ pDC->GetDeviceCaps(HORZRES));<br />
    int factor_y = ceil( (pDC->GetDeviceCaps(VERTSIZE) * 100.0)/ pDC->GetDeviceCaps(VERTRES));<br />
<br />
    CRect rect( 0, 0, (right.to_long() - left.to_long() + 10) * factor_x,<br />
                (bottom.to_long()- top.to_long() + 10) * factor_y );<br />
<br />
    if (!pDCMetaFile ->CreateEnhanced(pDC, m_psExporting->data(), &rect, NULL))<br />
    {<br />
      ::SetLastError(-1);<br />
<br />
      return AB_FALSE;<br />
    }<br />
<br />
    HDC hDC = pDCMetaFile->GetSafeHdc();<br />
<br />
    SetGraphicsMode(hDC, GM_ADVANCED);<br />
    pMetaNode->bounds.left   = left.to_long();<br />
    pMetaNode->bounds.right  = right.to_long() + 10;<br />
    pMetaNode->bounds.top    = top.to_long();<br />
    pMetaNode->bounds.bottom = bottom.to_long() + 10;<br />
<br />
    return AB_TRUE;<br />
}<br />
<br />
void<br />
U_W_SCROLL_VIEW::OnDraw(CDC* pDC)<br />
{<br />
    XFORM xForm;<br />
    RECT inv_rect;<br />
    MetaNode* meta_node;<br />
    POSITION  pos;<br />
<br />
    if( m_bInRepaint )<br />
        return;<br />
<br />
    m_bInRepaint = TRUE;<br />
    // CCF 5357 - move this before any call to handle_draw_persistent<br />
    m_hDC = pDC->GetSafeHdc();<br />
<br />
    m_bPrinting = FALSE;<br />
    AB_Integer left, top, right, bottom;<br />
<br />
    request_get_metafile_bounds(m_hExporting, left, top, right, bottom);<br />
<br />
    inv_rect.left   = left.to_long();;<br />
    inv_rect.top    = top.to_long();<br />
    inv_rect.right  = right.to_long();<br />
    inv_rect.bottom = bottom.to_long();<br />
    COLORREF clr = ::GetSysColor(COLOR_WINDOW);<br />
<br />
  <big>     // The following call sets the last error to ERROR_INVALID_PARAMETER<br />
       // However, both the inv_rect & the clr have valid logical coordinates.<br />
    pDC->FillSolidRect(&inv_rect, clr);<br />
</big><br />
        // CCF-5477: Block moved before calls to handle_draw_persistent<br />
    SetGraphicsMode(m_hDC, GM_ADVANCED);<br />
<br />
    ModifyWorldTransform( m_hDC, &xForm, MWT_IDENTITY );<br />
<br />
    Scale(m_hDC);<br />
    Translate(m_hDC);<br />
<br />
        // Now replay all metafiles to the saved one<br />
    pos = metafiles.GetHeadPosition();<br />
    while( pos != NULL )<br />
    {<br />
      meta_node = (MetaNode*)metafiles.GetNext(pos);<br />
      ::PlayEnhMetaFile(m_hDC,meta_node->hMetafile,&(meta_node->bounds));<br />
    }<br />
    <br />
    RestoreIdentityDC(m_hDC);<br />
}<br />

Question. MAPI Error ? Pin
im4help3-Feb-05 23:35
im4help3-Feb-05 23:35 
AnswerRe: . MAPI Error ? Pin
Antony M Kancidrowski4-Feb-05 1:59
Antony M Kancidrowski4-Feb-05 1:59 
GeneralAlt + Tab Icon Pin
shiraztk3-Feb-05 23:33
shiraztk3-Feb-05 23:33 
QuestionHow can i parse a command line in an SDI application? Pin
IronMike3-Feb-05 23:32
IronMike3-Feb-05 23:32 
AnswerRe: How can i parse a command line in an SDI application? Pin
Anthony_Yio4-Feb-05 0:54
Anthony_Yio4-Feb-05 0:54 
GeneralRe: How can i parse a command line in an SDI application? Pin
Rick York4-Feb-05 7:07
mveRick York4-Feb-05 7:07 
GeneralMemory used by Pocess. Pin
Member 17079243-Feb-05 23:23
Member 17079243-Feb-05 23:23 
GeneralRe: Memory used by Pocess. Pin
David Crow4-Feb-05 3:22
David Crow4-Feb-05 3:22 
GeneralRe: Memory used by Pocess. Pin
Blake Miller7-Feb-05 5:44
Blake Miller7-Feb-05 5:44 
QuestionHow to create new level in multilevel CTreeView Pin
bilas3-Feb-05 22:13
bilas3-Feb-05 22:13 
AnswerRe: How to create new level in multilevel CTreeView Pin
shiraztk4-Feb-05 0:53
shiraztk4-Feb-05 0:53 
GeneralRe: How to create new level in multilevel CTreeView Pin
bilas4-Feb-05 2:11
bilas4-Feb-05 2:11 
QuestionHow to realize FIND-function in class CHTMLView? Pin
bilas3-Feb-05 22:10
bilas3-Feb-05 22:10 
AnswerRe: How to realize FIND-function in class CHTMLView? Pin
Sheng Jiang 蒋晟6-Feb-05 14:08
Sheng Jiang 蒋晟6-Feb-05 14:08 
GeneralDialog Control Pin
nchannon3-Feb-05 21:55
nchannon3-Feb-05 21:55 
GeneralRe: Dialog Control Pin
RChin3-Feb-05 23:02
RChin3-Feb-05 23:02 
GeneralRe: Dialog Control Pin
nchannon4-Feb-05 7:43
nchannon4-Feb-05 7:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.