Click here to Skip to main content
15,923,273 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: CPU Usage Pin
Cedric Moonen3-Mar-10 2:24
Cedric Moonen3-Mar-10 2:24 
AnswerRe: CPU Usage Pin
Rajesh R Subramanian2-Mar-10 23:32
professionalRajesh R Subramanian2-Mar-10 23:32 
AnswerRe: CPU Usage Pin
Adam Roderick J2-Mar-10 23:37
Adam Roderick J2-Mar-10 23:37 
AnswerRe: CPU Usage Pin
CPallini3-Mar-10 0:06
mveCPallini3-Mar-10 0:06 
AnswerRe: CPU Usage Pin
Moak3-Mar-10 1:55
Moak3-Mar-10 1:55 
AnswerRe: CPU Usage Pin
David Crow3-Mar-10 3:06
David Crow3-Mar-10 3:06 
Questionto change user name of windows Pin
zon_cpp2-Mar-10 23:15
zon_cpp2-Mar-10 23:15 
AnswerRe: to change user name of windows Pin
Rajesh R Subramanian2-Mar-10 23:31
professionalRajesh R Subramanian2-Mar-10 23:31 
QuestionSetting a CToolBar Button's Label to take multiple lines of text Pin
David Ferreira2-Mar-10 22:54
David Ferreira2-Mar-10 22:54 
AnswerRe: Setting a CToolBar Button's Label to take multiple lines of text Pin
KarstenK2-Mar-10 23:43
mveKarstenK2-Mar-10 23:43 
GeneralRe: Setting a CToolBar Button's Label to take multiple lines of text Pin
David Ferreira2-Mar-10 23:54
David Ferreira2-Mar-10 23:54 
GeneralRe: Setting a CToolBar Button's Label to take multiple lines of text Pin
KarstenK3-Mar-10 0:36
mveKarstenK3-Mar-10 0:36 
GeneralRe: Setting a CToolBar Button's Label to take multiple lines of text Pin
David Ferreira3-Mar-10 1:14
David Ferreira3-Mar-10 1:14 
GeneralRe: Setting a CToolBar Button's Label to take multiple lines of text Pin
KarstenK3-Mar-10 1:30
mveKarstenK3-Mar-10 1:30 
QuestionHow to compute Islamic prayer time everyday? [modified] Pin
fantasy12152-Mar-10 21:41
fantasy12152-Mar-10 21:41 
AnswerRe: How to compute Islamic prayer time everyday? Pin
Rajesh R Subramanian2-Mar-10 22:47
professionalRajesh R Subramanian2-Mar-10 22:47 
QuestionRe: How to compute Islamic prayer time everyday? Pin
David Crow3-Mar-10 3:14
David Crow3-Mar-10 3:14 
AnswerRe: How to compute Islamic prayer time everyday? Pin
fantasy12153-Mar-10 16:23
fantasy12153-Mar-10 16:23 
GeneralRe: How to compute Islamic prayer time everyday? Pin
Game-point3-Mar-10 19:05
Game-point3-Mar-10 19:05 
QuestionMFC Drag & Drop Between two Tree control [modified] Pin
vkpMark2-Mar-10 20:39
vkpMark2-Mar-10 20:39 
AnswerRe: MFC Drag & Drop Between two Tree control [modified] Pin
SandipG 2-Mar-10 21:14
SandipG 2-Mar-10 21:14 
GeneralRe: MFC Drag & Drop Between two Tree control Pin
vkpMark2-Mar-10 21:50
vkpMark2-Mar-10 21:50 
GeneralRe: MFC Drag & Drop Between two Tree control Pin
vkpMark3-Mar-10 0:37
vkpMark3-Mar-10 0:37 
QuestionwxWidgets and themes Pin
zqueezy2-Mar-10 19:50
zqueezy2-Mar-10 19:50 
QuestionHow To Serailize collection class object Pin
adityarao312-Mar-10 19:45
adityarao312-Mar-10 19:45 
I have simple CLine class which has two member variables
which store first and last point of line.I store set of drawn lines in CObArray .Now I want to save the set of lines which I have drawn on CView on save button. And Get All lines back
on open button click. Means serialize and deserialize in and out of
CObArray Collection class.

I have tried as shown in code. but I get no values where I have mentioned in code.Thus enable to retrieve the saved drawing.
Can any one help me on this issue?


// Serialization3View.cpp : implementation of the CSerialization3View class
//

#include "stdafx.h"
#include "Serialization3.h"

#include "Serialization3Doc.h"
#include "Serialization3View.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CSerialization3View

IMPLEMENT_DYNCREATE(CSerialization3View, CView)

BEGIN_MESSAGE_MAP(CSerialization3View, CView)
//{{AFX_MSG_MAP(CSerialization3View)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
ON_COMMAND(ID_FILE_SAVE, OnFileSave)
ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSerialization3View construction/destruction

CSerialization3View::CSerialization3View()
{
// TODO: add construction code here

}

CSerialization3View::~CSerialization3View()
{
}

BOOL CSerialization3View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs

return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CSerialization3View drawing

void CSerialization3View::OnDraw(CDC* pDC)
{
CSerialization3Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
int liCount = pDoc->GetLineCount();
if(liCount > 1)
{
int lipos;
CLine* l;
for(lipos = 0;lipos < liCount;lipos++)
{
l = pDoc->GetLine(lipos);
l->Draw(pDC);
}
}
// TODO: add draw code for native data here
}

/////////////////////////////////////////////////////////////////////////////
// CSerialization3View printing

BOOL CSerialization3View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}

void CSerialization3View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}

void CSerialization3View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CSerialization3View diagnostics

#ifdef _DEBUG
void CSerialization3View::AssertValid() const
{
CView::AssertValid();
}

void CSerialization3View::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}

CSerialization3Doc* CSerialization3View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CSerialization3Doc)));
return (CSerialization3Doc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CSerialization3View message handlers

void CSerialization3View::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
SetCapture();
m_ptPrevPos = point;

CView::OnLButtonDown(nFlags, point);
}

void CSerialization3View::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(GetCapture() == this)
ReleaseCapture();
CView::OnLButtonUp(nFlags, point);
}

void CSerialization3View::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if((nFlags & MK_LBUTTON) == MK_LBUTTON)
{
if(GetCapture() == this)
{
CClientDC dc(this);
CLine *pLine =
GetDocument()->AddLine(m_ptPrevPos,point);
pLine->Draw(&dc);
m_ptPrevPos = point;
}
}
CView::OnMouseMove(nFlags, point);
}

void CSerialization3View::OnFileSave()
{
CSerialization3Doc* pDoc = GetDocument();
pDoc->fp.SeekToBegin();
CArchive ar(&(pDoc->fp),CArchive::store);
pDoc->m_oaLines.Serialize(ar);

}

void CSerialization3View::OnFileOpen()
{


CSerialization3Doc* pDoc = GetDocument();

pDoc->m_oaLines.RemoveAll();
RECT r;
GetWindowRect(&r);
InvalidateRect(&r,true);
pDoc->fp.SeekToBegin();
CArchive ar(&(pDoc->fp),CArchive::load);
pDoc->m2.Serialize(ar);
// here I expect that m2 obarray get all saved Lines
//but It does not happen.//
int liCount = pDoc->m2.GetSize();
if(liCount)
{
int lipos;
CLine* l;
for(lipos = 0;lipos < liCount;lipos++)
{

l = (CLine*)(pDoc->m2.GetAt(lipos));
//***************************************************
//But This does not work as l contains no values
CDC* dc = this->GetDC();
l->Draw(dc);
}
}

}
Be Happy

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.