Pass a vector from a pushbutton in dialog class to ONDRAW () in the view.cpp
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 53

Thread: Pass a vector from a pushbutton in dialog class to ONDRAW () in the view.cpp

Hybrid View

  1. #1
    Join Date
    Jun 2012
    Posts
    37

    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

  2. #2
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    5,927

    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

  3. #3
    Join Date
    Jun 2012
    Posts
    37

    Re: Pass a vector from a pushbutton in dialog class to ONDRAW () in the view.cpp

    Quote Originally Posted by Igor Vartanov View Post
    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..

  4. #4
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    5,927

    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

  5. #5
    Join Date
    Jun 2012
    Posts
    37

    Re: Pass a vector from a pushbutton in dialog class to ONDRAW () in the view.cpp

    Quote Originally Posted by Igor Vartanov View Post
    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

  6. #6
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    12,053

    Re: Pass a vector from a pushbutton in dialog class to ONDRAW () in the view.cpp

    Quote Originally Posted by tarkes View Post
    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.

  7. #7
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,288

    Re: Pass a vector from a pushbutton in dialog class to ONDRAW () in the view.cpp

    Quote Originally Posted by tarkes View Post
    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

  8. #8
    Join Date
    Jun 2012
    Posts
    37

    Re: Pass a vector from a pushbutton in dialog class to ONDRAW () in the view.cpp

    Quote Originally Posted by VictorN View Post
    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.

  9. #9
    Join Date
    Jun 2012
    Posts
    37

    Re: Pass a vector from a pushbutton in dialog class to ONDRAW () in the view.cpp

    Quote Originally Posted by tarkes View Post
    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.


    Quote Originally Posted by VictorN View Post
    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)

    #
    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.

  10. #10
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,288

    Re: Pass a vector from a pushbutton in dialog class to ONDRAW () in the view.cpp

    Quote Originally Posted by tarkes View Post
    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

  11. #11
    Join Date
    Jun 2012
    Posts
    37

    Re: Pass a vector from a pushbutton in dialog class to ONDRAW () in the view.cpp

    Quote Originally Posted by VictorN View Post
    What is a pView and where do you call this line from?
    Quote Originally Posted by Igor Vartanov View Post
    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.

  12. #12
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    12,053

    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.

  13. #13
    Join Date
    Jun 2012
    Posts
    37

    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

  14. #14
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    5,927

    Re: Pass a vector from a pushbutton in dialog class to ONDRAW () in the view.cpp

    Quote Originally Posted by tarkes View Post
    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

  15. #15
    Join Date
    Jun 2012
    Posts
    37

    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.

Page 1 of 2 12 LastLast

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
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center