Archived

This topic is now archived and is closed to further replies.

Chordz

Having a problem with simple GDI. Please help.

Recommended Posts

Hello, I''ve been making a miniature game for awhile now and I don''t want to give up on it because of some half-baked error, but, sadly, I''ve reached the end of my capability and come to you with open arms and hopes. Here is my problem: I made a RECT using the RECT Struct. I initilized it using SetRect. Then i moved it one the screen using OffsetRect(). After i did that i tried to see if a point was in it using PtInRect(). But the rectangles doesn''t exist.. I tried to fill it, but it doesn''t fill anything. I''m in the channel if you''d like to chat and I''ll e-mail the code if needed. Thank you for your time.

Share this post


Link to post
Share on other sites
Ok this is it, but its kinda weird and the variable names are right, so I have no idea, but of course, I wouldn't be asking if I had an idea =).

(Sorry I'm new to the forum, so if this little, textbox thingy doesn't work, pardon my ignorance).


    
// Define Rects

RECT Slot1;
RECT Slot2;
RECT Slot3;
RECT Slot4;
RECT Slot5;
RECT Slot6;
RECT Slot7;
RECT Slot8;
RECT Slot9;

// Other code.. blah.. blah


// Set up position and size

if(!OffsetRect(&Slot1,BoardTL.x,BoardTL.y)) return false;
if(!OffsetRect(&Slot2,BoardTL.x + 56, BoardTL.y)) return false;
if(!OffsetRect(&Slot3,BoardTL.x + 112, BoardTL.y )) return false;
if(!OffsetRect(&Slot4,BoardTL.x, BoardTL.y + 56)) return false;
if(!OffsetRect(&Slot5,BoardTL.x + 56, BoardTL.y + 56)) return false;
if(!OffsetRect(&Slot6,BoardTL.x + 112, BoardTL.y + 56)) return false;
if(!OffsetRect(&Slot7,BoardTL.x, BoardTL.y + 112)) return false;
if(!OffsetRect(&Slot8,BoardTL.x + 56, BoardTL.y + 112)) return false;
if(!OffsetRect(&Slot9,BoardTL.x + 112, BoardTL.y + 112)) return false;
if(!SetRect(&Slot1,56,56,56,56)) return false;
if(!SetRect(&Slot2,56,56,56,56)) return false;
if(!SetRect(&Slot3,56,56,56,56)) return false;
if(!SetRect(&Slot4,56,56,56,56)) return false;
if(!SetRect(&Slot5,56,56,56,56)) return false;
if(!SetRect(&Slot6,56,56,56,56)) return false;
if(!SetRect(&Slot7,56,56,56,56)) return false;
if(!SetRect(&Slot8,56,56,56,56)) return false;
if(!SetRect(&Slot9,56,56,56,56)) return false;

// Other code.. blah.. blah


// Use the dern things

if(PtInRect(&Slot1,ClickLocation)) SlotNumber = 0;
if(PtInRect(&Slot2,ClickLocation)) SlotNumber = 1;
if(PtInRect(&Slot3,ClickLocation)) SlotNumber = 2;
if(PtInRect(&Slot4,ClickLocation)) SlotNumber = 3;
if(PtInRect(&Slot5,ClickLocation)) SlotNumber = 4;
if(PtInRect(&Slot6,ClickLocation)) SlotNumber = 5;
if(PtInRect(&Slot7,ClickLocation)) SlotNumber = 6;
if(PtInRect(&Slot8,ClickLocation)) SlotNumber = 7;
if(PtInRect(&Slot9,ClickLocation)) SlotNumber = 8;
if(BoardList[SlotNumber] == 0)
BoardList[SlotNumber] = token; // Error is right here


// Other code.. blah.. blah




Like I said, if this little thingy didn't work, "oops". Thanks again for your help.

And I don't think it exists because when I try to fill it using FillRect (or some function like that), it doesn't fill anything at all. I even resized my window to 1240,1024 to make sure it wasn't out of bounds. Sadly, it wasn't to be found (the filled RECT).

Thanks again.

[edited by - Chordz on March 20, 2002 9:04:04 AM]

[edited by - Chordz on March 20, 2002 9:05:46 AM]

Share this post


Link to post
Share on other sites
hi there,

not very sure but I think you should make your SetRect calls before OffsetRect calls.. ops, and in fact if you give 56 for all parameters to SetRect, you define a point, not rect.. check out the SetRect function;

BOOL SetRect(
LPRECT lprc, // pointer to structure with rectangle to set
int xLeft, // left side
int yTop, // top side
int xRight, // right side
int yBottom // bottom side
);

and i would suggest to debug your code step by step, see what goes on to your Rects in each step..

hope that helps

cheers

-----------
my quote is under construction

Share this post


Link to post
Share on other sites
I had the SetRect() before OffsetRect() before, and I thought that by moving the RECT you sorta screwed the size, so I switched the order, but it didn''t make a difference. I thought that the numbers that you pass into SetRect() were ints that defined the length of each side of the RECT, not the location of the vertices. I''ll check it out, but I''m ''technically'' sure I know what I''m doing.
(TANSTAFFL HELP! I''M USING YOUR BOOK!!).
Heheh..

Thanks for your reply.

Share this post


Link to post
Share on other sites
quote:
Original post by Chordz
I thought that the numbers that you pass into SetRect() were ints that defined the length of each side of the RECT, not the location of the vertices.


nope, you are wrong, they are not length but x and y for topleft corner and x and y for bottomright corner..

cheers



-----------
my quote is under construction

Share this post


Link to post
Share on other sites