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

  • SEARCH
  • Home
  • 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 1017343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:41:22+00:00 2026-05-16T10:41:22+00:00

Possible Duplicate: c++ using too much cpu my game uses over 50% of cpu.

  • 0

Possible Duplicate:
c++ using too much cpu

my game uses over 50% of cpu. i found way to reduce the cpu to be 40-50% but i can’t find any other way to reduce it. i tried to use Code analyst profiler but it doesn’t give me any good information in my code where im using my cpu.
here is my code

// Xstrike.cpp : Defines the entry point for the application.
//

#include "stdafx.h"
#include "Xstrike.h"
#include <vector>

#define MAX_LOADSTRING 100

// Global Variables:
HINSTANCE hInst;                                // current instance
TCHAR szTitle[MAX_LOADSTRING];                  // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING];            // the main window class name
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;
const UINT_PTR PROTECTED_ID=0x6;
int conno=2;
int health=0;
int life=3;
int score=0;
int level=1;
int protect=0;
int cursor=0;
HCURSOR hCursor[3];

// Forward declarations of functions included in this code module:
ATOM                MyRegisterClass(HINSTANCE hInstance);
BOOL                InitInstance(HINSTANCE, int);
LRESULT CALLBACK    WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK    About(HWND, UINT, WPARAM, LPARAM);

struct Enemies
{
    int cEnemie1;
    int dEnemie1;
    int aEnemie1;
    int sEnemie1;
    int pEnemie1;
    bool e1;
    time_t now;
    time_t tEnemie1;
    vector <POINT> vS1Enemie1;
    vector <POINT> vS2Enemie1;
};

vector <POINT> vRegularShots;
Enemies Enemie1;
VOID installising()
{
    Enemie1.cEnemie1=0;
    Enemie1.dEnemie1=1;
    Enemie1.aEnemie1=0;
    Enemie1.sEnemie1=1;
    Enemie1.pEnemie1=550;
    Enemie1.e1=true;
    POINT pt;
    pt.x=0;
    pt.y=0;
    vRegularShots.push_back(pt);
}
VOID Paint(HDC hdc, HWND hWnd)
{
    int lifePos=200;
    hdc=GetDC(hWnd);
    HDC memDC=CreateCompatibleDC(hdc);
    HBITMAP hMemMap=CreateCompatibleBitmap(hdc, 225, 350);
    HBITMAP hOldMap=(HBITMAP)SelectObject(memDC, hMemMap);
    Graphics draw(memDC);

    // Images
    Image bg(L"bg.jpg");
    Image shot(L"RegularShots.png");
    Image iEnemie1(L"Enemie1.png");
    Image lifes(L"lifes.png");

    // Drawing
    draw.DrawImage(&bg, 0, 0);

    // if regular cursor
    if(cursor==0)
    {
        // Regular shots
        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--;
        }

        // Delete Shots
        for(long index=0; index < (long)vRegularShots.size(); index++) 
        {
            if(vRegularShots[index].y<-16)
            {
                vRegularShots.erase(vRegularShots.begin()+index);
            }
        }

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

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

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

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

            // Stop enemie1 timer
            if(Enemie1.vS1Enemie1.size()==0&&Enemie1.vS2Enemie1.size()==0)
            {
                KillTimer(hWnd, TAENEMIE1_ID);
            }
        }
        for(long index=0; index < (long)Enemie1.vS2Enemie1.size(); index++) 
        {
            if(Enemie1.vS2Enemie1[index].x<-21)
            {
                Enemie1.vS2Enemie1.erase(Enemie1.vS2Enemie1.begin()+index);
            }

            // Stop enemie1 timer
            if(Enemie1.vS1Enemie1.size()==0&&Enemie1.vS2Enemie1.size()==0)
            {
                KillTimer(hWnd, TAENEMIE1_ID);
            }
        }

        // player hits
        if(Enemie1.pEnemie1==550)
        {
            POINT pt;
            GetCursorPos(&pt);
            ScreenToClient(hWnd, &pt);
            for(long index=0; index < (long)Enemie1.vS1Enemie1.size(); index++)
            {
                if(((pt.x+5)>=Enemie1.vS1Enemie1[index].x&&(pt.x+5)<=(Enemie1.vS1Enemie1[index].x+17)&&pt.y>=Enemie1.vS1Enemie1[index].y&&pt.y<=(Enemie1.vS1Enemie1[index].y+17))||((pt.x+15)>=Enemie1.vS1Enemie1[index].x&&pt.y>=Enemie1.vS1Enemie1[index].y&&pt.y<=(Enemie1.vS1Enemie1[index].y+17)&&(pt.x+14)<=(Enemie1.vS1Enemie1[index].x+17))||((pt.x+21)>=Enemie1.vS1Enemie1[index].x&&(pt.y+14)>=Enemie1.vS1Enemie1[index].y&&(pt.y+14)<=(Enemie1.vS1Enemie1[index].y+17)&&(pt.x+21)<=(Enemie1.vS1Enemie1[index].x+17))||((pt.x+23)>=Enemie1.vS1Enemie1[index].x&&(pt.y+22)>=Enemie1.vS1Enemie1[index].y&&(pt.y+22)<=(Enemie1.vS1Enemie1[index].y+17)&&(pt.x+23)<=(Enemie1.vS1Enemie1[index].x+17))||((pt.x+13)>=Enemie1.vS1Enemie1[index].x&&(pt.y+31)>=Enemie1.vS1Enemie1[index].y&&(pt.y+31)<=(Enemie1.vS1Enemie1[index].y+17)&&(pt.x+13)<=(Enemie1.vS1Enemie1[index].x+17))||(pt.x>=Enemie1.vS1Enemie1[index].x&&(pt.y+22)>=Enemie1.vS1Enemie1[index].y&&(pt.y+22)<=(Enemie1.vS1Enemie1[index].y+17)&&pt.x<=(Enemie1.vS1Enemie1[index].x+21))||((pt.x+3)>=Enemie1.vS1Enemie1[index].x&&(pt.y+14)>=Enemie1.vS1Enemie1[index].y&&(pt.y+14)<=(Enemie1.vS1Enemie1[index].y+21)&&(pt.x+3)<=(Enemie1.vS1Enemie1[index].x+21)))
                {
                    health+=30;
                    Enemie1.pEnemie1=0;
                    InvalidateRect(hWnd, rect, false);
                }
            }
            for(long index=0; index < (long)Enemie1.vS2Enemie1.size(); index++)
            {
                if(((pt.x+5)>=Enemie1.vS2Enemie1[index].x&&(pt.x+5)<=(Enemie1.vS2Enemie1[index].x+17)&&pt.y>=Enemie1.vS2Enemie1[index].y&&pt.y<=(Enemie1.vS2Enemie1[index].y+17))||((pt.x+15)>=Enemie1.vS2Enemie1[index].x&&pt.y>=Enemie1.vS2Enemie1[index].y&&pt.y<=(Enemie1.vS2Enemie1[index].y+17)&&(pt.x+14)<=(Enemie1.vS2Enemie1[index].x+17))||((pt.x+21)>=Enemie1.vS2Enemie1[index].x&&(pt.y+14)>=Enemie1.vS2Enemie1[index].y&&(pt.y+14)<=(Enemie1.vS2Enemie1[index].y+17)&&(pt.x+21)<=(Enemie1.vS2Enemie1[index].x+17))||((pt.x+23)>=Enemie1.vS2Enemie1[index].x&&(pt.y+22)>=Enemie1.vS2Enemie1[index].y&&(pt.y+22)<=(Enemie1.vS2Enemie1[index].y+17)&&(pt.x+23)<=(Enemie1.vS2Enemie1[index].x+17))||((pt.x+13)>=Enemie1.vS2Enemie1[index].x&&(pt.y+31)>=Enemie1.vS2Enemie1[index].y&&(pt.y+31)<=(Enemie1.vS2Enemie1[index].y+17)&&(pt.x+13)<=(Enemie1.vS2Enemie1[index].x+17))||(pt.x>=Enemie1.vS2Enemie1[index].x&&(pt.y+22)>=Enemie1.vS2Enemie1[index].y&&(pt.y+22)<=(Enemie1.vS2Enemie1[index].y+17)&&pt.x<=(Enemie1.vS2Enemie1[index].x+21))||((pt.x+3)>=Enemie1.vS2Enemie1[index].x&&(pt.y+14)>=Enemie1.vS2Enemie1[index].y&&(pt.y+14)<=(Enemie1.vS2Enemie1[index].y+21)&&(pt.x+3)<=(Enemie1.vS2Enemie1[index].x+21)))
                {
                    health+=30;
                    Enemie1.pEnemie1=0;
                    InvalidateRect(hWnd, rect, false);
                }
            }
        }

        if(health>225)
        {
            cursor=1;
            SetTimer(hWnd, PROTECTED_ID, 1000, NULL);
            life--;
            health=0;
            InvalidateRect(hWnd, rect, false);
        }

        // Hits
        for(long index=0; index < (long)vRegularShots.size(); index++)
        {
            for(long indexs=0; indexs < (long)Enemie1.vS1Enemie1.size(); indexs++)
            {
                if((vRegularShots[index].x>=Enemie1.vS1Enemie1[indexs].x && vRegularShots[index].y>=Enemie1.vS1Enemie1[indexs].y && vRegularShots[index].y<=(Enemie1.vS1Enemie1[indexs].y+17) && vRegularShots[index].x<=(Enemie1.vS1Enemie1[indexs].x+17))||(Enemie1.vS1Enemie1[indexs].x>=vRegularShots[index].x && Enemie1.vS1Enemie1[indexs].y>=vRegularShots[index].y && Enemie1.vS1Enemie1[indexs].y<=(vRegularShots[index].y+16) && Enemie1.vS1Enemie1[indexs].x<=(vRegularShots[index].x+5)))
                {
                    Enemie1.vS1Enemie1.erase(Enemie1.vS1Enemie1.begin()+indexs);
                    vRegularShots[index].y=-17;
                    score+=100;
                    // Stop enemie1 timer
                    if(Enemie1.vS1Enemie1.size()==0&&Enemie1.vS2Enemie1.size()==0)
                    {
                        KillTimer(hWnd, TAENEMIE1_ID);
                    }
                }
            }
            for(long indexs=0; indexs < (long)Enemie1.vS2Enemie1.size(); indexs++)
            {
                if((vRegularShots[index].x>=Enemie1.vS2Enemie1[indexs].x && vRegularShots[index].y>=Enemie1.vS2Enemie1[indexs].y && vRegularShots[index].y<=(Enemie1.vS2Enemie1[indexs].y+17) && vRegularShots[index].x<=(Enemie1.vS2Enemie1[indexs].x+17))||(Enemie1.vS2Enemie1[indexs].x>=vRegularShots[index].x && Enemie1.vS2Enemie1[indexs].y>=vRegularShots[index].y && Enemie1.vS2Enemie1[indexs].y<=(vRegularShots[index].y+16) && Enemie1.vS2Enemie1[indexs].x<=(vRegularShots[index].x+5)))
                {
                    Enemie1.vS2Enemie1.erase(Enemie1.vS2Enemie1.begin()+indexs);
                    vRegularShots[index].y=-17;
                    score+=100;
                    // Stop enemie1 timer
                    if(Enemie1.vS1Enemie1.size()==0&&Enemie1.vS2Enemie1.size()==0)
                    {
                        KillTimer(hWnd, TAENEMIE1_ID);
                    }
                }
            }
        }
    }

    // If protected
    if(cursor==1)
    {
        if(protect!=4)
        {
            // Regular shots

            // 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--;
            }

            // Delete Shots
            for(long index=0; index < (long)vRegularShots.size(); index++) 
            {
                if(vRegularShots[index].y<-16)
                {
                    vRegularShots.erase(vRegularShots.begin()+index);
                }
            }
            // Delete Shots
        for(long index=0; index < (long)vRegularShots.size(); index++) 
        {
            if(vRegularShots[index].y<-16)
            {
                vRegularShots.erase(vRegularShots.begin()+index);
            }
        }

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

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

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

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

            // Stop enemie1 timer
            if(Enemie1.vS1Enemie1.size()==0&&Enemie1.vS2Enemie1.size()==0)
            {
                KillTimer(hWnd, TAENEMIE1_ID);
            }
        }
        }
        else
        {
            KillTimer(hWnd, PROTECTED_ID);
            cursor=0;
            protect=0;
        }
    }

    // Draw Lifes
    for(long index=0; index != life; index++)
    {
        draw.DrawImage(&lifes, lifePos, 275);
        lifePos-=30;
    }

    SolidBrush textColor(Color(255, 255, 54, 0));
    LinearGradientBrush linGrBrush(
    Point(1000, 20),
    Point(health, 20),
    Color(255, 255, 0, 0),     // opaque black 
    Color(0, 0, 0, 0));  // opaque red
    SolidBrush databrush(Color(0, 225, 0));

    draw.FillRectangle(&databrush, 0, 0, 225, 30);
    draw.FillRectangle(&linGrBrush, 0, 0, 225, 30);

    FontFamily courieNew(L"Courier New");
    Font font(&courieNew, 12, 0, UnitPixel);
    PointF pLevel(5.0f, 6.0f);
    PointF pScore(100.0f, 6.0f);
    WCHAR wLevel[11];
    WCHAR wScore[60];
    _swprintf(wLevel, L"Level : %d", level);
    _swprintf(wScore, L"Score : %d", score);
    draw.DrawString(wLevel, -1, &font, pLevel, &textColor);
    draw.DrawString(wScore, -1, &font, pScore, &textColor);

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


int APIENTRY _tWinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow)
{
    UNREFERENCED_PARAMETER(hPrevInstance);
    UNREFERENCED_PARAMETER(lpCmdLine);
    GdiplusStartupInput gdiplusStartupInput;
    ULONG_PTR           gdiplusToken;

    // TODO: Place code here.
    MSG msg;
    HACCEL hAccelTable;

    // Cursors
    hCursor[0]=LoadCursor(hInstance, MAKEINTRESOURCE(IDC_CURSOR));
    hCursor[1]=LoadCursor(hInstance, MAKEINTRESOURCE(IDC_PROTECTED));

    // Initialize GDI+.
    GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);


    // Initialize global strings
    LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
    LoadString(hInstance, IDC_XSTRIKE, szWindowClass, MAX_LOADSTRING);
    MyRegisterClass(hInstance);

    // Perform application initialization:
    if (!InitInstance (hInstance, nCmdShow))
    {
        return FALSE;
    }

    hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_XSTRIKE));

    // Main message loop:
    while (GetMessage(&msg, NULL, 0, 0))
    {
        if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }

    GdiplusShutdown(gdiplusToken);
    return (int) msg.wParam;
}



//
//  FUNCTION: MyRegisterClass()
//
//  PURPOSE: Registers the window class.
//
//  COMMENTS:
//
//    This function and its usage are only necessary if you want this code
//    to be compatible with Win32 systems prior to the 'RegisterClassEx'
//    function that was added to Windows 95. It is important to call this function
//    so that the application will get 'well formed' small icons associated
//    with it.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
    WNDCLASSEX wcex;

    wcex.cbSize = sizeof(WNDCLASSEX);

    wcex.style          = CS_HREDRAW | CS_VREDRAW;
    wcex.lpfnWndProc    = WndProc;
    wcex.cbClsExtra     = 0;
    wcex.cbWndExtra     = 0;
    wcex.hInstance      = hInstance;
    wcex.hIcon          = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_XSTRIKE));
    wcex.hCursor        = LoadCursor(hInstance, MAKEINTRESOURCE(IDC_CURSOR));
    wcex.hbrBackground  = (HBRUSH)(COLOR_WINDOW+1);
    wcex.lpszMenuName   = MAKEINTRESOURCE(IDC_XSTRIKE);
    wcex.lpszClassName  = szWindowClass;
    wcex.hIconSm        = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));

    return RegisterClassEx(&wcex);
}

//
//   FUNCTION: InitInstance(HINSTANCE, int)
//
//   PURPOSE: Saves instance handle and creates main window
//
//   COMMENTS:
//
//        In this function, we save the instance handle in a global variable and
//        create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
   HWND hWnd;

   hInst = hInstance; // Store instance handle in our global variable

   hWnd = CreateWindow(szWindowClass, szTitle, (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX),
      CW_USEDEFAULT, 0, 225, 350, NULL, NULL, hInstance, NULL);

   if (!hWnd)
   {
      return FALSE;
   }

   ShowWindow(hWnd, nCmdShow);
   UpdateWindow(hWnd);

   return TRUE;
}

//
//  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
//  PURPOSE:  Processes messages for the main window.
//
//  WM_COMMAND  - process the application menu
//  WM_PAINT    - Paint the main window
//  WM_DESTROY  - post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    int wmId, wmEvent;
    PAINTSTRUCT ps;
    HDC hdc;
    POINT pt;

    switch (message)
    {
    case WM_CREATE:
        installising();
        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(Enemie1.e1==true)
            {
                Enemie1.now=time(NULL);
                Enemie1.tEnemie1=Enemie1.now+1;
                Enemie1.e1=false;
            }
            Enemie1.now=time(NULL);
            if(Enemie1.now==Enemie1.tEnemie1)
            {
                SetTimer(hWnd, TDENEMIE1_ID, 550, NULL);
            }
            InvalidateRect(hWnd, rect, false);
            break;
        case LBUTTONDOWN_ID:
            GetCursorPos(&pt);
            ScreenToClient(hWnd, &pt);
            if(conno==1)
            {
                if(cursor==0)
                {
                    conno++;
                }
                else if(cursor==1)
                {
                    pt.x+=2;
                    conno++;
                }
            }
            else
            {
                if(cursor==0)
                {
                    pt.x+=18;
                }
                else if(cursor==1)
                {
                    pt.x+=15;
                }
                conno--;
            }
            vRegularShots.push_back(pt);
            break;
        case TDENEMIE1_ID:
            pt.y=5;
            pt.x=-21;
            Enemie1.vS1Enemie1.push_back(pt);
            pt.y=5;
            pt.x=219;
            Enemie1.vS2Enemie1.push_back(pt);
            Enemie1.dEnemie1=0;
            InvalidateRect(hWnd, rect, false);
            break;
        case TAENEMIE1_ID:
            if(Enemie1.pEnemie1!=550)
            {
                Enemie1.pEnemie1+=550;
            }
            InvalidateRect(hWnd, rect, false);
            break;
        case PROTECTED_ID:
            protect++;
            break;
        }
        break;
    case WM_SETCURSOR:
         SetCursor(hCursor[cursor]);
         return 0;
         break;
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProc(hWnd, message, wParam, lParam);
    }
    return 0;
}

// Message handler for about box.
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
    UNREFERENCED_PARAMETER(lParam);
    switch (message)
    {
    case WM_INITDIALOG:
        return (INT_PTR)TRUE;

    case WM_COMMAND:
        if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
        {
            EndDialog(hDlg, LOWORD(wParam));
            return (INT_PTR)TRUE;
        }
        break;
    }
    return (INT_PTR)FALSE;
}

if you know good profiler that is free, or any idea how to reduce my cpu usage.

  • 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-16T10:41:22+00:00Added an answer on May 16, 2026 at 10:41 am

    I don’t know about profiling Windows code, but your program is so small and simple (in absolute terms – it’s a lot to read on stackoverflow), that you could easily instrument it manually. I Googled up these functions:

    LARGE_INTEGER from;
    LARGE_INTEGER to;
    
    QueryPerformanceCounter (&from);
    // do stuff
    QueryPerformanceCounter (&to);
    
    LARGE_INTEGER elapsed = to - from;
    
    LARGE_INTEGER hertz;
    QueryPerformanceFrecuency (&hertz);
    

    Use your understanding of where the program might spend time to refine your placement of timers, drilling down on the slow code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Validate HWND using Win32 API How can I determent if the window
Possible Duplicate: What is the correct way of using extern for global variables ?
Possible Duplicate: Using Git with Visual Studio What's the most painless way for the
Possible Duplicate: ASP.NET “special” tags I hope this isn't too much of a newbie
Possible Duplicate: Using Git with an existing Xcode project Setting up a git repository
Possible Duplicate: Using ASP.NET Controls without databinding My previous question yielded few results so
Possible Duplicate: using bash: write bit representation of integer to file I need to
Possible Duplicate: Using SendMessage to enter text into an edit control belonging to another
Possible Duplicate: Using a bitwise & inside an if statement I have the following
Possible Duplicate: GCC problem : using a member of a base class that depends

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.