theForger's Win32 API Programming Tutorial

Home

Basics
  1. Getting Started
  2. A Simple Window
  3. Handling Messages
  4. The Message Loop
  5. Using Resources
  6. Menus and Icons
  7. Dialog Boxes
  8. Modeless Dialogs
  9. Standard Controls
  10. Dialog FAQ
Creating a simple application
  1. Creating controls at runtime
  2. Files and the common dialogs
  3. Tool and Status bars
  4. Multiple Document Interface
Graphics Device Interface
  1. Bitmaps and Device Contexts
  2. Transparency
  3. Timers and Animation
  4. Text, Fonts and Colours
Tools and Documentation
  1. References
  2. Free Visual C++
Appendices
  1. Solutions to Common Errors
  2. API vs. MFC
  3. Resource file notes

Free Borland C++ Command Line Tools

Obsolete

These tools are now so old and limited that I would not recommend using them at all.

Check out the Free VC++ 2008 tools available from Microsoft.

If you are perhaps a C++ historian, or alien archaeologist, feel free to keep reading...

Getting Them

Fortunately for anyone that wants to get into windows developement, Borland has offered its command line tools to the general public for FREE. Isn't that nice of them? There is no pretty IDE or resource editor, but beggers can't be choosers, and I'd have to say the compiler itself is of far better quality than either LCC-Win32 (which doesn't even do C++) or the various ports of other tools, gcc, mingw, cygwin, djgpp etc...

Read the readme to get yourself set up.

Borland C++ 5.5

What's extra spiffy is it even comes with a debugger! I don't use this, so I can't offer much help on it, but it's better than nothing. And if you're used to Turbo C++ from the DOS days, then this should be right up your ally.

For some reason Internet Explorer seems to have a problem with downloading this file, so if it clicking the link doesn't work, right click and Copy Shortcut, and then use your favourite FTP client to get it.

Turbo Debugger

Last but not least, a windows help file with full Win32 API reference. It's a few years old but still entirely accurate and much more convenient than MSDN online unless you need access to the most recent additions to the API (which if you're on this page, you don't). I use it regularly.

Win32 API Reference

Using Them

Basic commands

If you want to compile a single file program (simple_window.c for example), then you can use the following command:
bcc32 -tW simple_window.c
The -tW switch specifies a Win32 GUI application, instead of the default console application. You can compile multiple files into a single .exe by adding the other files to the end of this command.

Linking in Resources

This is a very frustrating issue for many users of the command line tools, and no wonder, since it seems borland tried to make it as hard as possible to link resources into your applications, the resource compiler brc32 no longer behaves as it did in earlier versions of the program where it would link the compiled resource into the .exe itself. When you run brc32 with no option to get the usage help, it still lists an option to turn .exe linking OFF, there simply appears to be no way to turn it ON.

I tried various combinations of command and options, but couldn't find any way to add a .res file to an .exe build with the above method. Which really sucks, cause the way I found to do it is a lot more complicated.

There is an easier way however...

BC++ now has an alternative method of including resources in a program by use of a #pragma (a non-standard preprocessor directive that compilers will ignore if they don't recognise it).

#pragma resource "app_name.res"
Placing this code in your main .c or .cpp file will cause the compiler to automatically link in the .res file that is generated from your .rc (.res is like an .obj file for resources).

Using the #pragma will allow you to compile programs nearly as simply as above, but you still need to compile the .rc file first using brc32. If you still want to use command line options as I did in the tutorial makefiles, read on...

The hard way...

These are the commands to use to compile the dlg_one example, including the resource.

bcc32 -c -tW dlg_one.c
ilink32 -aa -c -x -Gn dlg_one.obj c0w32.obj,dlg_one.exe,,import32.lib cw32.lib,,dlg_one.res
Nice eh? The -c option to bcc32 means compile only, don't link into an .exe. The -x -Gn options get rid of some extra files the linker creates that you probably don't need.

The real bugger with this is that since we are manually specifying the linker command, we need to include the default libraries and objs that the compiler would normally do for us. As you can see above, I've specified the appropriate files for a regular windows application.

To make things easier on yourself, it's best to do all this in a makefile. I've prepared a generic one that should work with all of the examples in the tutorial, and you should be able to adapt it to any of your own programs.

APP      = dlg_one
EXEFILE  = $(APP).exe
OBJFILES = $(APP).obj 
RESFILES = $(APP).res
LIBFILES =
DEFFILE  =

.AUTODEPEND
BCC32   = bcc32
ILINK32 = ilink32
BRC32   = brc32

CFLAGS  = -c -tWM- -w -w-par -w-inl -W -a1 -Od
LFLAGS  = -aa -V4.0 -c -x -Gn
RFLAGS  = -X -R 
STDOBJS = c0w32.obj
STDLIBS = import32.lib cw32.lib

$(EXEFILE) : $(OBJFILES) $(RESFILES)
   $(ILINK32) $(LFLAGS) $(OBJFILES) $(STDOBJS), $(EXEFILE), , \
      $(LIBFILES) $(STDLIBS), $(DEFFILE), $(RESFILES)

clean:
   del *.obj *.res *.tds *.map
You only need to modify the first 6 lines with the appropriate information.
 
Copyright © 1998-2022, Brook Miles (tutorial(nospam)winprog.org). All rights reserved.