how to modify the code to display bitmap

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 22/07/2007 at 01:52, xxxxxxxx wrote:

User Information:
Cinema 4D Version:    
Platform:      
Language(s) :   C.O.F.F.E.E  ;  C++  ;  XPRESSO  ;

---------
I want to render the object and display the progress with model.  but I have an little problem that  can't implement display the progress.  since  I am an newcome student about c4d,  how can I to modify the code section :   
AddUserArea( PREVIEW_AREA_ID, 0, m_bmp->GetBw(), m_bmp->GetBh());
AttachImage(PREVIEW_AREA_ID, m_bmp, 0);
this is my all code modifly after :
#ifndef   __RENDER__COMMON__H  
#define   __RENDER__COMMON__H
#include "c4d.h"
#include "c4d_symbols.h"
#include "c4d_general.h"
#include "c4d_baseobject.h"
class PreviewAreaBmp : public GeUserArea
{
 public: 
   AutoAlloc<BaseBitmap> m_pBmp;
   
 public:  // we only need to overload a few functions... 
  
  Bool Init(void)
  {
   BaseDocument* doc = GetActiveDocument();
   BaseContainer rdata = doc->GetActiveRenderData()->GetData();
   // initialize the bitmap 
   if( !m_pBmp || m_pBmp->Init( rdata.GetLong(RDATA_XRES), rdata.GetLong(RDATA_YRES) )!=IMAGE_OK )
   {
    return false;
   }
   return true;
  }

virtual Bool Init(LONG x, LONG y, LONG depth = 24)
  {
   // initialize the bitmap
   BaseDocument* doc = GetActiveDocument();
   BaseContainer rdata = doc->GetActiveRenderData()->GetData();
   if( !m_pBmp || m_pBmp->Init( x, y,depth ) != IMAGE_OK ) 
    return false;
           
   return true;
  }

virtual void Draw(LONG x1, LONG y1, LONG x2, LONG y2, LONG flag = 0 )
  {
   // if we have a valid bitmap, render it into the specified region
   if( m_pBmp )
   {
    DrawBitmap( m_pBmp, x1, y1, x2-x1, y2-y1, 0, 0, m_pBmp->GetBw(), m_pBmp->GetBh(), BMP_NORMALSCALED | BMP_ALLOWALPHA );
   }
   this->Redraw( TRUE);
  }
       virtual BaseBitmap* GetBitMap()
    {
     BaseBitmap* bmp = NULL;
     m_pBmp->CopyTo( bmp );
    
     return bmp;
    }
     
};
//////////////////////////////////////////////////////////////////////////////////////////////
class ModalRenderer : private GeModalDialog
{
private:
  BaseDocument* m_doc;
  BaseContainer m_rdata;
  String m_title;
   Bool m_showerrors;
   PreviewAreaBmp m_bmparea;
  Real m_p;
  LONG m_result;
  enum
  {
    SCROLL_GROUP_ID = 100000,
    PREVIEW_AREA_ID,
    DLGGROUP_ID,
    MAIN_GROUP_ID
  };
  class RenderThread : public Thread
  {
 private:
    ModalRenderer* m_dlg;
 public:
    RenderThread(ModalRenderer* dlg) : m_dlg(dlg) {}
    virtual ~RenderThread() { m_dlg = NULL; End(); Wait(FALSE); }
    virtual void Main()
    {
     if (!m_dlg) return;
     // Start render
     /*MessageDialog("SETP_ ThreadMain()!");*/
     LONG result =
     RenderDocument( m_dlg->m_doc,                    
        m_dlg->m_rdata,
        ProgressFunction,
        m_dlg,
        m_dlg->m_bmparea.m_pBmp,    
        m_dlg->m_showerrors,
        (BaseThread* )this->Get());
       
     if (m_dlg)
     {
      m_dlg->m_result = result;
     }
    }
    virtual const CHAR *GetThreadName(void)
    {
     char szThreadName[128]= {0};
     char *p = NULL;
     //GET THREAD NAME
     //RETURN
                    p = szThreadName;
     return p;
    }
 private:
    
   // Called by RenderDocument now and then
    static void ProgressFunction(Real p, void* dlg)
    {
     static_cast<ModalRenderer*>(dlg)->m_p = p;
    }
 } m_rt;
   
    friend class RenderThread;
public:
   ModalRenderer() :
      m_doc(NULL), 
      m_p(0.0),
      m_result(NOTOK),
      m_showerrors(TRUE),
      m_rt(this) { }
  
 
 virtual ~ModalRenderer()
 { 
   ShutdownThread();
 }
  // Render document 'doc' with settings 'rdata',
  // displaying a progress windows with 'title' and
  // optionally not showing error messages.
  Bool Render(BaseDocument* doc, const BaseContainer& rdata,
              const String& title = String(), Bool showerrors = TRUE)
  {
  if (!doc) return FALSE;
    
  if ( m_rt.IsRunning() )
  {   
   return FALSE;
  }
  
  m_doc = doc;
  m_rdata = rdata;
  m_title = title;
  m_showerrors = showerrors;
       
  Bool success = Open();
  
  ShutdownThread();
  return success && GetResult();
  }
//----------------------------------------------------------------------------------------------------
private:
    // Build the dialog
  virtual Bool CreateLayout()
  {
  if (!InitBitmap()) return FALSE;
   
  SetTitle(m_title);
  GroupBegin(MAIN_GROUP_ID, BFV_SCALEFIT | BFH_SCALEFIT, 1, 0, "", 0);
  {
   GroupSpace(4,4);
   ScrollGroupBegin(SCROLL_GROUP_ID, BFV_SCALEFIT | BFH_SCALEFIT,
      SCROLLGROUP_STATUSBAR | SCROLLGROUP_BORDERIN |
      SCROLLGROUP_NOBLIT);
   {
     //@@@@@@@@ at here is my modify,
    // I have been added  to class PreviewAreaBmp
   //but is fail from [email protected]@@@@@@@@@@@*/

//AddUserArea( PREVIEW_AREA_ID, 0, m_bmp->GetBw(), m_bmp->GetBh());
   //AttachImage(PREVIEW_AREA_ID, m_bmp, 0);

AddUserArea( PREVIEW_AREA_ID, 0, m_bmparea.m_pBmp->GetBw(), m_bmparea.m_pBmp->GetBh());
     
            
    AttachUserArea( m_bmparea, PREVIEW_AREA_ID);
          
   }
   GroupEnd();
   AddDlgGroup(DLG_CANCEL);
  }
  GroupEnd();
  return TRUE;
  }
  // Init dialog and start render
  virtual Bool InitValues()
  {
  UpdatePreview();
  SetTimer(500);
  Bool success = TRUE;
  
  if (!m_rt.IsRunning())
  {
   
   success = m_rt.Start(TRUE);
  }
  return success;
  }
  // Ask if the render is running
  virtual Bool AskClose()
  {
    
  if (!m_rt.IsRunning()) return FALSE;
     return !QuestionDialog("Do you really want to abort the rendering?");
  }
  // Deal with close box and cancel button problems
  virtual LONG Message(const BaseContainer &msg, BaseContainer &result)
  {
  // Workaround for bad base class implementation
  if (msg.GetId() == BFM_ACTION &&
   msg.GetLong(BFM_ACTION_ID) == IDC_CANCEL)
  {
   return Command(IDC_CANCEL, msg);
  }
  else if (msg.GetId() == BFM_CHECKCLOSE)
  {
   return AskClose();
  }
  else
  {
   return GeModalDialog::Message(msg,result);
  }
  }
  // Check for cancel button
  virtual Bool Command(LONG id, const BaseContainer& msg)
  {
  if (id == IDC_CANCEL && !AskClose())
  {
   ShutdownThread();
   return Close(FALSE);
  }
  return FALSE;
  }
  // Run every 500 ms...
  virtual void Timer(const BaseContainer& msg)
  {
  UpdatePreview();
  UpdateStatus();
  CheckFinished();
  }

// Create preview bitmap
  Bool InitBitmap()
  {  
     m_bmparea.Init( m_rdata.GetLong(RDATA_XRES), m_rdata.GetLong(RDATA_YRES) );
     return true;
  }
  // Tell the preview to redraw itself
  void UpdatePreview()
  {
  //GetUserArea is error from compile
  /*GeUserArea* ua = GetUserArea(PREVIEW_AREA_ID);*/
    //if (ua) ua->Redraw(TRUE);
    m_bmparea.Draw( 0, 0, m_rdata.GetLong(RDATA_XRES),  m_rdata.GetLong(RDATA_YRES) );
    //m_bmparea.Redraw( TRUE );
    
 
  }
  // Set new statusline text
  void UpdateStatus()
  {
  String txt;
  if (m_p != 1.0)
  {
  txt = "Rendering: " + LongToString(m_p * 100) + "%";
  }
  else
  {
  txt = "Finished!";
  }
  BaseContainer msg(BFM_SETSTATUSBAR);
  msg.SetLong(BFM_STATUSBAR_PROGRESSON, TRUE);
  msg.SetString(BFM_STATUSBAR_TXT, txt);
  msg.SetReal(BFM_STATUSBAR_PROGRESS, m_p);
  SendMessage(SCROLL_GROUP_ID, msg);
  }
  // Wait until render thread is stopped
  void ShutdownThread()
  { 
   m_rt.End();
   m_rt.Wait(FALSE);
  }
  // Check if the render is finished
  void CheckFinished()
  {
   if (!m_rt.IsRunning())
  {
   Close(m_result == RAY_OK);
  }
  }

// Internal class with render thread
 
 
  // So that the internal class can access private variables
 
 
};
#endif
 
///////////////////////////////////////////////////////////////////////////////////////////////
void ModulRender()
{
 BaseDocument* doc = GetActiveDocument();
 BaseObject* null = doc->GetActiveObject();
  if (!null) return;
BaseContainer rdata = doc->GetActiveRenderData()->GetData();
BaseBitmap* bmp = BaseBitmap::Alloc();
bmp->Init(rdata.GetLong(RDATA_XRES),
    rdata.GetLong(RDATA_YRES));
RenderDocument(doc, rdata, NULL , NULL, bmp, TRUE , NULL);
bmp->Save( GeGetStartupPath() + "test_modul.jpg", FILTER_JPG, NULL, SAVEBIT_32b*tchANNELS);
 
ShowBitmap(bmp);
 BaseBitmap::Free( bmp );
ModalRenderer mr;
Bool success = mr.Render(doc, rdata, null->GetName(), TRUE);
 
  MessageDialog("Finish!");
}

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 22/07/2007 at 02:00, xxxxxxxx wrote:

note:  the originality data like this. from http://www.plugincafe.com/forum/display_topic_threads.asp?ForumID=4&TopicID=656&SearchPagePosition=1&search=ModalRenderer&searchMode=allwords&searchIn=Thread&forum=0&searchSort=dateDESC&ReturnPage=Search
private:
 BaseDocument* m_doc;
  BaseContainer m_rdata;
  String m_title;
  BaseBitmap* m_bmp;
  Bool m_showerrors;
 
  Real m_p;
  LONG m_result;
  enum
  {
    SCROLL_GROUP_ID = 100000,
    PREVIEW_AREA_ID,
    DLGGROUP_ID,
    MAIN_GROUP_ID
  };