home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Borland Programmer's Resource
/
Borland_Programmers_Resource_CD_1995.iso
/
utils
/
6plus
/
abook.txt
< prev
next >
Wrap
Text File
|
1995-05-18
|
5KB
|
106 lines
I assume you've done some basic programming.
A computer is based on the cpu.
It reads instructions and moves or manipulated data.
Data can be from or to the inside of the cpu in registers,
outside the cpu on the memory bus,
or in a peripheral device. (Disk, screen, printer, etc.)
A special type of memory structure is the stack.
An area in memory that the cpu keeps a special pointer to.
It is a simple linear pointer that is moved as things are put on,
or pulled off, the stack. This has become particularly
important today as it allows a program and operating
system to exchange information without the program
having a absolute pointer, i.e. know either where itself
or the memory area is. This is important because virtual
operating systems can move both the program or data areas
around in memory, or even in and out of physical memory,
at any time.
All high level programming tools use this technique, C, Pascal,
Fortral, Cobol, etc. However, they never agreed on how it was
to be done, so there are now two basic conventions, C and Pascal.
C pushes the parameters onto the stack in reverse order, Pascal
pushes parameters onto the stack in forward order. i.e.
DoSomthing( x, y ) in C would push y onto the stack and then x.
Pascal would push x onto the stack first, and y onto the stack second.
This naturally must be done in the order that the operating system
expects so that as it pulls the parameters off the stack it knows
which one is which.
This is the first major brake between Windows and C programming.
Windows is basically C, but uses Pascal parameter conventions.
That is why you will always see a TYPE set before every Window
function that you create. You will not see WinMain, but instead
PASCAL WinMain, or the newer APIENTRY WinMain. Each
tells the C compiler that these calls should push their parameters
onto the stack in the Pascal manner rather than the C manner,
and expect to pull its parameters off the stack in the Pascal manner.
Windows pulls them off the stack in the Pascal order, and then
cleans up the stack. (resets the stack pointer) This again is
different than C, where your program is expected to clean up the
stack after the function call has returned. (you no longer have
to worry about stack cleaning either way, the compiler
adds code to do that anyway)
Mechanics.
Compiled languages work thusly ... Your human language source
code is compiled into machine language chunks, and then linked
to the other chunks of your code, if more than one, and to things
that are needed and supplied with the programming tools.
If you want to do i/o you have to link in the i/o library. These
are pieces of code, in machine language form, that is often needed,
that somebody else has built for you. String manipulation things,
i/o things, etc. In Windows these include things like the code
that makes the file open dialog box.
The two pieces you need to build a Windows program is a source
code file, and a makefile. Unlike Dos, or NT console apps, Windows
programs can't be simply compiled. A more normal set of files are ...
myapp.c Your basic program source code
myapp.h Your header file
myapp.rc Your resource file
myapp.def Your definition file
myapp.ico Your icon
makefile or myapp.mak For SDK or VC
The header file is where you set constant values, i.e.
#define DARK_RED RGB(128, 0, 0)
#define FALSE 0
etc.
and prototype your functions, i.e.
long FAR PASCAL MainWndProc(HWND, UINT, WPARAM, LPARAM);
The resourse file is where you define which icon the program uses,
define any dialog boxes that you want to make, define you menu
structure, and set any key accelerators (translations) that you want to set.
Your version information that would get embedded into the file also goes here.
The definition file isn't needed usually in Window anymore, but it is a good
idea to make one so that you can easily change your program type or
reset the default stack size easily if you have a need or wish to.
The makefile tells NMAKE how to build your program, from what pieces,
in what order, what things to include in the link process, and sets all the
variables for the compiler and linker.
Again, the simplest way to get started, learning or programming is to start
with a sample that has some of the funtionality you need, and build from
there. I don't care what Don says. <g>
I have included one simple sample program for your viewing enjoyment.
If you compare it to samples in the SDK you will notice I format my
text a lot different than most C programmers. Don't let that throw you.
Study it to figure out the program flow, and how it all works, and then
try to extend it. Add an item to the menu. This requires adding a
constant for it in the header file, adding a line for it in the menu in the
resource file, and then adding code to the program to receive the
event/message, and tell the program what to do at that point.
I think you will be amazed at how clean, clear, and logical the flow
of Windows programming is.