simple loop problem or pixel one
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Thread: simple loop problem or pixel one

  1. #1
    Join Date
    May 2009
    Posts
    88

    Post simple loop problem or pixel one

    my code goes as
    1.I check if the pixel colour is different from bakground colour in onLbutton down function
    by
    if(GetPixel(hDC,point.x,point.y)==RGB(0,0,128))
    {
    busindex=pDoc->InBus (tempx ,tempy );
    if(busindex>=0)
    {SetCapture();m_dragging=TRUE;}

    }
    2.my InBus ftn checks as:

    InBus
    {
    CBus1* bus;
    bus=GetBus(index);
    if( x>= bus->m_x1 && x<=abs(bus->m_x2 -bus->m_x1))
    {
    if( y>= bus->m_y1 && y<=abs(bus->m_y2 -bus->m_y1))
    {
    return index;
    }
    return -1;
    }
    getbus simply return a pointer 2 dat object in an array
    this should return a index of object that has co-ordinates enclosing x,y
    the problem is in 2 step it never goes in that if statements......
    i cud not get it y??
    1 reason i thought was of Mapping of co-ordinates....any ways pllzz think ........
    thnx

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

    Re: simple loop problem or pixel one

    Please rewrite your post using code tags and words found in a typical English dictionary.

    This isn't the first time code tags and real words have been mentioned to you. You want help, you need to follow the protocol.
    Last edited by GCDEF; May 27th, 2009 at 04:32 PM.

  3. #3
    Join Date
    May 2009
    Posts
    88

    Re: simple loop problem or pixel one

    sir agreed my code is not is according to proper tags and tagging it will take another some hour or so but if you can please help me out with this right now.....actually am in shortage of time...and have to submit the project.....sir co-ordinate and help me out...
    hope you would co-operate and help me out

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

    Re: simple loop problem or pixel one

    Quote Originally Posted by pinnachio View Post
    sir agreed my code is not is according to proper tags and tagging it will take another some hour or so but if you can please help me out with this right now.....actually am in shortage of time...and have to submit the project.....sir co-ordinate and help me out...
    hope you would co-operate and help me out
    It takes all of two or three seconds to post using code tags. You want help, but you won't take the time to follow the forum guidelines. Good luck with that strategy. You could have added tags and formatting in less time than it took to write that sarcastic reply.

  5. #5
    Join Date
    May 2009
    Posts
    88

    Re: simple loop problem or pixel one

    here you go sir......
    my first step is

    checking for if the user has click on a RGB(0,0,128) pixel
    Code:
    void CPflowView::OnLButtonDown(UINT nFlags, CPoint point) 
    {
    	// TODO: Add your message handler code here and/or call default
    	long tempx=point.x ;
    	long tempy=point.y ;
    	CPflowDoc* pDoc = GetDocument();
    	pDC=GetDC();
    	OnPrepareDC(pDC);
    	pDC->DPtoLP(&point);
    	x2=point.x;
    	y2=point.y ;
    	HDC hDC= pDC->GetSafeHdc();
    	
    	if(bCheckBusOpt==FALSE)
    	{
    		if(GetPixel(hDC,point.x,point.y)==RGB(0,0,128))
    		{
    			busindex=pDoc->InBus (x2 ,y2 );
    			/*char temp[10];
    			ltoa(busindex,temp,10);
    			MessageBox(temp);*/
    			if(busindex>=0)
    			{SetCapture();m_dragging=TRUE;}
    		}
    	}
    	
    	if(bCheckBusOpt==TRUE)
    		DrawBus();
    		
    	CScrollView::OnLButtonDown(nFlags, point);
    }
    the InBus function is as:
    Code:
    int CPflowDoc::InBus(long x,long y)
    	{
    	int index=GetNumBus();
    	CBus1* bus;
            while(index--)
    	{	
    		CBus1* bus;
    		bus=GetBus(index);
    		if( x>= bus->m_x1 && x<=abs(bus->m_x2 -bus->m_x1))
    		{
    			if( y>= bus->m_y1 && y<=abs(bus->m_y2 -bus->m_y1))
    			{
    			return index;
    			}
    		}
    	}
    return -1;
    }
    and
    here the problem is it never goes into the if statement......
    can u please help me now??

  6. #6
    Join Date
    May 2009
    Posts
    88

    Post Re: simple loop problem or pixel one

    the Inbus function above has some errors the new Inbus function that i made is:
    Code:
    int CPflowDoc::InBus(long x,long y)
    	{
    	int index=GetNumBus();
    	CBus1* bus;
    	CPoint p;
    	p.x =x;
    	p.y =y;
    	while(index--)
    	{
    	bus=GetBus(index);
    	CRect rect;
    	rect= new CRect(bus->m_y1 ,bus->m_x1,abs(bus->m_x2 -bus->m_x1) ,abs(bus->m_y2 -bus->m_y1) );
    	if(rect.PtInRect (p))
    		return index;
    	return -1;
    	}
    still the index is not returned properly can any one please tell me why??

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

    Re: simple loop problem or pixel one

    It is impossible to help you since we have no idea what CBus1 is, how GetBus and GetNumBus look like and so on.
    Try to debug you code step-by-step (set a break point into the CPflowDoc::InBus method) to see what happens, what values are returned by GetNumBus and GetBus, what coordinates are used to create CRect object and so on.

    Besides, your code is wrong since it provides memory leaks: CRect objects are newed but never deleted!
    BTW, why are creating them in the heap?
    Victor Nijegorodov

  8. #8
    Join Date
    May 2009
    Posts
    88

    Re: simple loop problem or pixel one

    well CBus1 is a generic class defined by me......
    and GetNumBus is a function that determines the the total number of members in an array
    Code:
    int CPflowDoc::GetNumBus()
    {
    	return m_BusArray.GetSize();
    }
    and GetBus is a function that returns a pointer to that member of array whose index is passed member

    Code:
    CBus1* CPflowDoc::GetBus(int index)
    {
    	if(index<0||index>m_BusArray.GetUpperBound())
    		return 0;
    	return m_BusArray.GetAt(index);
    }
    also my array declaration is as
    Code:
    	CTypedPtrArray<CObArray, CBus1*>m_BusArray;
    here the class CBus1 is derived from CObject class.

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

    Re: simple loop problem or pixel one

    Quote Originally Posted by pinnachio View Post
    the Inbus function above has some errors the new Inbus function that i made is:
    Code:
    int CPflowDoc::InBus(long x,long y)
    	{
    	int index=GetNumBus();
    	CBus1* bus;
    	CPoint p;
    	p.x =x;
    	p.y =y;
    	while(index--)
    	{
    	bus=GetBus(index);
    	CRect rect;
    	rect= new CRect(bus->m_y1 ,bus->m_x1,abs(bus->m_x2 -bus->m_x1) ,abs(bus->m_y2 -bus->m_y1) );
    	if(rect.PtInRect (p))
    		return index;
    	return -1;
    	}
    still the index is not returned properly can any one please tell me why??
    The best thing you can do at this point is watch it run inside the debugger to see what it's doing and why.

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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center