|In playing around with some basic GDI stuff, I had the need to draw an object in the middle of the main window and then when a button is clicked, draw that object progressively closer to some corner (in my code below, the object moves to the lower right corner, but ultimately I'd like it to move to any corner). So my question is: how to calculate those new X/Y coordinates with each button click?
The initial X/Y coordinates are calculated in response to
nScreenWidth = LOWORD(lParam);
nScreenHeight = HIWORD(lParam);
nX = (nScreenWidth - nObjectWidth) / 2;
nY = (nScreenHeight - nObjectHeight) / 2;
break;When the button is clicked, new X/Y coordinates are "calculated" like:
if (LOWORD(wParam) == ID_BUTTON)
nX += 20;
nY += 10;
InvalidateRect(hWnd, NULL, TRUE);
break;The object is drawn in response to
HDC hdc = BeginPaint(hWnd, &ps);
break;You can count on one hand how many GDI projects I've done in the past (and have fingers left over) so I'm walking in somewhat uncharted territory for me. As a visual aide, if you envision a straight line drawn from the middle of the screen to one of its corners, each pixel of that line is on an X/Y coordinate. What would that calculation look like?
"One man's wage rise is another man's price increase." - Harold Wilson
"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
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
modified 11-Jan-21 15:00pm.