home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional Developers Kit 1992 November / Disc01 / Disc01.mdf / os2tk20 / c / samples / samples.ls_ / SAMPLES.LST
Encoding:
File List  |  1992-08-28  |  21.0 KB  |  502 lines

  1.   SAMPLE PROGRAMS
  2.   ---------------
  3.  
  4.   This file describes the sample programs available with the Toolkit.  Most
  5.   sample programs are written in C language and demonstrate the use of the API
  6.   functions of the control program (base operating system) and the Presentation
  7.   Manager interface.  In addition to C language, there are assembler language
  8.   and REXX sample programs.  Each sample program serves as a template that can
  9.   be easily modified for your own purposes.  All C language samples contain the
  10.   overhead routines necessary to create a Presentation Manager application, as
  11.   well as stubs for the basic menu items that all applications should have.
  12.   There are many comments within the source code that clarify technical infor-
  13.   mation by presenting it in an alternate form.
  14.  
  15.  
  16.   STARTING A SAMPLE PROGRAM
  17.   _________________________
  18.  
  19.   FROM THE DESKTOP
  20.  
  21.   When installed, most sample programs appear in the Sample Programs folder.
  22.   To start a sample program, select the folder, then select the appropriate
  23.   sample program.
  24.  
  25.   FROM AN OS/2 COMMAND PROMPT
  26.  
  27.   To start a sample program from an OS/2 command prompt, type the name of the
  28.   executable file and press Enter.  If you have edited source code of a sample
  29.   program and want to recompile, link, and run the files; change to the SAMPLES
  30.   subdirectory and type:
  31.  
  32.       NMAKE /f samples.mak [samplename]
  33.  
  34.   where:
  35.  
  36.   SAMPLENAME
  37.      is the name of the sample program you want to build.  To build all of the
  38.      programs, set samplename to ALL (or omit it).
  39.  
  40.   Your output is the executable file.  For information about the NMAKE utility,
  41.   refer to the online Tools Reference.
  42.  
  43.   FROM WORKFRAME/2
  44.  
  45.   Perhaps you have installed both the Toolkit and the WorkFrame/2 product; if
  46.   so, you can start a sample program (assuming you have set up a project for
  47.   the sample program) from the WorkFrame/2 Project Control window.  Select
  48.   ACTIONS from the menu bar, then select RUN; a project window displays the
  49.   sample program.  You also can edit, compile, link, and run a sample program
  50.   from the WorkFrame/2.
  51.  
  52.  
  53.   ANIMALS -- THE BASIC SOM SAMPLE PROGRAM
  54.   _______________________________________
  55.  
  56.   ANIMALS demonstrates a system object model (SOM) program in an object-
  57.   oriented programming context.  ANIMALS also demonstrates basic concepts of
  58.   subclassing and inheritance, polymorphism, encapsulation, and constructors
  59.   using the analogy of a zoological taxonomy.  This sample program consists of
  60.   6 classes containing 14 methods.
  61.  
  62.   The AnimalFactory and DogFactory metaclass supply constructor methods.
  63.   BigDog and LittleDog inherit the metaclass of their parent, DogFactory, and
  64.   their constructors can be used to create BigDogs, LittleDogs, and generic
  65.   Dogs.
  66.  
  67.  
  68.   CLIPBRD -- THE CLIPBOARD SAMPLE
  69.   _______________________________
  70.  
  71.   CLIPBRD demonstrates how to provide a Presentation Manager interface to the
  72.   clipboard.  Initially, CLIPBRD displays a standard window with a bit map.
  73.   The user can cut and paste data in this window, using the system clipboard as
  74.   an intermediate storage area.
  75.  
  76.  
  77.   CLOCK -- THE TIMER SERVICES SAMPLE
  78.   __________________________________
  79.  
  80.   CLOCK demonstrates how to use and implement window timers and system-resource
  81.   timers.  This sample program displays both an analog and digital clock.  To
  82.   simulate elapsed seconds, the main Presentation Manager thread repeatedly
  83.   sets a one-second window timer that updates the current time.  CLOCK features
  84.   an audible and visual alarm that the user can set.  When the time expires,
  85.   the sample makes use of the DOS timer services and notifies the user by
  86.   sounding an alarm.
  87.  
  88.  
  89.   DIALOG -- THE DIALOG BOX SAMPLE
  90.   _______________________________
  91.  
  92.   DIALOG demonstrates how to associate a dialog box with a standard window.
  93.   The dialog box is defined as a dialog template in a resource file.  This
  94.   sample program also demonstrates how to implement an entry field, push
  95.   buttons, and message boxes.
  96.  
  97.  
  98.   DLLAPI -- THE DYNAMIC LINK LIBRARY SAMPLE
  99.   _________________________________________
  100.  
  101.   DLLAPI demonstrates how to write and use a dynamic link library (DLL).  The
  102.   sample has a DLL file and an executable (EXE) file.  The DLL uses protected
  103.   memory on its shared data, and exception management to validate the pointer
  104.   parameters for a 32-bit API function.  The EXE file demonstrates how to
  105.   handle a divide-by-zero exception, and calls the function with invalid
  106.   pointer parameters, followed by a call with valid pointer parameters.
  107.  
  108.  
  109.   DRAGDROP -- THE DIRECT MANIPULATION SAMPLE
  110.   __________________________________________
  111.  
  112.   DRAGDROP demonstrates how to move files between directories with the dragging
  113.   techniques of direct manipulation.  This sample program creates a list box
  114.   that contains a scrollable list of the current directory.  To change the
  115.   current directory to one lower in the directory tree, the user selects the
  116.   directory name from the list and presses Enter.  To change the current direc-
  117.   tory to one higher in the directory tree, the user selects FILE from the menu
  118.   bar, then OPEN.  The SELECT SUBDIRECTORY window appears.  The user types the
  119.   name of the subdirectory, then selects OK.
  120.  
  121.   The sample program must be started twice so there are two running instances
  122.   of the sample.  Then, using a mouse, the user:
  123.  
  124.   o   Changes the directory file list in the first sample as previously men-
  125.       tioned
  126.   o   Selects a file name from the second sample
  127.   o   Drags the file name (with mouse button 2) to the directory in the first
  128.       sample
  129.   o   Drops the file name in the directory of the first sample.
  130.  
  131.   The file is now moved into the chosen directory.
  132.  
  133.  
  134.   EAS -- THE EXTENDED ATTRIBUTES EDITOR SAMPLE
  135.   ____________________________________________
  136.  
  137.   EAS demonstrates a multithreaded application that retrieves, modifies, or
  138.   sorts files by their extended attribute value.  Included in this sample
  139.   program are Presentation Manager procedures for dialog boxes and a standard
  140.   client window.  EAS lets the user select an extended attribute file name from
  141.   a list, or enter a new name in an entry field.  The user can select the
  142.   extended attribute type from a table.
  143.  
  144.  
  145.   GRAPHIC -- THE GRAPHICS SAMPLE
  146.   ______________________________
  147.  
  148.   GRAPHIC demonstrates how to use default viewing transformation functions of
  149.   the Presentation Manager.  It also demonstrates how to use an asynchronous
  150.   drawing thread.  The sample program lets the user load metafiles using a
  151.   dialog box.  The dialog box has a help push button.  When the help push
  152.   button is activated, it provides instructions on loading a metafile from
  153.   another directory.  The user also can print a metafile or graphic circle.
  154.  
  155.  
  156.   HANOI -- THE MULTITHREADED PRESENTATION MANAGER SAMPLE
  157.   ______________________________________________________
  158.  
  159.   HANOI demonstrates a multithreaded application with the familiar "towers of
  160.   Hanoi" puzzle.  When the sample program is started the user sees three poles
  161.   (A, B, and C).  Initially,  pole A has on it a stack of disks starting with
  162.   the largest disks on the bottom and succeeding smaller disks on the top.  The
  163.   main thread handles the Presentation Manager interface and lets the user
  164.   start or stop the Hanoi routine.  It also lets the user reset the number of
  165.   working disks.  The second thread is created when START is selected from the
  166.   Options menu.  This thread starts the recursive execution of the Hanoi algo-
  167.   rithm, runs in the background, and moves and paints the disks.
  168.  
  169.  
  170.   HELLO -- THE STANDARD WINDOW SAMPLE
  171.   ___________________________________
  172.  
  173.   HELLO demonstrates how to create and display a standard window.  This sample
  174.   program also demonstrates how to use resources defined in a resource script
  175.   file.  Initially, HELLO displays a standard window with the text "Hello."
  176.   The menu bar contains the OPTIONS choice.  If the choice is selected, the
  177.   resulting menu contains three choices, each of which paint a different text
  178.   string in the window.
  179.  
  180.  
  181.   IMAGE -- THE PRESENTATION MANAGER PORTING SAMPLE
  182.   ________________________________________________
  183.  
  184.   IMAGE demonstrates how to migrate from an existing OS/2 16-bit application to
  185.   a 32-bit application.  This program also demonstrates how to display an image
  186.   using the GpiImage function.  The image data comes from a file the user
  187.   selects using the standard File Open dialog procedure.
  188.  
  189.  
  190.   IPF -- THE INFORMATION PRESENTATION FACILITY SAMPLE
  191.   ___________________________________________________
  192.  
  193.   IPF demonstrates how to use the Information Presentation Facility to create
  194.   an online document and an application-controlled window that displays ani-
  195.   mation.  The online document also features customized windows that display
  196.   text and graphics.
  197.  
  198.   Two files are associated with this sample:
  199.  
  200.   o   The IPF online document (.INF) file
  201.   o   The OS/2 dynamic link library (.DLL) file.
  202.  
  203.   The .INF file is the compiled IPF tag document.  The source contains tagging
  204.   that defines different types of windows.  Tags that control the format and
  205.   display of text also are included in this file.
  206.  
  207.   The .DLL file is the compiled C-language source for the communication object
  208.   that is called when the .INF file is read during run time.  The bit map files
  209.   used for the animation are also provided.
  210.  
  211.  
  212.   JIGSAW -- THE RETAINED GRAPHICS SAMPLE
  213.   ______________________________________
  214.  
  215.   JIGSAW demonstrates the use of bit maps in a graphics application.  JIGSAW
  216.   provides a jigsaw puzzle based on the decomposition of an arbitrary bit map
  217.   loaded from a file.  The user can jumble the pieces, then drag them with a
  218.   mouse.  The image can be made smaller or larger, or scrolled horizontally and
  219.   vertically.
  220.  
  221.   JIGSAW also demonstrates how to call the Information Presentation Facility
  222.   help hook, to create a help instance and associate the instance with the
  223.   active application window.
  224.  
  225.  
  226.   NPIPE -- THE NAMED PIPES SAMPLE
  227.   _______________________________
  228.  
  229.   NPIPE demonstrates two-way communication between two unrelated processes
  230.   using named pipe functions.  This sample program implements the game of tic-
  231.   tac-toe with two executable files, CLINPIPE.EXE (the client) and SVRNPIPE.EXE
  232.   (the server).  The server is the computer, and the client is the user.
  233.  
  234.  
  235.   PALETTE -- THE PALETTE MANAGER SAMPLE
  236.   -------------------------------------
  237.   PALETTE demonstrates the creation of a window using a custom palette and
  238.   animation.  The user can display an IBM logo or an OS/2 logo.  When run on
  239.   a system having a fully-populated XGA adapter, the sample shows a palette
  240.   animation technique from a second thread of execution.
  241.  
  242.  
  243.   PDD -- THE PHYSICAL DEVICE DRIVER SAMPLE
  244.   ________________________________________
  245.  
  246.   PDD demonstrates how to construct a physical device driver.  Features of this
  247.   sample include:
  248.  
  249.   o   Initializing a device driver
  250.   o   Defining a device driver header
  251.   o   Requesting device driver helper services.
  252.  
  253.   Also included are such elements as a strategy routine and interrupt handlers.
  254.  
  255.   PDD is an assembler language sample program.  To run PDD, add a DEVICE state-
  256.   ment to the bottom of the CONFIG.SYS file.  Specify the path and complete
  257.   file name to PDD.  For example:
  258.  
  259.     DEVICE=C:\TOOLKT20\ASM\SAMPLES\PDD\PDD.SYS
  260.  
  261.  
  262.   PRINT -- THE PRINTER SAMPLE
  263.   ___________________________
  264.  
  265.   PRINT demonstrates how to display and print text, graphics, metafiles, and
  266.   bit maps.  It also demonstrates how to:
  267.  
  268.   o   Query and display a system printer configuration
  269.   o   Interact with the printer drivers to change job properties
  270.   o   Query and display available printer and screen fonts
  271.   o   Print from an asynchronous thread.
  272.  
  273.  
  274.   QUEUES -- THE INTERPROCESS COMMUNICATION QUEUE SAMPLE
  275.   _____________________________________________________
  276.  
  277.   QUEUES demonstrates interprocess communications (IPC) using 32-bit queuing
  278.   APIs.  It consists of two executable programs, SVRQUEUE.EXE and CLIQUEUE.EXE.
  279.  
  280.   SVRQUEUE creates an IPC queue; a named, shared-memory buffer for queue ele-
  281.   ments; and a shared, named, mutex (mutual exclusive) semaphore.  After ini-
  282.   tializing the queue, SVRQUEUE starts a thread to read from the queue, prints
  283.   the contents of the messages read from the queue, and terminates at the
  284.   user's request.
  285.  
  286.   CLIQUEUE opens the queue and accesses the shared-memory element buffer and
  287.   mutex semaphore, and starts a thread to write to the queue.  CLIQUEUE
  288.   requests a string of data from the user, allocates a shared-memory element
  289.   from the buffer, puts the string in the shared-memory element, then uses an
  290.   event semaphore to direct the thread to write the element to the queue.
  291.   CLIQUEUE terminates at the user's request.
  292.  
  293.  
  294.   REXX -- THE PROCEDURES LANGUAGE/2 REXX SAMPLES
  295.   ______________________________________________
  296.  
  297.   Five REXX sample programs are included with the &tk.:
  298.  
  299.   o   CALLREXX
  300.   o   DEVINFO
  301.   o   PMREXX
  302.   o   RXMACDLL
  303.   o   REXXUTIL
  304.  
  305.  
  306.   CALLREXX -- THE REXX INTERPRETER INVOCATION SAMPLE
  307.  
  308.   CALLREXX demonstrates how a C-language application calls a REXX application.
  309.   To run the REXX application BACKWARD.FNC, CALLREXX.C issues RexxStart.
  310.   RexxStart calls the REXX interpreter and passes in a parameter string.
  311.   BACKWARD.FNC returns a result string to the C-language application.
  312.  
  313.  
  314.   DEVINFO -- THE REXX VARIABLE POOL INTERFACE SAMPLE
  315.  
  316.   This program issues DosDevConfig and returns the data in a collection of com-
  317.   pound variables when all available items are requested, or a single variable
  318.   when only one item is requested.  This is a REXX subcommand handler and Vari-
  319.   able Pool example.  This sample can be run in an OS/2 full-screen session, an
  320.   OS/2 text-window session, or in PMREXX.
  321.  
  322.  
  323.   PMREXX -- THE PRESENTATION MANAGER REXX INTERFACE SAMPLE
  324.  
  325.   This sample provides a Presentation Manager window in which the user can
  326.   display the output from a REXX procedure or from any programs called by the
  327.   REXX procedure.  The window has an entry field into which the user can type.
  328.  
  329.  
  330.   RXMACDLL -- THE EXTERNAL FUNCTIONS IN REXX MACROSPACE SAMPLE
  331.  
  332.   This sample demonstrates the macrospace interface with two C-language
  333.   programs:  MACRO.C and RXNLSINF.C, which are compiled into two separate
  334.   dynamic link libraries.
  335.  
  336.   MACRO.C contains REXX external functions, which perform REXX macrospace oper-
  337.   ations.  RXNLSINF.C contains a REXX external function that provides informa-
  338.   tion related to National Language Support (for example, as a currency symbol
  339.   and separator).  RXMACDLL.CMD uses MACRO.DLL to load NLSMONEY.CMD into the
  340.   macrospace and calls NLSMONEY.CMD several times to format currency amounts.
  341.   NLSMONEY.CMD formats the amounts according to the specifications provided by
  342.   RXNLSINF.DLL.
  343.  
  344.   RXMACDLL can be run in an OS/2 full-screen session, an OS/2 window session,
  345.   or in PMREXX.
  346.  
  347.  
  348.   REXXUTIL -- THE REXX UTILITY FUNCTIONS SAMPLE
  349.  
  350.   REXXUTIL demonstrates a set of external functions packaged in a dynamic link
  351.   library, including:
  352.  
  353.   o   Use of OS/2 system functions in REXX external functions
  354.   o   Techniques for passing large amounts of data to a REXX program using REXX
  355.       compound variables as arrays.
  356.  
  357.   REXXUTIL can be run in an OS/2 full-screen session or an OS/2 window session.
  358.   REXXUTIL cannot be run in PMREXX because some of the functions use video ser-
  359.   vices.
  360.  
  361.  
  362.   SEMAPH -- THE SEMAPHORE AND SHARED MEMORY SAMPLE
  363.   ________________________________________________
  364.  
  365.   SEMAPH demonstrates the use of mutex and event semaphores.  In the sample,
  366.   several threads share access to the same resource.  A mutex semaphore is used
  367.   to guarantee that only one thread has access to the resource at a time.  An
  368.   event semaphore is used to signal the thread to give up the resource.  The
  369.   event semaphore can be posted by the user or run in auto mode.  In auto mode,
  370.   the event semaphore will be posted at fixed time intervals.  A mutex
  371.   semaphore is used to check for a stop event or for a user signal to give up
  372.   the resource.
  373.  
  374.   Each thread can display as a different colored square; similarly, the
  375.   resource can display as a rectangle, the color of which is that of the first
  376.   thread that owns it.
  377.  
  378.  
  379.   SORT -- THE MULTITHREADED PROCESS SAMPLE
  380.   ________________________________________
  381.  
  382.   SORT demonstrates the use of multiple threads by performing multiple sorts at
  383.   the same time.  Each sorting algorithm runs from a separate thread.  The main
  384.   thread is used to handle the main window's messages, while the routine that
  385.   updates the display is run from another thread.
  386.  
  387.  
  388.   STYLE -- THE STYLE-GUIDE SAMPLE
  389.   _______________________________
  390.  
  391.   STYLE demonstrates a Presentation Manager application that conforms with
  392.   Common User Access (CUA)* requirements and implements the following new
  393.   controls:
  394.  
  395.   o   Container
  396.   o   Notebook
  397.   o   Slider
  398.   o   Spin button
  399.   o   Value set.
  400.  
  401.   This sample program also demonstrates secondary windows, such as dialog and
  402.   message boxes.  The code in STYLE is structured so that the addition of a new
  403.   function is handled in an efficient manner.  For example, to add a new
  404.   command to an existing menu, you need only add the command to the resource
  405.   file, then add the appropriate message-processing routines to the STY_USER.C
  406.   file.
  407.  
  408.   *CUA is a trademark of the IBM Corporation.
  409.  
  410.  
  411.   TEMPLATE -- THE APPLICATION TEMPLATE SAMPLE
  412.   ___________________________________________
  413.  
  414.   TEMPLATE demonstrates the structure common to all Presentation Manager appli-
  415.   cations.  This sample program shows how to structure an application that has
  416.   more than one source file.  TEMPLATE also demonstrates how to:
  417.  
  418.   o   Create a standard window
  419.   o   Load resources from a resource file
  420.   o   Create a dialog box and a button control
  421.   o   Display a message box
  422.   o   Open a file
  423.   o   Close a file
  424.   o   Print text
  425.   o   Paint a window
  426.   o   Process a message from a menu
  427.   o   Run a thread in the background
  428.   o   Exit a process.
  429.  
  430.  
  431.   TP -- THE ADVANCED SOM SAMPLE PROGRAM
  432.   _____________________________________
  433.  
  434.   TP (text processing) demonstrates an advanced system object model (SOM)
  435.   program in an object-oriented programming context.  TP demonstrates the use
  436.   of abstract superclasses, and public and private methods.  This sample
  437.   program also demonstrates subclassing, polymorphism, and encapsulation.
  438.  
  439.   TP reads a free-form file of text and markup language and produces a for-
  440.   matted output file.  The markup language is deliberately made up so that it
  441.   is clearly defined as a simulation.  The input file demonstrates the pro-
  442.   duction of paginated, multi-column text with indentation, page numbers, unor-
  443.   dered lists, headers, and footers.
  444.  
  445.  
  446.   VDD -- THE VIRTUAL DEVICE DRIVER SAMPLE
  447.   _______________________________________
  448.  
  449.   VDD demonstrates a basic virtual device driver, including how to:
  450.  
  451.   o   Interface with the virtual device driver helper services
  452.   o   Enable and disable system interrupts
  453.   o   Enable and disable a network card interrupt
  454.   o   Simulate interrupts in a DOS session
  455.   o   Initialize the device driver
  456.   o   Define a virtual device header.
  457.  
  458.   Use VDD with the physical device driver sample (PHYSDEV), to establish inter-
  459.   device driver communications between a 16-bit physical device driver and a
  460.   32-bit virtual device driver.
  461.  
  462.   VDD also demonstrates how to control a network card -- this concept can be
  463.   used to control other peripheral devices.
  464.  
  465.  
  466.   VMM -- THE VIRTUAL-MEMORY MANAGEMENT SAMPLE
  467.   ___________________________________________
  468.  
  469.   VMM demonstrates the use of virtual memory by using new memory-management
  470.   functions to allocate and set the attributes of memory.  Users can read or
  471.   write data into memory and reset the attributes using a dialog box.  The
  472.   memory manager protects or opens the virtual memory to read or write oper-
  473.   ations according to the different attributes of each memory block.  To free
  474.   memory, the user enters the address of the memory.
  475.  
  476.  
  477.   WORMS -- THE MIXED-MODE SAMPLE
  478.   ______________________________
  479.  
  480.   WORMS demonstrates how to call video (Vio), keyboard (Kbd), and mouse (Mou)
  481.   16-bit function from a 32-bit code segment.  This sample program displays
  482.   earth worms aimlessly moving about the screen.  Each worm is a separate
  483.   thread with a unique color combination and movement pattern.  When one worm
  484.   encounters another worm, the color attribute of the first worm is set to red.
  485.   The user can add or delete worms using the keyboard or mouse.
  486.  
  487.  
  488.   WPCAR -- THE WORKPLACE OBJECT SAMPLE
  489.   ____________________________________
  490.  
  491.   WPCAR demonstrates how to create a workplace object using basic object-
  492.   oriented programming techniques and the IBM System Object Model (SOM),
  493.   including:
  494.  
  495.   o   Initializing an object
  496.   o   Adding settings pages to an object
  497.   o   Saving and restoring the state of an object
  498.   o   Modifying object context menus (adding and deleting menu items)
  499.   o   Querying of object class data
  500.   o   Processing context menu items
  501.   o   Implementing settings page dialog processing.
  502.