-
June 5th, 2012, 07:41 AM
#1
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
-
June 5th, 2012, 07:53 AM
#2
Re: Pass a vector from a pushbutton in dialog class to ONDRAW () in the view.cpp
Easy. The vector belongs with your app document class. Document is accessible from your view any time.
Best regards,
Igor
-
June 5th, 2012, 07:56 AM
#3
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..
-
June 5th, 2012, 07:59 AM
#4
Re: Pass a vector from a pushbutton in dialog class to ONDRAW () in the view.cpp
But how do i call the ONDRAW () from the ONBUTTON() in dialog class.
You must never call OnDraw directly. Instead, you call pView->Invalidate().
The vector was declared and created ONBUTTON function itself.
And again, the vector belongs with your document class. This is your data to make drawing on.
Best regards,
Igor
-
June 5th, 2012, 08:04 AM
#5
Re: Pass a vector from a pushbutton in dialog class to ONDRAW () in the view.cpp
Originally Posted by Igor Vartanov
You must never call OnDraw directly. Instead, you call pView->Invalidate().
And again, the vector belongs with your document class. This is your data to make drawing on.
Yes that is true but pView->Invalidate() doesnot work.. It shows undeclared identifier
-
June 5th, 2012, 08:09 AM
#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.
-
June 5th, 2012, 08:09 AM
#7
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
What is a pView and where do you call this line from?
Victor Nijegorodov
-
June 5th, 2012, 08:15 AM
#8
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.
-
June 5th, 2012, 08:18 AM
#9
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
#
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;
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.
-
June 5th, 2012, 08:31 AM
#10
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?
BTW, did you ever hear there is a lot of samples in MSDN, also for SDI with Doc/View architecture?
http://msdn.microsoft.com/en-us/libr...386059(v=vs.71)
http://msdn.microsoft.com/en-us/libr...386073(v=vs.71)
Victor Nijegorodov
-
June 5th, 2012, 02:41 PM
#11
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.
-
June 5th, 2012, 02:45 PM
#12
Re: Pass a vector from a pushbutton in dialog class to ONDRAW () in the view.cpp
You haven't shown enough code and it's not clear what "gets stuck" means.
-
June 5th, 2012, 08:08 AM
#13
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
-
June 5th, 2012, 09:39 AM
#14
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.
Best regards,
Igor
-
June 5th, 2012, 08:14 AM
#15
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.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|