CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 4 1234 LastLast
Results 1 to 15 of 53
  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
    6,620

    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
    6,620

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

  7. #7
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    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.

  8. #8
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    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

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

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

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

  12. #12
    Join Date
    Jun 2012
    Posts
    37

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

    For eg in the
    ONDRAW(CDC *pDC)
    For (i=0 to end)
    for j= 0 to end

    //Do the operations
    pDC->SETPIXEL(i,j,RGB(values,values,values) //I get values from VECTOR
    //calculation
    }}

  13. #13
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    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

  14. #14
    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
    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)
    I have attached the codes i had written.. pView i declared
    void CColourdlg::OnPlot() ... that I was just experimenting if it was working..But i have deleted that...
    These codes I had atached work perfectly and generated the vector in a text file.. The text file i was experimenting wether the desired output is obatined.. I donot need the text file. The vector has to be accesed in ONDRAW() which i will be using to calcute RGB values and use them in plotting pixels. I hope the problem is clear now..

    Yes during my search i could find those links but I donot know those links donot work.. I think in this country it doesnot work...

  15. #15
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

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

    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.

Page 1 of 4 1234 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
  •  





Click Here to Expand Forum to Full Width

Featured