need help

I cant make a array with a variable as a spot in it

example:
x [count]


//header files to include
#include<windows.h>
#include<stdlib.h>
#include<time.h>
int count = 4;
int particlesamount = 4;
int x [4];
int y [4];
//function prototypes (forward declarations)
BOOL InitInstance(HINSTANCE, int);
ATOM MyRegisterClass(HINSTANCE);
LRESULT CALLBACK WinProc(HWND, UINT, WPARAM, LPARAM);

//the window event callback function

LRESULT CALLBACK WinProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps; // unknown
HDC hdc; // unknown
char *title = "chem sim"; //creates declares title char

RECT rt;// unknown
COLORREF c;// adds color variable
COLORREF x;
switch (message) // begins windows message switch
{
case WM_PAINT: // if windows message is to redraw
//get the dimensions of the window
// |
GetClientRect(hWnd, &rt);// |
//--------------------------------


hdc = BeginPaint (hWnd, &ps); //start drawing on device context
x = RGB(255, 255, 255);
c = RGB(0, 0, 0);//declares color of pixels

count = particlesamount;

while (count > 0)
{
SetPixel(hdc, 0 + x[count], 0 + y[count], c);
}
EndPaint(hWnd, &ps);//stop drawing
break; //breaks case

case WM_KEYDOWN: // if windows message is a key down

if( wParam == VK_SPACE ) // if space key is pressed
{
InvalidateRect( hWnd, NULL, NULL ); // force the entire window to repaint
}
break;// breaks case

case WM_DESTROY:// if windows message is to close
PostQuitMessage(0);//close
break;// breaks case
}
return DefWindowProc(hWnd, message, wParam, lParam);// unknown
}

//helper function to set up the window properties
ATOM MyRegisterClass(HINSTANCE hInstance)
{
//create the window class structure
WNDCLASSEX wc;
wc.cbSize = sizeof(WNDCLASSEX);

//fill the struct with info
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = (WNDPROC)WinProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = NULL;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = "chem sim";
wc.hIconSm = NULL;

//set up the window with the class info
return RegisterClassEx(&wc);
}

//helper function to create the window and refresh it
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;

//create a new window
hWnd = CreateWindow(
"chem sim", //window class
"chem sim", //title bar
WS_OVERLAPPEDWINDOW, //window style
CW_USEDEFAULT, //x position of window
CW_USEDEFAULT, //y position of window
1280, //width of the window
720, //height of the window
NULL, //parent window
NULL, //menu
hInstance, //application instance
NULL); //window parameters


//was there an error creating the window?
if(!hWnd)
return FALSE;

//display the window
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);

return TRUE;
}

//entry point for a Windows program
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
//declare variables
MSG msg;

//register the class
MyRegisterClass(hInstance);

//initialize application
if(!InitInstance (hInstance, nCmdShow))
return FALSE;

//set random number seed
srand(time(NULL));

//main message loop
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
closed account (Dy7SLyTq)
you mean declare an array with a variable amount? its impossible unless you use new and delete. perosnally i would use a vector which is a 1000 times better than an array
Topic archived. No new replies allowed.