PDA

View Full Version : Here I am going to ramble about something, just tell me if I am on the right track.



incognito
04-03-2002, 03:17 PM
On a Rect rc;
WAIT STILL FORMATING





rc.top
==================
rc.left | | rc.right
| |
| |
| |
| |
==================
rc.bottom


Ok, this is the first part of the question, is this analogy right?

Barjor
04-03-2002, 03:20 PM
I would say it is

incognito
04-03-2002, 03:23 PM
Now for the code........




bool Prog_Init()
{
//create a solid red pen
hpenNew=CreatePen(PS_SOLID,0,RGB(255,0,0));

//retrieve the client rectangle for the window
RECT rcClient;
GetClientRect(hWndMain,&rcClient);

hrgnClip=CreateEllipticRgn(0,0,rcClient.right,rcCl ient.bottom);


//borrow the dc from the main window
HDC hdc=GetDC(hWndMain);

//select the new pen into the dc, and keep the old one
hpenOld=(HPEN)SelectObject(hdc,hpenNew);

//select the clipping region into the dc
SelectObject(hdc,hrgnClip);

//make vertical stripes
int nStripeX=rcClient.right/10;
int nCount;

//loop through and draw the stripes
for(nCount=0;nCount<10;nCount++)
{
//moveto the top of the client area
MoveToEx(hdc,nStripeX*nCount,0,NULL);

//line to the bottom of the client area
LineTo(hdc,nStripeX*nCount,rcClient.bottom);
}

//make the horizontal stripes
int nStripeY=rcClient.bottom/10;

//loop through and draw the stripes
for(nCount=0;nCount<10;nCount++)
{
//move to the left of the client area
MoveToEx(hdc,0,nStripeY*nCount,NULL);

//line to the right of the client area
LineTo(hdc,rcClient.right,nStripeY*nCount);
}

//return the borrowed dc to the system
ReleaseDC(hWndMain,hdc);

return(true);//return success
}

incognito
04-03-2002, 03:24 PM
Not done.......Wait!!!!!!!!:D

jdinger
04-03-2002, 03:24 PM
Besides the slight offset on some parts (which I'm guessing is just a typo), then yes. That's a correct visual representation of a RECT structure's members.

jdinger
04-03-2002, 03:27 PM
Elchulo2002, this looks exactly like code from Panzera's DX7.0 Iso Programming book. Is there something specific you're having trouble with? I'm almost finished with the book, so let me know if you are having trouble with a specific chapter/exercise.

incognito
04-03-2002, 03:29 PM
Originally posted by jdinger
Elchulo2002, this looks exactly like code from Panzera's DX7.0 Iso Programming book. Is there something specific you're having trouble with? I'm almost finished with the book, so let me know if you are having trouble with a specific chapter/exercise.

Yes it is.........I will PM later about it Thanks :D......oh I am formatting my question on another window so cya......:D this is actually kind of funny...lol

incognito
04-03-2002, 03:38 PM
This is what I think.........oh BTW I am the book just pretty much gave me the code for this one, so it's up to me to "find" out how it works..........go figure....


int nStripeX=rcClient.right/10;
//assigns rc.client/10 to nstripeX, this would be assuming that the rect was 800*600, this would be 800/10 or 80 that's being assignged to nStripeX.




//loop through and draw the stripes
for(nCount=0;nCount<10;nCount++)
{
//moveto the top of the client area
MoveToEx(hdc,nStripeX*nCount,0,NULL);

//line to the bottom of the client area
LineTo(hdc,nStripeX*nCount,rcClient.bottom);
}



Ok first of all MoveToEx(hdc,nStripeX*nCount,0,NULL);
ok so I think that here we move our current poing to
nStripeX*nCount or 80, and our Y coordinate would be zero.....
so this would be moving our point to the top left corner of our screen (not exactly the top but you know around there)?

(remember tell me which parts are wrong or right) :D

LineTo(hdc,nStripeX*nCount,rcClient.bottom);
This lines our original point to nStripeX*nCount or 80 again and why would be rcClient.bottom which would be 600 or towards the bottom of the screen therefore making a virtical line..... This loops until it is done 10 times.......Ok Now for your comments please.





Thank you in Advance.

incognito
04-03-2002, 03:40 PM
And oh yeah the Spaces of between the line would increase, because as ncount increases this value is multiplied by the coordinates?

jdinger
04-03-2002, 03:43 PM
Ok first of all MoveToEx(hdc,nStripeX*nCount,0,NULL);
ok so I think that here we move our current poing to
nStripeX*nCount or 80, and our Y coordinate would be zero.....
so this would be moving our point to the top left corner of our screen (not exactly the top but you know around there)?


Correct. Not quite the top-left corner. The top is correct but it is 80 pixels from the left corner. Coord would be (80,0).



LineTo(hdc,nStripeX*nCount,rcClient.bottom);
This lines our original point to nStripeX*nCount or 80 again and why would be rcClient.bottom which would be 600 or towards the bottom of the screen therefore making a virtical line..... This loops until it is done 10 times.......Ok Now for your comments please.

Yes, this makes a vertical line. This exercise doesn't have too much purpose except to give you an idea of how Regions work (and to be honest you'll hardly ever (if ever) use regions).

incognito
04-03-2002, 03:46 PM
Whoho, it feels good when you get something right :)


What about this "And oh yeah the Spaces of between the line would increase, because as ncount increases this value is multiplied by the coordinates?"

Also why is this rcClient.right/10;
divided by the again, like tell me what it is doing in words, so I can get an idea......Thanks

jdinger
04-03-2002, 03:48 PM
Originally posted by elchulo2002
And oh yeah the Spaces of between the line would increase, because as ncount increases this value is multiplied by the coordinates?

Exactly. This is the same principle that most game programmers use to cycle through their animation frames.

For instance, you have a bitmap that is 240 pixels wide (6 frames of an animation, each frame is 40 pixels wide). To cycle through you would incriment an int (for instance, iFrame) and multiply iFrame times 40 (the width of each frame) to get the dimensions for your animation RECT.

Example:


int iFrame;
RECT rcAnim, rcBitmap;

//simple anim loop
iFrame++;
if(iFrame==5) iFrame=0;
SetRect(&rcAnim,iFrame*40,0,(iFrame*40)+40,40);


iFrame*40 gives you the starting left of the RECT, so to get the right just add the width of each "frame" to that number.

jdinger
04-03-2002, 03:55 PM
Originally posted by elchulo2002
Whoho, it feels good when you get something right :)


Glad to be able to help! :D


Originally posted by elchulo2002
Also why is this rcClient.right/10;
divided by the again, like tell me what it is doing in words, so I
can get an idea......Thanks

This is just a way to get a number that we can use as a refrerence for when you cycle through the animation (LineTo) part of the loop. It simply gives us 10 evenly spaced lines drawn. So if you wanted 20 you'd just use:

int nStripeY=rcClient.bottom/20;

rcClient.bottom is the farthest distance from 0 so we set our integer value based off of it. This way if you want to have 20 evenly spaced lines (irregardless of the size of your window) you'll always have it. As long as you trigger it to refigure the value of nStripeY whenever you get a WM_PAINT message. ie: you can resize your window to any size and you'll always have 20 evenly spaced vertical lines.

incognito
04-03-2002, 03:57 PM
Ok Thank you.........Guess I can move on now with my reading......


PS. Check your PM Box.