Pass a vector from a pushbutton in dialog class to ONDRAW () in the view.cpp
I am creating an SDI to plot a picture pixel wise using pDC->setpisel()
I have a large 2D vector which is generate in PLOT button in a dialog . On pressing the 2d vector is generated. How will I pass this 2D vector to ONDRAW(CDC*pDC). So that i can process further the vector and put as pixels using for loop.. I donot know if ::Postmessage could workout.. How to use it if it does so??
I would be highly thankkful for ideas and sugestions
Re: Pass a vector from a pushbutton in dialog class to ONDRAW () in the view.cpp
Originally Posted by Igor Vartanov
Easy. The vector belongs with your app document class. Document is accessible from your view any time.
But how do i call the ONDRAW () from the ONBUTTON() in dialog class.. The vector was declared and created ONBUTTON function itself.. Actually it reads a text file and geenrated the vector..
I am bit new to visual C++ 6..
Re: Pass a vector from a pushbutton in dialog class to ONDRAW () in the view.cpp
Originally Posted by tarkes
Yes that is true but pView->Invalidate() doesnot work.. It shows undeclared identifier
Then set up a pointer to your view as a member of your dialog and set it before you call DoModal, or pass the view's pointer in as the parent of the dialog when you create it, and call GetParent from inside the dialog.
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?
I have push button () in dlg.cpp file..There I have generated the vector by reading a text consists of number for calculations..
pView i declared there.
Re: Pass a vector from a pushbutton in dialog class to ONDRAW () in the view.cpp
Originally Posted by tarkes
I have push button () in dlg.cpp file..There I have generated the vector by reading a text consists of number for calculations..
pView i declared there.
Originally Posted by VictorN
Where "there"? And how?
And what does it have to do with a pointer to existing View class object?
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;
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++;
::MessageBeep((WORD)-1);
}
ncols=j;
nrows=i;
ifs.close();
std::vector<double>::iterator itr;
std::vector<double>::iterator col;
std::vector< std::vector<double> >::iterator row;
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() );
// Divide with maximum value
for (row = vec.begin(); row != vec.end(); row++)
{
for (col = row->begin(); col != row->end(); col++)
{
*col=(*col/ *itr);;
}
}
ofs.open("Matrix.txt");
//ofs<<vec[1][1];
for (k=0;k<nrows;k++)
{
for (l=0;l<ncols;l++)
{ofs<<vec[k][l]<<'\t';} ofs<<'\n';}
ofs.close();
OnOK();
}
This isthe code written to read text with tab separtaed values and vector i generated.. It is in dlg.cpp file ..Now I neeed to call this in ONDRAW(CDC pDC)..
Code:
void CContourPlotView::OnDraw(CDC* pDC)
{
CContourPlotDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
Last edited by tarkes; June 5th, 2012 at 08:40 AM.
Re: Pass a vector from a pushbutton in dialog class to ONDRAW () in the view.cpp
Originally Posted by tarkes
I have push button () in dlg.cpp file..There I have generated the vector by reading a text consists of number for calculations.. pView i declared there.
Where "there"? And how?
And what does it have to do with a pointer to existing View class object?
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
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
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
I have push button () in dlg.cpp file..There I have generated the vector by reading a text consists of number for calculations..
pView i declared there.
Bookmarks