Re: Pass a vector from a pushbutton in dialog class to ONDRAW () in the view.cpp
Originally Posted by GCDEF
You're not listening to the advice being offered. That tends to stop the help from coming.
As mentioned, data belongs in the document class.
Your dialog needs access to your view so it can invalidate it. I told you a couple of ways to set that up.
In OnDraw, call GetDocument() to get the data from the document object.
If you're going to ask for help, you should listen to it.
Code:
void CContourPlotView::OnDraw(CDC* pDC)
{
CContourPlotDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
This code is already writeen. The variable i ha used for 2D vector is vec.
when i use vec in ONDRAW(). it shows undeclared identifier
I have attached the complete set of codes above in the discussion i had written in ONPLOT() in the contourplotdlg.cpp which is dialog
Please have a look at it..
Re: Pass a vector from a pushbutton in dialog class to ONDRAW () in the view.cpp
Originally Posted by tarkes
Code:
void CContourPlotView::OnDraw(CDC* pDC)
{
CContourPlotDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
This code is already writeen. The variable i ha used for 2D vector is vec.
when i use vec in ONDRAW(). it shows undeclared identifier
I have attached the complete set of codes above in the discussion i had written in ONPLOT() in the contourplotdlg.cpp which is dialog
Please have a look at it..
I did look at it. At this point all I can really say, and I don't mean this in a bad way as everybody starts somewhere, is you're not understanding some very fundamental concepts of OOP and doc/view architecture.
Do you understand classes and their member variables?
Re: Pass a vector from a pushbutton in dialog class to ONDRAW () in the view.cpp
Originally Posted by GCDEF
I did look at it. At this point all I can really say, and I don't mean this in a bad way as everybody starts somewhere, is you're not understanding some very fundamental concepts of OOP and doc/view architecture.
Do you understand classes and their member variables?
yess yess and i do understand that.. It was sucessful what u had suggested..
I need an if condition in ONDRAW() so that when i call invalidate if (invalidate is called) then follwo the plotting instructions;
Now How to acess the vector in ONDRAW()...
Please donot mind. from last 10 days I am struggling.. May be in confusion state i am asking silly questions.. I am in learning stage also and beginner.. Gradually once I pickup and understand it i will be able to do..
Re: Pass a vector from a pushbutton in dialog class to ONDRAW () in the view.cpp
Originally Posted by tarkes
Soory If i am asking any stupid question.. But I am bit new to the Visual C++ 6.. I am in beginner stage working on it and learnign it..Please Kindly help me
You show us no real project. So we have to answer with something that you have to adopt in your code some way proper for your real code. In case you're not able to do that, you're stuck, no matter how sorry you are about this.
To have a conversation both sides must speak the same language. So, please put aside your current project and try to analyze the sample Victor recommended you, as well as other samples from MSDN site. Play with the samples, modify them and see what effect your changes cause. Buy (or lend from somebody) some books on MFC programming and work those through. When you understand the concept, please come back, you're always welcome.
Re: Pass a vector from a pushbutton in dialog class to ONDRAW () in the view.cpp
Originally Posted by VictorN
What is a pView and where do you call this line from?
Originally Posted by Igor Vartanov
You show us no real project. So we have to answer with something that you have to adopt in your code some way proper for your real code. In case you're not able to do that, you're stuck, no matter how sorry you are about this.
To have a conversation both sides must speak the same language. So, please put aside your current project and try to analyze the sample Victor recommended you, as well as other samples from MSDN site. Play with the samples, modify them and see what effect your changes cause. Buy (or lend from somebody) some books on MFC programming and work those through. When you understand the concept, please come back, you're always welcome.
Ok I followed all the instructions as given.. All codes compile successfully without any errror. But during execution it gets stuck.
I found that this statement makes the loop stuck and ends the SDI
pDoc->RGBVector.push_back(temp)
pDoc- is a CContourPlotDoc pointer declared in CONTOURdialog (userdefined) header file inherited from CDialog class
RGBVector- declared in CContourPlotDoc.h file which stores the RGB values in vector
temp is RGB value vector 3*1 and pushed into RGBVector
It is done so that I can access the RGB vector in ONDRAW()
Is there any syntax error. or the methodology is wrong??
Last edited by tarkes; June 5th, 2012 at 02:44 PM.
Re: Pass a vector from a pushbutton in dialog class to ONDRAW () in the view.cpp
Originally Posted by GCDEF
You haven't shown enough code and it's not clear what "gets stuck" means.
Code:
void CColourdlg::OnPlot()
{
// TODO: Add your control notification handler code here
//Getting number of rows and columns
int j=0,i=0,k=0,l=0,ncols=0, nrows=0,R=0,G=0,B=0;
double array[10][10]={0};
std::ofstream ofs;
CEdit *pEdit = (CEdit*)GetDlgItem(IDC_EDIT1);
LPTSTR lpData = new TCHAR[500];
ZeroMemory(lpData,500*sizeof(TCHAR));
pEdit->GetLine(0,lpData,500);
std::string line;
std::ifstream ifs(lpData,ios::nocreate);
//Declare a Matrix pointer
std::vector< std::vector<double> > vec;
//Store in Matrix
//ifs.open(lpData,ios::nocreate);
std::string lin;
while (std::getline(ifs, lin)) // read one line at a time
{
double val;
std::istringstream jss(lin);
std::vector<double> row;
j=0;
while (jss >> val) // read one value at at time from the line
{
row.push_back(val);
j++;
}
vec.push_back(row);
i++;
}
ncols=j;
nrows=i;
ifs.close();
//pDoc->size.push_back(nrows);
//pDoc->size.push_back(ncols);
std::vector<double>::iterator itr;
std::vector<double>::iterator col;
std::vector< std::vector<double> >::iterator row;
std::vector< std::vector<int> > rgbvec;
std::vector<double> vec_rmax;
for (row = vec.begin(); row != vec.end(); row++)
{
itr=std::max_element( row->begin(), row->end() );
vec_rmax.push_back(*itr);
}
itr=std::max_element( vec_rmax.begin(), vec_rmax.end() );
::MessageBeep((WORD)-1);
// Divide with maximum value
for (row = vec.begin(); row != vec.end(); row++)
{
for (col = row->begin(); col != row->end(); col++)
{
*col=(*col/ *itr);
if (*col==0 || *col<0.142857)
{R=148;G=0;B=211;}
else if (*col==0.142857 || *col<0.285714)
{R=75;G=0;B=130;}
else if (*col>=0.285714 || *col<0.428571)
{R=0;G=0;B=255;}
else if (*col>=0.428571 || *col<0.571428)
{R=0;G=255;B=0;}
else if (*col>=0.571428 || *col<0.714286)
{R=255;G=255;B=0;}
else if (*col>=0.714286 || *col<0.857143)
{R=255;G=127;B=0;}
else
{R=255;G=0;B=0;}
std::vector<int> temp;
temp.push_back(R);
temp.push_back(G);
temp.push_back(B);
pDoc->RGBVector.push_back(temp);
}
}
ofs.open("Matrix.txt");
//ofs<<temp[0];
/*for (k=0;k<nrows;k++)
{
for (l=0;l<ncols;l++)
{ofs<<vec[k][l]<<'\t';} ofs<<'\n';}
ofs.close();
pView->Invalidate();*/
OnOK();
}
I have marked it red during looping. this is PLOTBUTTON() in Contoutdlg.cpp source file
Once it is updates the vector declared in Document.h I can acess it in ONDRAW()
Last edited by tarkes; June 5th, 2012 at 02:51 PM.
Re: Pass a vector from a pushbutton in dialog class to ONDRAW () in the view.cpp
Originally Posted by tarkes
I have marked it red during looping. this is PLOTBUTTON() in Contoutdlg.cpp
But you failed to use code tags when posting code. The code you posted is unreadable without proper use of code tags.
Second:
Code:
LPTSTR lpData = new TCHAR[500];
ZeroMemory(lpData,500*sizeof(TCHAR));
You're using vectors all over the place, so why did you not want to use it here? Because of this, your code has a memory leak every time you call OnPlot.
As a matter of fact, all you need to do is declare an array since you know the size already:
Re: Pass a vector from a pushbutton in dialog class to ONDRAW () in the view.cpp
Originally Posted by Paul McKenzie
But you failed to use code tags when posting code. The code you posted is unreadable without proper use of code tags.
Second:
Code:
LPTSTR lpData = new TCHAR[500];
ZeroMemory(lpData,500*sizeof(TCHAR));
You're using vectors all over the place, so why did you not want to use it here? Because of this, your code has a memory leak every time you call OnPlot.
As a matter of fact, all you need to do is declare an array since you know the size already:
Either the array or vector version will not cause the memory leak.
Regards,
Paul McKenzie
For calculation puroposes i need values and so do i store it in vector format.. I have attached a screen shot as weel as i have quoted the code. Please have a look.
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.