CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 4 FirstFirst 1234 LastLast
Results 16 to 30 of 53
  1. #16
    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 GCDEF View Post
    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..

  2. #17
    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 gcdef View Post
    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.

    sooryy ..extremely sorry.. I dodnot see your post.. I missed yours. Let me try your suggestion




    Yes it was sucefful... Could u sugeest me..how to acess the vector.. The vector I am not able to acess in ONDRAW().. Please help me..
    Last edited by tarkes; June 5th, 2012 at 09:16 AM.

  3. #18
    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
    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?

  4. #19
    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
    sooryy ..extremely sorry.. I dodnot see your post.. I missed yours. Let me try your suggestion




    Yes it was sucefful... Could u sugeest me..how to acess the vector.. The vector I am not able to acess in ONDRAW().. Please help me..
    Again, the vector should be a member of the document class. It should not exist in the dialog class.

  5. #20
    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 GCDEF View Post
    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..

  6. #21
    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 GCDEF View Post
    Again, the vector should be a member of the document class. It should not exist in the dialog class.
    yess I was guessing that.. Got some Idea.. i will try that in the night.. Thanks a lot..

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

    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

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

  9. #24
    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 haven't shown enough code and it's not clear what "gets stuck" means.

  10. #25
    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 GCDEF View Post
    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.

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


    Please, edit your post adding Code tags aroung code snippet!
    Victor Nijegorodov

  12. #27
    Join Date
    Apr 1999
    Posts
    27,449

    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 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:
    Code:
        TCHAR lpData[500] = {0};
        pEdit->GetLine(0,lpData,500);
    If for some reason you wanted to use vector:
    Code:
    std::vector<TCHAR> lpData(500);
    pEdit->GetLine(0, &lpData[0], lpData.size());
    Either the array or vector version will not cause the memory leak.

    Regards,

    Paul McKenzie

  13. #28
    Join Date
    Jun 2012
    Posts
    37

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

    I have attached a snap shot of working window showing CDOCUMENT.h file opened.. Please have alook at it
    Attached Images Attached Images  

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

    First. The code is almost unreadable because of using no code tags.

    Second. What is pDoc- > RGBVector definition?

    Code:
    std::vector<int> temp;
    temp.push_back(R);
    temp.push_back(G);
    temp.push_back(B);
    pDoc->RGBVector.push_back(temp);
    Third. RGB perfectly fits into 32bit:
    Code:
    COLORREF temp = RGB(R, G, B);
    EDIT: the latter means, there's no need to pile arrays on arrays. BTW, it seems you never care about cleaning RGBVector.
    Last edited by Igor Vartanov; June 5th, 2012 at 03:21 PM.
    Best regards,
    Igor

  15. #30
    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 Paul McKenzie View Post
    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:
    Code:
        TCHAR lpData[500] = {0};
        pEdit->GetLine(0,lpData,500);
    If for some reason you wanted to use vector:
    Code:
    std::vector<TCHAR> lpData(500);
    pEdit->GetLine(0, &lpData[0], lpData.size());
    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.

Page 2 of 4 FirstFirst 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