home *** CD-ROM | disk | FTP | other *** search
/ Borland Programmer's Resource / Borland_Programmers_Resource_CD_1995.iso / utils / 6plus / abook.txt < prev    next >
Text File  |  1995-05-18  |  5KB  |  106 lines

  1.  
  2. I assume you've done some basic programming.
  3.  
  4. A computer is based on the cpu.
  5. It reads instructions and moves or manipulated data.
  6. Data can be from or to the inside of the cpu in registers,
  7. outside the cpu on the memory bus,
  8. or in a peripheral device. (Disk, screen, printer, etc.)
  9.  
  10. A special type of memory structure is the stack.
  11. An area in memory that the cpu keeps a special pointer to.
  12. It is a simple linear pointer that is moved as things are put on,
  13. or pulled off, the stack.  This has become particularly 
  14. important today as it allows a program and operating
  15. system to exchange information without the program
  16. having a absolute pointer, i.e. know either where itself
  17. or the memory area is.  This is important because virtual 
  18. operating systems can move both the program or data areas
  19. around in memory, or even in and out of physical memory, 
  20. at any time.
  21.  
  22. All high level programming tools use this technique, C, Pascal,
  23. Fortral, Cobol, etc.  However, they never agreed on how it was
  24. to be done, so there are now two basic conventions, C and Pascal.
  25. C pushes the parameters onto the stack in reverse order, Pascal
  26. pushes parameters onto the stack in forward order. i.e.
  27. DoSomthing( x, y ) in C would push y onto the stack and then x.
  28. Pascal would push x onto the stack first, and y onto the stack second.
  29. This naturally must be done in the order that the operating system
  30. expects so that as it pulls the parameters off the stack it knows
  31. which one is which.
  32.  
  33. This is the first major brake between Windows and C programming.
  34. Windows is basically C, but uses Pascal parameter conventions.
  35. That is why you will always see a TYPE set before every Window
  36. function that you create.  You will not see WinMain, but instead
  37. PASCAL WinMain, or the newer APIENTRY WinMain.  Each 
  38. tells the C compiler that these calls should push their parameters
  39. onto the stack in the Pascal manner rather than the C manner,
  40. and expect to pull its parameters off the stack in the Pascal manner.
  41. Windows pulls them off the stack in the Pascal order, and then
  42. cleans up the stack. (resets the stack pointer)  This again is 
  43. different than C, where your program is expected to clean up the
  44. stack after the function call has returned.  (you no longer have 
  45. to worry about stack cleaning either way, the compiler
  46. adds code to do that anyway)
  47.     
  48. Mechanics.
  49. Compiled languages work thusly ...  Your human language source
  50. code is compiled into machine language chunks, and then linked
  51. to the other chunks of your code, if more than one, and to things
  52. that are needed and supplied with the programming tools.
  53. If you want to do i/o you have to link in the i/o library.  These 
  54. are pieces of code, in machine language form, that is often needed,
  55. that somebody else has built for you.  String manipulation things,
  56. i/o things, etc.  In Windows these include things like the code
  57. that makes the file open dialog box.
  58.  
  59. The two pieces you need to build a Windows program is a source
  60. code file, and a makefile.  Unlike Dos, or NT console apps, Windows
  61. programs can't be simply compiled.  A more normal set of files are ...
  62.  
  63. myapp.c        Your basic program source code
  64. myapp.h        Your header file
  65. myapp.rc        Your resource file
  66. myapp.def    Your definition file
  67. myapp.ico    Your icon
  68. makefile or myapp.mak   For SDK or VC
  69.  
  70. The header file is where you set constant values, i.e.
  71. #define DARK_RED    RGB(128, 0, 0)
  72. #define FALSE    0
  73. etc.
  74. and prototype your functions, i.e.
  75. long FAR PASCAL MainWndProc(HWND, UINT, WPARAM, LPARAM);
  76.  
  77. The resourse file is where you define which icon the program uses,
  78. define any dialog boxes that you want to make, define you menu
  79. structure, and set any key accelerators (translations) that you want to set.
  80. Your version information that would get embedded into the file also goes here.
  81.  
  82. The definition file isn't needed usually in Window anymore, but it is a good 
  83. idea to make one so that you can easily change your program type or
  84. reset the default stack size easily if you have a need or wish to.
  85.  
  86. The makefile tells NMAKE how to build your program, from what pieces,
  87. in what order, what things to include in the link process, and sets all the 
  88. variables for the compiler and linker.
  89.  
  90. Again, the simplest way to get started, learning or programming is to start
  91. with a sample that has some of the funtionality you need, and build from
  92. there.  I don't care what Don says. <g>
  93.  
  94. I have included one simple sample program for your viewing enjoyment.
  95. If you compare it to samples in the SDK you will notice I format my
  96. text a lot different than most C programmers.  Don't let that throw you.
  97.  
  98. Study it to figure out the program flow, and how it all works, and then
  99. try to extend it.  Add an item to the menu.  This requires adding a 
  100. constant for it in the header file, adding a line for it in the menu in the
  101. resource file, and then adding code to the program to receive the 
  102. event/message, and tell the program what to do at that point.
  103.  
  104. I think you will be amazed at how clean, clear, and logical the flow
  105. of Windows programming is.
  106.