Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1024093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:43:40+00:00 2026-05-16T11:43:40+00:00

i have to event that should insert values in two vectors but when event

  • 0

i have to event that should insert values in two vectors but when event get called for the first time it inserts the values successfully but when it get called again it will insert the values in the first vector but not in the second vector than when another event get called the second vector’s values will be deleted.
here is the full code

#define MAX_LOADSTRING 100

RECT *rect;
const UINT_PTR EVERYTHING_ID=0x1;
const UINT_PTR LBUTTONDOWN_ID=0x3;
const UINT_PTR TDENEMIE1_ID=0x4;
const UINT_PTR TAENEMIE1_ID=0x5;
int conno=2;
int side=0;
int cEnemie1=0;
int dEnemie1=1;
int aEnemie1=0;
int sEnemie1=1;
bool e1=true;
time_t now;
time_t tEnemie1;

vector <POINT> vRegularShots;
vector <POINT> vS1Enemie1;
vector <POINT> vS2Enemie1;
VOID Paint(HDC hdc, HWND hWnd)
{
    hdc=GetDC(hWnd);
    HDC memDC=CreateCompatibleDC(hdc);
    HBITMAP hMemMap=CreateCompatibleBitmap(hdc, 225, 350);
    HBITMAP hOldMap=(HBITMAP)SelectObject(memDC, hMemMap);
    Graphics draw(memDC);

    // Drawing
    Image bg(L"bg.jpg");
    draw.DrawImage(&bg, 0, 0);

    // Regular shots
    Image shot(L"RegularShots.png");
    long s=vRegularShots.size();

    // Draw shots
    for(long index=0; index < (long)vRegularShots.size(); ++index) 
    { 
        draw.DrawImage(&shot, vRegularShots[index].x, vRegularShots[index].y);
    }

    // Update the shots
    for(long index=0; index < (long)vRegularShots.size(); ++index) 
    { 
        vRegularShots[index].y--;
    }

    // Create Enemies
    if(dEnemie1==0)
    {
        if(cEnemie1<2)
        {
            if(aEnemie1==0)
            {
                SetTimer(hWnd, TAENEMIE1_ID, 550, NULL);
            }
            aEnemie1=1;
            cEnemie1++;
        }
        else
        {
            KillTimer(hWnd, TDENEMIE1_ID);
        }
        dEnemie1=1;
    }

    // Draw enemies
    for(long index=0; index < (long)vS1Enemie1.size(); ++index) 
    {
        Image iEnemie1(L"Enemie1.png");
        draw.DrawImage(&iEnemie1, vS1Enemie1[index].x, vS1Enemie1[index].y);
    }
    for(long index=0; index < (long)vS2Enemie1.size(); ++index) 
    {
        Image iEnemie1(L"Enemie1.png");
        draw.DrawImage(&iEnemie1, vS2Enemie1[index].x, vS2Enemie1[index].y);
    }

    // Update enemies
    for(long index=0; index < (long)vS1Enemie1.size(); index++) 
    {
        vS1Enemie1[index].x++;
        vS1Enemie1[index].y++;
    }
    for(long index=0; index < (long)vS2Enemie1.size(); index++) 
    {
        vS2Enemie1[index].x--;
        vS2Enemie1[index].y++;
    }

    // Delete enemies
    for(long index=0; index < (long)vS1Enemie1.size(); index++) 
    {
        if(vS1Enemie1[index].x>225)
        {
            vS1Enemie1.erase(vS1Enemie1.begin()+index);
        }
    }
    for(long index=0; index < (long)vS2Enemie1.size(); index++) 
    {
        if(vS2Enemie1[index].x>225)
        {
            vS2Enemie1.erase(vS2Enemie1.begin()+index);
        }
    }

    BitBlt(hdc, 0, 0, 225, 350, memDC, 0, 0, SRCCOPY);
    ReleaseDC(hWnd, hdc);
    SelectObject(memDC, hOldMap);
    DeleteObject(hMemMap);
    DeleteDC(memDC);
}

VOID CheckDead()
{
    for(long index=0; index < (long)vRegularShots.size(); ++index) 
    { 
         vRegularShots[index].x, vRegularShots[index].y;
    }
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    int wmId, wmEvent;
    PAINTSTRUCT ps;
    HDC hdc;
    POINT pt;
    POINT pts;

    switch (message)
    {
    case WM_CREATE:
        SetTimer(hWnd, EVERYTHING_ID, 1, NULL);
        break;
    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);
        Paint(hdc, hWnd);
        EndPaint(hWnd, &ps);
        break;
    case WM_LBUTTONDOWN:
        GetCursorPos(&pt);
        ScreenToClient(hWnd, &pt);
        if(conno==1)
        {
            conno++;
        }
        else
        {
            pt.x+=18;
            conno--;
        }
        vRegularShots.push_back(pt);
        SetTimer(hWnd, LBUTTONDOWN_ID, 350, NULL); 
        InvalidateRect(hWnd, rect, false);
        break;
    case WM_LBUTTONUP:
        KillTimer(hWnd, LBUTTONDOWN_ID);
        break;
    case WM_TIMER:
        switch(wParam)
        {
        case EVERYTHING_ID:
            if(e1==true)
            {
                now=time(NULL);
                tEnemie1=now+1;
                e1=false;
            }
            now=time(NULL);
            if(now==tEnemie1)
            {
                SetTimer(hWnd, TDENEMIE1_ID, 550, NULL);
            }
            InvalidateRect(hWnd, rect, false);
            break;
        case LBUTTONDOWN_ID:
            GetCursorPos(&pt);
            ScreenToClient(hWnd, &pt);
            if(conno==1)
            {
                conno++;
            }
            else
            {
                pt.x+=18;
                conno--;
            }
            vRegularShots.push_back(pt);
            break;
        case TDENEMIE1_ID:
            pt.y=5;
            pt.x=-26;
            vS1Enemie1.push_back(pt);
            pt.y=52;
            pt.x=251;
            vS2Enemie1.push_back(pt);
            dEnemie1=0;
            InvalidateRect(hWnd, rect, false);
            break;
        case TAENEMIE1_ID:
            InvalidateRect(hWnd, rect, false);
            break;
        }
        break;
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProc(hWnd, message, wParam, lParam);
    }
    return 0;
}

i set a break point at dEnemie1=0 in TAENEMIE1_ID.
anyidea?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T11:43:41+00:00Added an answer on May 16, 2026 at 11:43 am

    For one thing, these two loops have issues:

    // Delete enemies
    for(long index=0; index < (long)vS1Enemie1.size(); index++) 
    {
        if(vS1Enemie1[index].x>225)
        {
            vS1Enemie1.erase(vS1Enemie1.begin()+index);
        }
    }
    for(long index=0; index < (long)vS2Enemie1.size(); index++) 
    {
        if(vS2Enemie1[index].x>225)
        {
            vS2Enemie1.erase(vS2Enemie1.begin()+index);
        }
    }
    

    One issue with each is that when you erase the POINT at index index, then all POINTs at indices index + 1, index + 2, etc. are shifted to the left by one. So, when you increment index, you skip a POINT. The other issue is that you should be using the unsigned size_type as the type of your indexing variable rather than casting to long, which is signed.

    Here is corrected code:

    // Delete enemies
    vector <POINT>::size_type index;
    for(index=0; index < vS1Enemie1.size(); ) 
    {
        if(vS1Enemie1[index].x>225)
        {
            vS1Enemie1.erase(vS1Enemie1.begin()+index);
        }
        else
            ++index;
    }
    for(index=0; index < vS2Enemie1.size(); ) 
    {
        if(vS2Enemie1[index].x>225)
        {
            vS2Enemie1.erase(vS2Enemie1.begin()+index);
        }
        else
            ++index;
    }
    

    It would be even better if you used iterators:

    // Delete enemies
    vector <POINT>::iterator it;
    for(it=vS1Enemie1.begin(); it != vS1Enemie1.end(); ) 
    {
        if(it->x > 225)
        {
            it = vS1Enemie1.erase(it);
        }
        else
            ++it;
    }
    for(it=vS2Enemie1.begin(); it != vS2Enemie1.end(); ) 
    {
        if(it->x > 225)
        {
            it = vS2Enemie1.erase(it);
        }
        else
            ++it;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.