|
Im not really looking to using vectors.
Ah well I think I'll do it otherwise then :p
Thanks anyhows!
|
|
|
|
|
a map would be much better for this, IMO.
|
|
|
|
|
In the Solitaire game, when you are moving the card around, it moves "over"' the other cards. I'm trying to figure out how this is done using either of the draw-related functions within cards.dll. I can move a card around on the playing area just fine. If that card moves over any of the other cards, it will erase them. If I add invalidating code to the end of the OnMouseMove() function, the card I am moving becomes obscurred by the other cards constantly being redrawn. What can I do to ensure that the card I am moving stays atop the other cards and at the same keep those other cards updated?
Unless there's no other way, I'd like to use the functions provided in cards.dll if I can. I've done very little in regards to GDI so my problem(s) here may be elementary.
Thanks.
- DC
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
I believe the perfect way to go would be to use DirectX .
But you could try to set the CS_SAVEBITS style in the WNDCLASS structure for the cards window.
This way the window being moved will restore the background rather than the window in the background drawing itself.
|
|
|
|
|
Hi David,
When you move a card, it leaves behind two rectangles that need to be
repainted, to fill in the area where the card was.
For each move, I would calculate those two rectangles, use
the InvalidateRect() function (twice) to add those exposed rects
to the window's update region, then call UpdateWindow() to force an
immediate redraw.
In the WM_PAINT handler, you're probably already drawing all the cards
that are visible by iterating through a collection of some kind.
If you aren't already, you'll probably want to keep track of the
Z-order of the cards so cards on top get rendered last. That means
when a card is dragged, it needs to be moved to the top of the z-order
before doing the redraws that occur while moving the card. That should
solve the "becomes obscurred by the other cards constantly being redrawn"
issue, since the card being moved is drawn last.
To keep track of z-order, I would just use a simple collection like a
CTypedPtrArray, since generally only one card at a time is going to
change in z-order, and most likely its going to move to the top. You
can just remove the card object from the array and insert it back in
at the end of the array. The WM_PAINT handler then just needs to
draw cards in the same order they are in the array.
Hopefully that all makes sense.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I suppose that, when moving a card, it automatically comes to the top of the Z order, so, inside WM_PAINT handler it should be drawn last of all. The update region should be the union of the starting and ending position rectangles.
Just a guess: hope it makes sense.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I'm not sure if you solved your problem but I used Catch 22[^] to learn about cards.dll; you may find it useful.
|
|
|
|
|
Yeah, I've been studying it the past few days. Thanks.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
hmm i dunno if this is appropriate but my question is how to do a simple bufferoverrun which hack into a function.
basically i got a c++ code which has 2 function, foo() and bar(). the program accept input and pass the input to foo(). i want to buffer overrun till it reads into bar() function.
can this be done??
|
|
|
|
|
nuttynibbles wrote: can this be done??
Sure. I've never tried it so I do not have any examples. See here.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
DavidCrow wrote: See here.
Do you think it's a good idea to teach people how to hack?
|
|
|
|
|
I'm not really in a position to judge someone, Richard. A lot of what I know today is a direct result of my past. I was not a criminal, but I did want to know how things worked.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
DavidCrow wrote: I'm not really in a position to judge someone
Nor me, but the original question included the following "my question is how to do a simple bufferoverrun which hack into a function.", which leads me to believe this could well be someone trying to write a virus of sorts.
|
|
|
|
|
hey sorry guys but its actually for a simple school assignment. we need to know the ways of buffer overrun to better write a secure system. things like strcpy are vulnerable if not used correctly
modified on Wednesday, November 4, 2009 5:44 PM
|
|
|
|
|
Perhaps your request could have been worded better; the word 'hack' tends to ring alarm bells.
|
|
|
|
|
haha my bad. anw i managed to do it. basically do buffer overrun and when the system crash, find the return address. use ASCII to input the function address that u wanna gain access to.
|
|
|
|
|
Hey I would like to appreciate your intension behind the question. I would strongly suggest this[^]
|
|
|
|
|
Can someone please look at this and tell me what I am doing wrong with my pointer.
#include <stdio>
#include <stdlib.h>
#define SENT 4 //"Quit" menu choice
void DisplayMenu (void);
int GetMenuChoice (void);
void Gen2Rand (int*r1, int*r2);
void DrillOneProb (int c, int r1, int r2);
int main (void)
{
int c;
int r1,
r2;
DisplayMenu();
c = GetMenuChoice();
while (c >= 1 && c < SENT)
{ Gen2Rand (&r1, &r2);
DrillOneProb (c, r1,r2);
DisplayMenu();
c = GetMenuChoice();
printf("Program Complete\n");}
return (0);
}
void DisplayMenu (void)
{
printf("MENU OF OPERATIONS\n");
printf("1. Addition.\n");
printf("2. Subtraction.\n");
printf("3. Multiplication.\n");
printf("4. Quit.\n\n");
}
int GetMenuChoice (void)
{
int c;
do{
printf ("Enter the number of the operation to try (1-4):\n");
scanf ("%d", &c);
if (c<1 || c>SENT)
printf("\aInput value is out of range.\n");
while (c < 1 || c > SENT);
return (c);
}
void Gen2Rand (int*r1p, int*r2p)
int r1;
int r2;
r1 = 2 + rand() % 11;
r2 = 2 + rand() % 11;
*r1p = r1;
*r2p = r2;
return (0);
}
void DrillOneProb (int c, int r1, int r2)
{
int CorAns,
Reply;
switch (c)
{
case 1:
printf("+");
CorAns = r1 + r2;
break;
case 2:
printf("-");
CorAns = r1 - r2;
break;
default:
printf("x");
CorAns = r1 * r2;
break;
}
printf(" %d, ?", Reply);
scanf ("%d", &Reply);
if
(Reply == CorAns)
printf("Yes, that is correct. Good Job!");
else
{ printf("No, the correct answer is: %d", CorAns);
printf("\n\n");
}
|
|
|
|
|
You've not stated what problems if any that you're having?
PS:
In your function prototypes, you don't need to specify any variable names for the parameters. Just the data types are OK. This is Ok:
void DrillOneProb (int, int, int);
|
|
|
|
|
void Gen2Rand (int*r1p, int*r2p)
1. Error is undeclared identifier r2p
2. type error in argument 2 to 'Gen2Rand', found 'int' expected 'pointer to int'
3. possible usage of r1p and r2p before definition
*r1p = r1;<br />
*r2p = r2;
1. Error is r1p and r2p is not a pointer.
I met my instructor yesterday and he said that the prototypes were correct. So should I change the void Gen2Rand (int*r1, int*r2)
|
|
|
|
|
Ibrahim Bello wrote: In your function prototypes, you don't need to specify any variable names for the parameters. Just the data types are OK. This is Ok:
void DrillOneProb (int, int, int);
But not very helpful to someone looking at a function prototype in a header file.
You measure democracy by the freedom it gives its dissidents, not the freedom it gives its assimilated conformists.
|
|
|
|
|
You are missing: 1) a closing brace in GetMenuChoice() , and 2) an opening brace in Gen2Rand() . There are other errors but addressing those two should get you further along.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Thank you, That did fix the prob.
|
|
|
|
|
That's good.
As for the prototype, this is OK:
void Gen2Rand (int*, int*); . No need for specifying variable names in prototype. Just let the compiler know what data type to expect for that function. Cheers!
|
|
|
|
|
IMHO, I would say that it is good practice to specify the parameter names in the function prototype, especially when the parameters are the same type. This is not for the compiler's sake but for your own sanity when you come to call the function. It will help you to get your parameters in the right order without having to analyze your code.
Tony 
|
|
|
|