• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 235
  • Last Modified:

Looking for a nice free stable C/C++ platform to do some simple windows programming

Hi.  I am trying to write a program that displays a small white square (8x8 pixels) on a black screen that is moving (using graphics), also the keyboard modifies the direction/acceleration of the square.  My problems are:
(1) I don't have C/C++ installed on my PC (I don't really know where to get a good free compiler)
(2) I'm not clear on how graphics work in C (will it be platform independent?)
(3) I can use the keyboard, but I need to detect every 10ms what the state of two keys are (up or down) to recalculate the cursor position, so its not detecting simple keypresses, etc.  I need to scan the key state every 10ms.

I know some of this stuff is easy, and I am familiar with C/C++, just haven't done it in a few years.  I'll even set this as a 150-point question just so that you're not wasting your time.

Any help would be welcome.  Thanks.

1 Solution
As for a free C/C++ compiler... MingW32 http://www.mingw.org/

As for the graphics work, you will need to use a third party library such as SDL:
I mean as per the graphics, you have many options, but a graphics library isn't part of the basic
C++ language

You could also use DirectX for graphics, maybe someone else has a better link

Borland has "personal" versions of some of their development tools available for
free download... http://www.borland.com/products/downloads/download_cbuilderx.html

See here also: http://www.thefreecountry.com/compilers/cpp.shtml
I found devcpp quite good

Easily manage email signatures in Office 365

Managing email signatures in Office 365 can be a challenging task if you don't have the right tool. CodeTwo Email Signatures for Office 365 will help you implement a unified email signature look, no matter what email client is used by users. Test it for free!

This may be a bit of a stretch if you prefer to stay on windows:

    linux: http://fedora.redhat.com/
    gcc: http://gcc.gnu.org/
    GDK is part of GNOME and could be used for graphics
    the keypress handling can be handled through the event/message mechanisms
Don't forget the excellent www.openwatcom.org   compiler suite.  16 and 32-bits, real and DPMI and protect-mode.  Win 31, Win95/98/NT/XP.  Fast compiler nad good optimization.   Great manuals.
And good graphics libraries included.  And freee.  And still supported and being improved.

2) as said above, C does not do graphics.  people write libraries (in C, but thats besides the point) that do graphics for you, such as openGL, or directX, or X, or the windows GUI API.  A library can be cross platform (openGL is), but usually the initialization (creating the initial window) is not.  You can look into GLUT if you really want cross-platform abilities.  GLUT is a GUI API that works under both Windows, and Unix (using X), and macintosh (obviously since osX is a unix variant, but I believe there is a GLUT variant for OS9) GLUT compiles into native API code for whatever system you compiled on (or are compiling for, if you do some command line tricks)
3) Reading the keyboard accuratly every 10ms is going to be hard.  under windows, DirectInput should be able to do similar.  But ask yourself how important is this EVERY 10ms?  If your harddrive is thrashing because the computer is bogged down, you might not get to execute your code every 10ms.  One thing you can do is track KEY_DOWN and KEY_UPs, and keep track of the state of the key.  A timer will then let you keep approximatly 10ms timing.  Threads will help you out for keeping the timers going at the right rate, but watch out for multirhtreading issues.

Are you actually using a keyboard?  10ms is 1/100th of a second.  Its hard for a human hand to have that kind of accuracy, and the human eye can't see that fast (I use PWM at these frequencies to give an LED the appearance of dimming).  Or is this a hacked apart connection to some hardware component that has 10ms accuracy.
powertrainAuthor Commented:
Re: open watcom (grg99), I went to the openwatcom site and it looks like you have to pay for it.... is that true?

Re: timing issues (CmdrRickHunter), well actually its for an experiment with some specific requirements.  In actuality I will need to scan the state of the keyboard (2 keys) every 1ms (and store it) and perform the calculation to display the tiny square every 10ms.  If I put it that way, do you think it will be any more possible
Windows is not a real-time OS (nor are most major OSes).  You can't be guarenteed to even run once per millisecond (much less check something every millisecond).  You might get lucky, and have it work, and be able to get the polling rate you want... or you might get unlucky and have your program get switched out of memory on you, and not be able to use it for 50ish ms.

as for displaying at 100Hz (10ms), it can be done, assuming your monitor does support 100Hz refresh rates.  be sure to tell the graphics language to "wait for refresh", and make sure you update at over 100Hz (so that you dont miss anything).

I dont know how strict your requirements are.  If you HAVE to poll every 1ms, on the ms, then you would have the best results writing a simple microcontroller to poll it, and tell the computer the states.  That way if it takes the computer 2ms to get around to executing your thread, it just has to handle two updates at once (not too hard).

If its okay to miss a poll every so often, you could try your luck with a OS specific keyboard reading function (something like DirectInput from the DirectX suite).  It might have the update rate you want, it might not.

Featured Post

Free tool for managing users' photos in Office 365

Easily upload multiple users’ photos to Office 365. Manage them with an intuitive GUI and use handy built-in cropping and resizing options. Link photos with users based on Azure AD attributes. Free tool!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now