ok i know how to do the left mouse button down evet(WM_LBUTTONDOWN). but im having some troubles with it. when use it with vectors it seems to add 101 elemnts everytime the left mouse button is down. i think that every time the mouse button is down, it sends 101 messages to WM_LBUTTONDOWN that causes 101 elements to be added. here is the code for the event
case WM_LBUTTONDOWN:
iRegularShots=0;
pt.x = GET_X_LPARAM(lParam);
pt.y = GET_Y_LPARAM(lParam);
pRegularShots.push_back(pt);
InvalidateRect(hWnd, rect, false);
break;
any ideas ?
im not missing a break;
i used teh size() function to tell me how many elemnts were assigned.
i set two break points one one pRegularShots.push_back(pt); and the other one on different function that will use what is inside the vector to display the image. and i got 101 calls over there but only one call on the pRegularShots.push_back(pt);.
this is the function code
VOID fRegularShot(HDC hdc, HWND hWnd)
{
Graphics graphics(hdc);
Image shot(L"RegularShots.png");
long index=0;
long s=pRegularShots.size();
while(index < (long)pRegularShots.size())
{
graphics.DrawImage(&shot, pRegularShots[index].x, pRegularShots[index].y);
++index;
}
}
windows prudocer
switch (message)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDM_ABOUT:
DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
OnPaint(hdc, hWnd, 1);
if(iRegularShots==0)
{
fRegularShot(hdc, hWnd);
}
EndPaint(hWnd, &ps);
break;
case WM_LBUTTONDOWN:
iRegularShots=0;
pt.x = GET_X_LPARAM(lParam);
pt.y = GET_Y_LPARAM(lParam);
pRegularShots.push_back(pt);
InvalidateRect(hWnd, rect, false);
return 0;
break;
case WM_LBUTTONUP:
iRegularShots=1;
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}