The Daily Click ::. Forums ::. Non-Klik Coding Help ::. I hate Borland 5.02
 

Post Reply  Post Oekaki 
 

Posted By Message

Cazra

Crazy?

Registered
  24/07/2002
Points
  4472

Game of the Week WinnerVIP Member
20th September, 2004 at 06:22:28 -

Borland 5.02 doesn't like windows programming for some dumb reason(even if the code is exactly correct).

Does anyone know any free C++ compilers that support Windows programming without any fussing?

 
n/a

Lazernaut



Registered
  08/09/2002
Points
  1103

VIP MemberThe Cake is a LieIt's-a me, Mario!Wii OwnerPokemon Ball!
20th September, 2004 at 06:26:55 -

I'm writing a report on C++ in school as we speak/write, and i'm using Dev-c++ ( www.bloodshed.net ). It's free, easy to use and i haven't experienced any problems with code not working...

Image Edited by the Author.

 
n/a

Cazra

Crazy?

Registered
  24/07/2002
Points
  4472

Game of the Week WinnerVIP Member
20th September, 2004 at 06:48:36 -

yay! Dev-C++ is way better! Thanks.

 
n/a

Lazernaut



Registered
  08/09/2002
Points
  1103

VIP MemberThe Cake is a LieIt's-a me, Mario!Wii OwnerPokemon Ball!
20th September, 2004 at 06:52:25 -

no problem

 
n/a

Muz



Registered
  14/02/2002
Points
  6499

VIP MemberI'm on a BoatI am an April FoolHonored Admin Alumnus
20th September, 2004 at 10:00:33 -

LOL. Borland is a piece of outdated crap .

 
Disclaimer: Any sarcasm in my posts will not be mentioned as that would ruin the purpose. It is assumed that the reader is intelligent enough to tell the difference between what is sarcasm and what is not.

Image

Cazra

Crazy?

Registered
  24/07/2002
Points
  4472

Game of the Week WinnerVIP Member
20th September, 2004 at 17:55:19 -

I've come across another problem. General Windows programming works fine in Dev-C++ but for some reason, it won't compile the following code:

//12.2 - Bouncing Ball Program -Mark Lee -Prima Publishing
#include <windows.h>

LRESULT CALLBACK WndProc(HWND hWnd, UINT nMsg, WPARAM wParam,
LPARAM lParam);

int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPreInst,
LPSTR lpszCmdLine, int nCmdShow)
{
HWND hWnd;
MSG msg;
WNDCLASSEX wc;

//fill the WNDCLASSEX structure with the appropriate values
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInst;
wc.hIcon = LoadIcon(NULL, IDI_EXCLAMATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = "BouncingBall";
wc.hIconSm = LoadIcon(NULL, IDI_EXCLAMATION);

//register the new class
RegisterClassEx(&wc);

//create a window
hWnd = CreateWindowEx(
NULL,
"BouncingBall",
"The Bouncing Ball Program",
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInst,1);

//event loop - handle all messages
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}

//standard return value
return (msg.wParam);
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT nMsg, WPARAM wParam,
LPARAM lParam)
{
//static variables used to keep track of the balls position
static int dX = 5, dY = 5; //stores direction
static int x = 0, y = 0, oldX = 0, oldY = 0;//stores position
//device context and brush used for drawing
HDC hDC;
HBRUSH brush;

//find out which message is being sent
switch(nMsg)
{
case WM_CREATE:
//create the timer (0.02 seconds)
SetTimer(hWnd, 1, 20, NULL);
break;

case WM_TIMER: //when the timer goes off (only one)
//get the dc for drawing
hDC = GetDC(hWnd);
//use pure white
brush = (HBRUSH)SelectObject(hDC, GetStockObject(WHITE_BRUSH));

//fill a RECT object with the appropriate values
RECT temp;
temp.left = oldX;
temp.top = oldY;
temp.right = oldX + 30;
temp.bottom = oldY + 30;

//cover the old ellipse
FillRect(hDC, &temp, brush);
//get ready to draw the new ellipse
brush = (HBRUSH)SelectObject(hDC, GetStockObject(GRAY_BRUSH));
//draw it
Ellipse(hDC, x, y, 30 + x, 30 + y);
//update the values
oldX = x;
oldY = y;
//prep the new coordinates for next time
x += dX;
y += dY;
//get the window size and store it in rect
RECT rect;
GetClientRect(hWnd, &rect);
//if the circle is going off the edge then reverse its direction
if(x + 30 > rect.right || x < 0)
{
dX = -dX;
}
if(y + 30 > rect.bottom || y < 0)
{
dY = -dY;
}
//put the old brush back
SelectObject(hDC, brush);
//release the dc
ReleaseDC(hWnd, hDC);
break;

case WM_DESTROY:
//destroy the timer
KillTimer(hWnd, 1);
//end the program
PostQuitMessage(0);
break;

default:
//let Windows handle every other message
return(DefWindowProc(hWnd, nMsg, wParam, lParam));
}

return 0;
}

_
Btw, the code should work because it's from a C++ programming book made in 2001.

 
n/a

Kris

Possibly Insane

Registered
  17/05/2002
Points
  2017
20th September, 2004 at 18:05:48 -

the last parameter of CreateWindowEx is LPVOID (void*) so you can't pass value 1 without typcasting it. Try changing it to 0 or NULL instead.

maybe you made a typo while you were copying from the book?

i'm pretty sure borland works fine with windows. maybe you forgot to link some libraries. what sort of errors did it give you?

also, If you can find a copy, get Visual C++. Probably Microsoft's best piece of work

Image Edited by the Author.

 
"Say you're hanging from a huge cliff at the top of mt. everest and a guy comes along and says he'll save you, and proceeds to throw religious pamphlets at you while simultaniously giving a sermon." - Dustin G

AsparagusTrevor

Mine's a pint of the black stuff

Registered
  20/08/2002
Points
  2364

Game of the Week WinnerHas Donated, Thank You!VIP MemberEvil kliker
20th September, 2004 at 18:21:32 -

After Flight Simulator of course.

 
Image

Cazra

Crazy?

Registered
  24/07/2002
Points
  4472

Game of the Week WinnerVIP Member
20th September, 2004 at 18:37:55 -

oh yeah, I was modifying the file to try to find out what the problem was. Here's the original code:


//12.2 - Bouncing Ball Program -Mark Lee -Prima Publishing
#include <windows.h>

LRESULT CALLBACK WndProc(HWND hWnd, UINT nMsg, WPARAM wParam,
LPARAM lParam);

int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPreInst,
LPSTR lpszCmdLine, int nCmdShow)
{
HWND hWnd;
MSG msg;
WNDCLASSEX wc;

//fill the WNDCLASSEX structure with the appropriate values
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInst;
wc.hIcon = LoadIcon(NULL, IDI_EXCLAMATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = "BouncingBall";
wc.hIconSm = LoadIcon(NULL, IDI_EXCLAMATION);

//register the new class
RegisterClassEx(&wc);

//create a window
hWnd = CreateWindowEx(
NULL,
"BouncingBall",
"The Bouncing Ball Program",
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInst,
NULL
);

//event loop - handle all messages
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}

//standard return value
return (msg.wParam);
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT nMsg, WPARAM wParam,
LPARAM lParam)
{
//static variables used to keep track of the balls position
static int dX = 5, dY = 5; //stores direction
static int x = 0, y = 0, oldX = 0, oldY = 0;//stores position
//device context and brush used for drawing
HDC hDC;
HBRUSH brush;

//find out which message is being sent
switch(nMsg)
{
case WM_CREATE:
//create the timer (0.02 seconds)
SetTimer(hWnd, 1, 20, NULL);
break;

case WM_TIMER: //when the timer goes off (only one)
//get the dc for drawing
hDC = GetDC(hWnd);
//use pure white
brush = (HBRUSH)SelectObject(hDC, GetStockObject(WHITE_BRUSH));

//fill a RECT object with the appropriate values
RECT temp;
temp.left = oldX;
temp.top = oldY;
temp.right = oldX + 30;
temp.bottom = oldY + 30;

//cover the old ellipse
FillRect(hDC, &temp, brush);
//get ready to draw the new ellipse
brush = (HBRUSH)SelectObject(hDC, GetStockObject(GRAY_BRUSH));
//draw it
Ellipse(hDC, x, y, 30 + x, 30 + y);
//update the values
oldX = x;
oldY = y;
//prep the new coordinates for next time
x += dX;
y += dY;
//get the window size and store it in rect
RECT rect;
GetClientRect(hWnd, &rect);
//if the circle is going off the edge then reverse its direction
if(x + 30 > rect.right || x < 0)
{
dX = -dX;
}
if(y + 30 > rect.bottom || y < 0)
{
dY = -dY;
}
//put the old brush back
SelectObject(hDC, brush);
//release the dc
ReleaseDC(hWnd, hDC);
break;

case WM_DESTROY:
//destroy the timer
KillTimer(hWnd, 1);
//end the program
PostQuitMessage(0);
break;

default:
//let Windows handle every other message
return(DefWindowProc(hWnd, nMsg, wParam, lParam));
}

return 0;
}

-

Here's the error message Dev-C++ generates:
http://www.sitesled.com/members/neonair/Cpperror.PNG

The only header file used is windows.h. I tried doing another Windows program in it( a simple messagebox) which uses windows.h, but it worked fine then. So, the links to the libraries should be right.

 
n/a

Kris

Possibly Insane

Registered
  17/05/2002
Points
  2017
20th September, 2004 at 18:44:20 -

I got different errors to that, I think mine's outdated... I'll look once I've got the newest version

edit: never mind, it was just being arsey that I didn't set it to a win32 project. these error messages are unbelievably useless

Ok, simple enough. In dev-cpp, NULL is typcasted to void*, Meaning whenever you use it, the compiler thinks you're trying to pass a pointer to an int parameter (in this case, parameter #1). Try 0 instead. This'd explain why MSVC has no troubles (MSVC doesn't typecast NULL)


hWnd = CreateWindowEx(
0,
"BouncingBall",
"The Bouncing Ball Program",
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInst,
NULL
);


Image Edited by the Author.

 
"Say you're hanging from a huge cliff at the top of mt. everest and a guy comes along and says he'll save you, and proceeds to throw religious pamphlets at you while simultaniously giving a sermon." - Dustin G

Cazra

Crazy?

Registered
  24/07/2002
Points
  4472

Game of the Week WinnerVIP Member
20th September, 2004 at 20:58:12 -

Thanks, that gets rid of the error, but it still won't compile because of a bunch of other "errors"

 
n/a

Lazernaut



Registered
  08/09/2002
Points
  1103

VIP MemberThe Cake is a LieIt's-a me, Mario!Wii OwnerPokemon Ball!
21st September, 2004 at 02:24:57 -

i just tried compiling the last code you (snerlin) wrote, and it compiles without a problem and the ball bounces around... only got 1 little error, something about null or whatever.

 
n/a

Cazra

Crazy?

Registered
  24/07/2002
Points
  4472

Game of the Week WinnerVIP Member
21st September, 2004 at 06:14:21 -

Nevermind, found the problem. I had to make a Windows Application project in the compiler first

thanks for the help anyways though.

Btw, for the code,


HDC hDC;
HBRUSH brush;
brush= (HBRUSH)SelectObject(hDC, GetStockObject(WHITE_BRUSH));

_
, is it possible to make the brush's color be something else besides white, gray, or black?

 
n/a

ChrisB

Crazy?

Registered
  16/08/2002
Points
  5457
21st September, 2004 at 06:44:51 -

Create your own brush using CreateBrush(). I think it just takes a COLORREF (use the RGB(r,g,b) macro to make a colour value for that) but it wouldn't hurt to have a quick look on MSDN if it doesn't work for you.

HBRUSH hBrush = CreateBrush(RGB(128,0,192));

 
n/a

Kris

Possibly Insane

Registered
  17/05/2002
Points
  2017
21st September, 2004 at 13:51:04 -

Are you trying to make games with the windows api? you'd probably be best looking for a directx wrapper like Allegro or SDL

 
"Say you're hanging from a huge cliff at the top of mt. everest and a guy comes along and says he'll save you, and proceeds to throw religious pamphlets at you while simultaniously giving a sermon." - Dustin G
   

Post Reply



 



Advertisement

Worth A Click