![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#11 |
|
Battle Programmer
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 763
Rep Power: 3
![]() |
the :: operator is for scope resolution in C++
|
|
|
|
|
|
#12 |
|
Hobbyist Programmer
Join Date: Nov 2005
Posts: 149
Rep Power: 3
![]() |
God, I'm sure I sound like a newbie to C++. Probably because I am.
When I type in the line "using System;" it says "Parse error before `;'" Here's my code... #include <windows.h>
#include <ctime>
#include <cstdlib>
#include <iostream>
using System;
int randInt(int end)
{
return (int)((rand()*1.0/RAND_MAX)*end);
}
const char g_szClassName[] = "myWindowClass";
const int windowWidth=200;
const int windowHeight=200;
const int drawableWidth=windowWidth-13;
const int drawableHeight=windowHeight-39;
class MyDot
{
public:
int x,y;
float realX,realY,energyY,energyX;
void initialize()
{
srand((unsigned)time(NULL));
for (int i=0;i<20;i++)
{
rand();
}
energyX=((rand()*1.0/RAND_MAX)-.5);
energyY=((rand()*1.0/RAND_MAX)-.5);
x=randInt(drawableWidth);y=randInt(drawableHeight);
realX=x;realY=y;
}
void draw(HDC hdc)
{
SetPixel(hdc,x,y,RGB(157,4,170));
SetPixel(hdc,x+1,y,RGB(157,4,170));
SetPixel(hdc,x,y+1,RGB(157,4,170));
SetPixel(hdc,x+1,y+1,RGB(157,4,170));
}
void go()
{
realX+=energyX;realY+=energyY;
x=(int)realX;y=(int)realY;
}
void push(float forceX,float forceY)
{
energyX+=forceX;
energyY+=forceY;
}
};
int a=0;
ArrayList dots=new ArrayList();
RECT myRect;
HBRUSH myBrush;
MyDot dot;
HDC hdcBuffer;
HDC hdc;
HBITMAP hbmBuffer;
HBITMAP hbmOldBuffer;
void paintStuff(HDC hdc)
{
FillRect(hdcBuffer,&myRect,myBrush);
dot.draw(hdcBuffer);
BitBlt(hdc,0,0,windowWidth,windowHeight,hdcBuffer,0,0,SRCCOPY);
}
// Step 4: the Window Procedure
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_CREATE:
{
srand((unsigned)time(NULL));
dot.initialize();
myBrush=CreateSolidBrush(RGB(255,255,255));
SetRect(&myRect, 0, 0, windowWidth, windowHeight);
SetTimer(hwnd,1,17,NULL);
hdc=GetDC(hwnd);
hdcBuffer=CreateCompatibleDC(hdc);
hbmBuffer=CreateCompatibleBitmap(hdc,drawableWidth,drawableHeight);
SelectObject(hdcBuffer,hbmBuffer);
}
break;
case WM_TIMER:
{
a++;
hdc=GetDC(hwnd);
paintStuff(hdc);
ReleaseDC(hwnd, hdc);
dot.push(0,0.1);
//Bouncing:
if (dot.realY>drawableHeight & dot.energyY>0)
{
dot.energyY*=-1;
}
if (dot.realY<0 & dot.energyY<0)
{
dot.energyY*=-1;
}
if (dot.realX>drawableWidth & dot.energyX>0)
{
dot.energyX*=-1;
}
if (dot.realX<0 & dot.energyX<0)
{
dot.energyX*=-1;
}
dot.go();
}
break;
case WM_PAINT:
{
PAINTSTRUCT ps;
hdc=BeginPaint(hwnd,&ps);
paintStuff(hdc);
EndPaint(hwnd,&ps);
}
break;
case WM_LBUTTONDOWN:
{
char szFileName[MAX_PATH];
HINSTANCE hInstance = GetModuleHandle(NULL);
GetModuleFileName(hInstance, szFileName, MAX_PATH);
MessageBox(hwnd, szFileName, "This program is:", MB_OK | MB_ICONINFORMATION);
}
break;
case WM_MBUTTONDOWN:
{
HDC hdc=GetDC(hwnd);
TextOut(hdc,a,10,"Hello World",11);
ReleaseDC(hwnd, hdc);
}
break;
case WM_RBUTTONDOWN:
{
}
break;
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
{
KillTimer(hwnd,1);
PostQuitMessage(0);
}
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX wc;
HWND hwnd;
MSG Msg;
//Step 1: Registering the Window Class
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName = NULL;
wc.lpszClassName = g_szClassName;
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
if(!RegisterClassEx(&wc))
{
MessageBox(NULL, "Window Registration Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
// Step 2: Creating the Window
hwnd = CreateWindowEx(
WS_EX_CLIENTEDGE,
g_szClassName,
"The title of my window",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, windowWidth, windowHeight,
NULL, NULL, hInstance, NULL);
if(hwnd == NULL)
{
MessageBox(NULL, "Window Creation Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
// Step 3: The Message Loop
while(GetMessage(&Msg, NULL, 0, 0) > 0)
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
} |
|
|
|
|
|
#13 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5
![]() |
Like I have already said: If you are using VC.NET, then you can use the class ArrayList. But you are not, so you cannot use ArrayList, unless you write it yourself.
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for." -- Socrates |
|
|
|
|
|
#14 |
|
Hobbyist Programmer
Join Date: Nov 2005
Posts: 149
Rep Power: 3
![]() |
Okay, I think I'm on the right track now; I'm using vectors. Sorry I made you guys repeat yourselves...
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|