Ok so I’m working with vectors today yaya!
well im also working with getcursorpos() and i get weird results.
here is the code:
VOID fRegularShot(HDC hdc, HWND hWnd)
{
Graphics graphics(hdc);
Image shot(L"RegularShots.png");
long index=0;
while(index<=(long)pRegularShots.size())
{
index+=2;
int x=pRegularShots.at(index);
int y1=index+1;
int y=pRegularShots.at(y1);
graphics.DrawImage(&shot, x, y);
}
}
///////////////////////////////////////////////////
event
case WM_LBUTTONDOWN:
iRegularShots=0;
POINT pt;
GetCursorPos(&pt);
pRegularShots.insert(pRegularShots.begin()+1, pt.y);
pRegularShots.insert(pRegularShots.begin()+1, pt.x);
InvalidateRect(hWnd, rect, false);
break;
Well basically function fregularshots() get called and use the vector elements which contains the positions of the cursor than draws the image on the cursor positions.
but it doesn’t seem to draw it on the cursor positions.
any ideas?
GetCursorPos returns cursor position in screen coordinates. Use ScreenToClient(hWnd, …) to convert it to window client coordinates.
You can work also without GetCursorPos function. When WM_LBUTTONDOWN notification is received, lParam contains window client mouse coordinates: x in low-order word, y in high-order word:
Edit:
Let’s make this code more simple.
vector<POINT> pRegularShots; VOID fRegularShot(HDC hdc, HWND hWnd) { Graphics graphics(hdc); Image shot(L"RegularShots.png"); long index=0; while(index < (long)pRegularShots.size()) { graphics.DrawImage(&shot, pRegularShots[index].x, pRegularShots[index].y); ++index; } } case WM_LBUTTONDOWN: POINT pt; pt.x = GET_X_LPARAM(lParam); pt.y = GET_Y_LPARAM(lParam); pRegularShots.push_back(pt); InvalidateRect(hWnd, rect, false); break;