-
May 27th, 2009, 03:09 PM
#1
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
-
May 27th, 2009, 03:29 PM
#2
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 03:32 PM.
-
May 27th, 2009, 03:43 PM
#3
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
-
May 27th, 2009, 03:54 PM
#4
Re: simple loop problem or pixel one
Originally Posted by pinnachio
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.
-
May 28th, 2009, 04:40 AM
#5
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??
-
May 28th, 2009, 04:47 AM
#6
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??
-
May 28th, 2009, 04:58 AM
#7
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
-
May 28th, 2009, 09:55 AM
#8
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.
-
May 28th, 2009, 10:05 AM
#9
Re: simple loop problem or pixel one
Originally Posted by pinnachio
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|