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

Cazra

Crazy?

Registered
  24/07/2002
Points
  4472

Game of the Week WinnerVIP Member
21st September, 2004 at 20:57:53 -

Ya, I'm using windows api right now, but I plan to move on to DirectX and OpenGL.

 
n/a

Cazra

Crazy?

Registered
  24/07/2002
Points
  4472

Game of the Week WinnerVIP Member
21st September, 2004 at 20:58:19 -

Darn double post...

Image Edited by the Author.

 
n/a

Cazra

Crazy?

Registered
  24/07/2002
Points
  4472

Game of the Week WinnerVIP Member
22nd September, 2004 at 06:59:14 -

I have a new problem. I'm trying to make it so I can move the circle around using the arrow keys, but for some reason my code won't move it. wParam doesn't seem to be returning anything.


#include <windows.h>
using namespace std;

/* Declare Windows procedure */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

/* Make the class name into a global variable */
char szClassName[ ] = "WindowsApp";
bool startFrame=0;
int keyB;

int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)

{
HWND hwnd; /* This is the handle for our window */
MSG messages; /* Here messages to the application are saved */
WNDCLASSEX wincl; /* Data structure for the windowclass */

/* The Window structure */
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */
wincl.style = CS_DBLCLKS; /* Catch double-clicks */
wincl.cbSize = sizeof (WNDCLASSEX);

/* Use default icon and mouse-pointer */
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL; /* No menu */
wincl.cbClsExtra = 0; /* No extra bytes after the window class */
wincl.cbWndExtra = 0; /* structure or the window instance */
/* Use Windows's default color as the background of the window */
wincl.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);

/* Register the window class, and if it fails quit the program */
if (!RegisterClassEx (&wincl))
return 0;

/* The class is registered, let's create the program*/
hwnd = CreateWindowEx (
0, /* Extended possibilites for variation */
szClassName, /* Classname */
"Windows App", /* Title Text */
WS_OVERLAPPEDWINDOW, /* default window */
CW_USEDEFAULT, /* Windows decides the position */
CW_USEDEFAULT, /* where the window ends up on the screen */
640, /* The programs width */
480, /* and height in pixels */
HWND_DESKTOP, /* The window is a child-window to desktop */
NULL, /* No menu */
hThisInstance, /* Program Instance handler */
NULL /* No Window Creation data */
);

/* Make the window visible on the screen */
ShowWindow (hwnd, nFunsterStil);

/* Run the message loop. It will run until GetMessage() returns 0 */
while (GetMessage (&messages, NULL, 0, 0))
{
/* Translate virtual-key messages into character messages */
TranslateMessage(&messages);
/* Send message to WindowProcedure */
DispatchMessage(&messages);
}

/* The program return-value is 0 - The value that PostQuitMessage() gave */
return messages.wParam;
}


/* This function is called by the Windows function DispatchMessage() */

LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static int pX,pY;
    keyB = (int)wParam; 

static char string[4]="moo";
if(!startFrame)
{
pX=320;
pY=200;
startFrame=true;
}
HDC hDC;
HBRUSH brush;
switch (message) /* handle the messages */
{
case WM_CREATE:
SetTimer(hwnd, 1, 200, NULL);
break;

case WM_TIMER:
hDC = GetDC(hwnd);
brush= (HBRUSH)SelectObject(hDC, GetStockObject(WHITE_BRUSH));
RECT temp;
temp.left=0;
temp.right=640;
temp.top=0;
temp.bottom=480;
FillRect(hDC, &temp, brush);
brush = (HBRUSH)SelectObject(hDC, GetStockObject(GRAY_BRUSH));
Ellipse(hDC,pX,pY,pX+32,pY+32);
            if(keyB==VK_LEFT)

pX--;
if(keyB==VK_RIGHT)
pX++;
if(keyB==VK_UP)
pY--;
if(keyB==VK_DOWN)
pY++;


SelectObject(hDC,brush);
ReleaseDC(hwnd,hDC);
break;

case WM_DESTROY:
PostQuitMessage (0); /* send a WM_QUIT to the message queue */
break;
default: /* for messages that we don't deal with */
return DefWindowProc (hwnd, message, wParam, lParam);
}

return 0;
}

.

Image Edited by the Author.

Image Edited by the Author.

 
n/a

Kris

Possibly Insane

Registered
  17/05/2002
Points
  2017
22nd September, 2004 at 11:12:24 -

I think you have to put keypress handling inside its own event (WM_KEYDOWN or something, it's probably on MSDN somewhere)

 
"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

Liquixcat

Administrator
Lazy Coder

Registered
  08/12/2002
Points
  201

VIP MemberLikes TDCKitty
23rd November, 2004 at 11:23:14 -

How do you remember all this stuff?? Without TGF/MMF I'd be lost. C++ seems like it takes the memory of a computer. Maybe I'm missing the easy way to remember this crap. I've tried learning these other languages, I never can do it. Anyways, I'm done rambling now. lol

 
thinking is like pong, it's easy, but you miss sometimes.

Batchman



Registered
  08/08/2003
Points
  231
23rd November, 2004 at 15:01:03 -

just to say : dev-cpp is just a gui that use G{CC|++} toolchain, which can be upgraded to the latest version ...

 
n/a

Hagar

Administrator
Old klik fart

Registered
  20/02/2002
Points
  1692

You've Been Circy'd!Teddy Bear
15th December, 2004 at 15:27:30 -

In borland there is tickboxes when you create a new project and use VPL (or something like that) must be ticked for window apps to work. I dont know much about windows C++, i'm best at c hardware programming and know next to nothing about the above .

 
n/a

Lazernaut



Registered
  08/09/2002
Points
  1103

VIP MemberThe Cake is a LieIt's-a me, Mario!Wii OwnerPokemon Ball!
3rd January, 2005 at 06:31:55 -

Liquix kitty -> If you learn programming from bottom up, it's a learning procedure. You take one thing at a time. Then stuff is usually easily remembered. That's why tutorials are great.

 
n/a

Cazra

Crazy?

Registered
  24/07/2002
Points
  4472

Game of the Week WinnerVIP Member
3rd January, 2005 at 09:11:41 -

Ironically, C++ programming is read by the computer from top down.

 
n/a

Nuklear41

Possibly Insane

Registered
  12/01/2008
Points
  2395

VIP MemberPS3 OwnerWii Owner
13th January, 2005 at 13:43:47 -

tdc doesnt suck. Everyone on it does.

 
Image

The Track Master



Registered
  21/11/2004
Points
  462
14th January, 2005 at 19:18:31 -

He's...right?

 
n/a
   

Post Reply



 



Advertisement

Worth A Click