home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 17 / CD_ASCQ_17_101194.iso / vrac_os2 / pfaq31.zip / PFAQ31.INF (.txt) < prev    next >
OS/2 Help File  |  1994-08-30  |  203KB  |  6,759 lines

  1.  
  2. ΓòÉΓòÉΓòÉ 1. Introduction and Credits ΓòÉΓòÉΓòÉ
  3.  
  4.             OS/2 2.x Frequently Asked Questions, Programmer's Edition
  5.  
  6.                           Version 3.1, August 29, 1994
  7.                            Compiled by Andreas Almroth
  8.  
  9.                        Pre-3.x versions by Jeff M. Garzik
  10.                         Pre-2.x versions by Barry Jaspan
  11.  
  12.                       Copyright (c) 1994 by Andreas Almroth
  13.                               All Rights Reserved.
  14.  
  15. For changes, suggestions, or additions please mail andreas@traci.almroth.pp.se 
  16. or write to: 
  17.  
  18. Andreas Almroth
  19. Fanrik Stals Gata 153
  20. S-754 39 UPPSALA
  21. SWEDEN
  22.  
  23. Mention of a product does not constitute an endorsement.  Customers outside the 
  24. United States should not necessarily rely on 800 telephone numbers, page 
  25. numbers, part numbers, or upgrade policies contained in this List.  Electronic 
  26. mail addresses are in Internet form; use addressing appropriate to your mail 
  27. system. 
  28.  
  29. This FAQ is freely distributable for noncommercial purposes.  (For commercial 
  30. purposes, please contact the author.)  If you redistribute the FAQ, please 
  31. include all the original files. 
  32.  
  33. This FAQ is updated quarterly and is distributed through various computer 
  34. networks and online services, including the Internet and many BBSes. 
  35.  
  36. Both ASCII text and OS/2 Information Presentation Facility (INF) versions of 
  37. the FAQ are provided.  To view the INF version of the List, go to any OS/2 
  38. command line prompt (e.g. double click on "OS/2 Window") and type: 
  39.  
  40. VIEW PROGFAQ.INF
  41.  
  42. The ASCII text version may be viewed using any text editor, word processor, or 
  43. file listing utility.  The text version is intended to answer any questions you 
  44. may have before actually obtaining and using OS/2.  You will find that the INF 
  45. version provides a much more attractive interface, with hypertext links, fast 
  46. indexing, and, increasingly, illustrations. 
  47.  
  48. If you have not received all three files (README.CMD, PROGFAQ.INF, and 
  49. PROGFAQ.TXT), please ask your system operator to make sure he/she is receiving 
  50. the correct and complete package every month. 
  51.  
  52. Many of the answers in this FAQ refer to anonymous ftp site FTP-OS2.CDROM.COM 
  53. (192.153.46.2). The name 'cdrom.com' is used as a shorthand to refer to this 
  54. site.  It has become, by default, the Internet storehouse for OS/2 files.  If 
  55. you cannot get files from this site (for whatever reason), then check OS/2 
  56. Software Sources for a source near you. You may find a more convenient method 
  57. of getting files than from cdrom.com.  (Non-US readers will note Bjorn 
  58. Fahller's FTP site, ftp.luth.se, is the main overseas FTP site.) 
  59.  
  60.  
  61. Related Information:
  62.  
  63. Release Notes
  64. OS/2 Software Sources
  65. Obtaining this FAQ / Contacting the Author
  66.  
  67.  
  68. ΓòÉΓòÉΓòÉ 2. Release Notes ΓòÉΓòÉΓòÉ
  69.  
  70. Text which has been revised or updated since the last release will appear in 
  71. the same color as this paragraph. 
  72.  
  73. Version 3.1: 
  74. Added index search facility (but only to some extent, sorry) 
  75. As usual, questions and answers have been added or changed. 
  76.  
  77. Version 3.0: A new maintainer of the OS/2 Programming FAQ: Andreas Almroth 
  78. Some answers changed or added. 
  79.  
  80. Version 2.3:  This release does not include very many new sections, but the 
  81. information has been reorganized for greater readability and easier maintenence 
  82. (for me).  Major changes include title re-wording for brevity, revision 
  83. coloring, and updated information. 
  84.  
  85.  
  86. Related Information:
  87.  
  88. Introduction and Credits
  89. OS/2 Software Sources
  90. Obtaining this FAQ / Contacting the Author
  91.  
  92.  
  93. ΓòÉΓòÉΓòÉ 3. Questions Covered in this Release ΓòÉΓòÉΓòÉ
  94.  
  95. Languages, Compilers, Debuggers
  96.   What programming languages come with OS/2?
  97.   Programming language availability
  98.   Which of these compilers can be used to generate PM apps?
  99.   Which assemblers can produce OS/2 32-bit code?
  100.   The two GNU C/C++/ObjC packages
  101.   What is REXX?  How do I write and run a REXX program?
  102.   What debuggers are available for OS/2?
  103. Tools, Toolkits, Accessories
  104.   How do I use PATCH, maybe with my own programs?
  105.   What programming editors are available for OS/2?
  106.   What programming tools/toolkits/accessories are available for OS/2?
  107.   What GNU tools are available and where can I find them?
  108.   Is a socket library available?  How can I use it?
  109. Compiling
  110.   Can I distribute the C-Set++ runtime DLL?
  111.   How big should my stacksize be?
  112.   How do I determine what C/C++ compilator is compiling my code?
  113.   How do I perform parallel compilation?
  114.   What is an RC of 87 (invalid param) from the API?
  115.   GCC/2 crashes with a trap when I try to compile a program.  Why?
  116.   How do I recompile EPM (easily)?
  117.   How to I get BC++ for DOS/Windows to run?
  118. Documentation, Help
  119.   Where can I get information on OS/2 APIs and programming?
  120.   Where can I get sample code?
  121.   Are there any OS/2 programming classes or seminars?
  122.   What are good ref. books for programming in OS/2 and PM?
  123.   What are good OS/2 programming magazines?
  124.   What are the OS/2 redbooks, and how do I get them?
  125.   How can I view the GNU C documentation?
  126.   Where can I get documentation on the OBJ/LIB/EXE format used by OS/2 2.x?
  127.   Where can I find information on HPFS?
  128. PM Programming
  129.   Printing
  130.     Are there any SIMPLE examples of printing?
  131.     Is there an easy way to get printer output (another opinion)?
  132.     How do I print a bitmap?
  133.     How do I do my own Print Screen?
  134.   Menus
  135.     How do I add a menu to a dialog box?
  136.     How do I make a dynamically changing menu?
  137.     How do I create a conditional cascade menu?
  138.     How do I remove a separator from a menu?
  139.   Container Controls
  140.     How do I stop a container from flashing every time I add a record?
  141.     How do I get my containers to use Mini-icons?
  142.     How do I sort a container control?
  143.     How do I query all records in a container - tree view?
  144.   I can't get different colors in text control windows
  145.   How can I toggle my titlebar on and off?
  146.   How can I get transparent regions in bitmaps?
  147.   How do I create a status bar at the bottom of my window?
  148.   How to have a frame/client and still have a std window?
  149.   How do I use printf() in a PM program?
  150.   I have a SOM DLL. How do I register it?
  151.   How do I save and restore my window size and position?
  152.   How do you make a window float above all other?
  153.   How to ensure the sizing's correct so the dlg "fits" in the notebook...?
  154.   How do I prevent Shutdown from stopping my app?
  155.   When I pass a structure to WinCreateWindow, sometimes it doesn't work!
  156.   How do I use type filtering in 2.0's open dlg?
  157.   When minimizing, my dialog box is overwriting my icon!
  158.   How do I make a multi-column listbox?
  159.   How do I create my own Master Help Index?
  160.   How do I change the font in an MLE?
  161.   Why can't I import files larger than 64KB into my MLE?
  162.   How do I get PM screen size?
  163.   How do I attach Instance data to window created with WinCreateStdWindow?
  164.   How do I get a list of fonts?
  165.   How do I create a folder in C and put my pgm in it?
  166.   How do I do it in REXX?
  167.   How do I use the Font dialog (WinFontDlg)?
  168.   How do I take control of frame sizing?
  169.   How do I use the 16-bit EPM toolkit?
  170.   How do I get error info after using WinGetLastError()?
  171.   Do you have code to save/restore the clipboard?
  172.   How do I know what item was selected in a Combo box?
  173.   How do I get a bitmap into a dialog in a DLL?
  174.   How does programming PM compare to programming X?
  175.   How do I put bitmaps on buttons?
  176.   Can a PM program tell if there's a previous instance of itself running?
  177.   How to avoid crash when using Drag and Drop?
  178. Miscellaneous Programming
  179.   Explain the SYS_DLL keywords.
  180.   How do I start another session?
  181.   How do I check if a filename is valid?
  182.   Why should I use _beginthread instead of DosCreateThread?
  183.   How do I open a file that is already in use?
  184.   Can we use Vio in v2.0? Where are the docs for it?
  185.   Can I redirect stdin and stdout in a child process?
  186.   How do I use DosMon*() to stuff the kbd buf?
  187.   How do I determine what file system a drive uses?
  188.   How do I get the error message from a DOS API call?
  189.   How do I set an exception handler?
  190.   How can I determine a diskette format and if a disk is in a drive?
  191.   What do all those keywords mean when making a DLL?
  192.   Where can I find serial port sample code?
  193.   How do I disable <Ctrl><Alt><Del>?
  194.   Why doesn't printf() produce output when I expect it to?
  195.   How do I write an OS/2 device driver?
  196.   How do I change the master environment?
  197.   What is the best way to communicate between processes?
  198.   What is the best way to communicate between threads?
  199.   How to I write an IFS?
  200.   How do I interface with OS/2's SCSI support?
  201.   How do I program full-screen graphics?
  202.   How do I program MMPM/2 programs?
  203.   How do I peripheral memory or an I/O port?
  204. Porting
  205.   How do I port my DOS keyboard TSR to OS/2?
  206.   How can I simulate (Unix feature) under OS/2?
  207.   How can I recompile public domain/shareware source code for OS/2?
  208.   How can I port my DOS program to OS/2?
  209.   How can I port my Windows program to OS/2?
  210. Miscellaneous
  211.   Is OS/2 suitable for real time programs?
  212.   What is available for multimedia programming under OS/2?
  213.   What is available for AI/neural net programming under OS/2?
  214.   Special software offers
  215.   Technical Support
  216.   Developer's Assistance Program (DAP)
  217.  
  218.  
  219. ΓòÉΓòÉΓòÉ 4. Languages, Compilers, Debuggers ΓòÉΓòÉΓòÉ
  220.  
  221. This section covers the programming tools currently available for OS/2.  The 
  222. following topics are available: 
  223.  
  224. What programming languages come with OS/2?
  225. Programming language availability
  226. Which of these compilers can be used to generate PM apps?
  227. Which assemblers can produce OS/2 32-bit code?
  228. The two GNU C/C++/ObjC packages
  229. What is REXX?  How do I write and run a REXX program?
  230. What debuggers are available for OS/2?
  231.  
  232.  
  233. ΓòÉΓòÉΓòÉ 4.1. What programming languages come with OS/2? ΓòÉΓòÉΓòÉ
  234.  
  235. The original BASIC and BASICA (for systems with BASIC in ROM, mainly IBM 
  236. systems), DOS's QBASIC, and OS/2's REXX comes with OS/2 2.x. 
  237.  
  238. REXX is basically the official command language of OS/2. 
  239.  
  240.  
  241. Related Information:
  242.  
  243. What is REXX?  How do I write and run a REXX program?
  244.  
  245.  
  246. ΓòÉΓòÉΓòÉ 4.2. Programming language availability ΓòÉΓòÉΓòÉ
  247.  
  248. Virtually all of them: Assembler, C, C++, COBOL, Pascal, Fortran, Smalltalk, 
  249. Modula-2, LISP, Forth, Perl, and more.  The OS/2 Tools Guide on cdrom.com 
  250. (os2/all/info/tinf34.zip) contains information on these and more.  Also check 
  251. the User's Edition for information on IBM's Development Tools Guide.  It's a 
  252. free catalog from IBM. 
  253.  
  254. All prices listed are "list price," as listed in Fall/Winter Programmer's 
  255. Paradise catalog.  All entries marked "Freely Available" can be obtained from 
  256. cdrom.com unless otherwise noted. 
  257.  
  258.  1. Ada 
  259.  
  260.    o GNU Ada 1.67 for OS/2; freely available; under development; cs.nyu.edu in 
  261.      the pub/gnat directory. Needs GCC/2 to compile applications written in 
  262.      Ada. 
  263.    o Alsys AdaWorld OS/2 i2 refid=proglang.Assembler 
  264.  
  265.  2. Assembly Language 
  266.  
  267.    o IBM Macro Assembler, $288 
  268.    o GNU assembler v1.38, included in emx/gcc 0.8h package 
  269.    o GNU assembler v1.38, included in GCC/2 v2.5.4 package 
  270.    o Turbo Assembler v3.21, included in Borland C++ for OS/2 package 
  271.  
  272.  3. BASIC 
  273.  
  274.    o CA-REALIZER, $100 
  275.    o ObjectView PM Basic, $899 
  276.  
  277.  4. C/C++ 
  278.  
  279.    o Borland C++ for OS/2 v1.00, $495 
  280.    o CA-C++ for OS/2, $449 
  281.    o emx/gcc 0.8h (v2.5.8), freely available 
  282.    o GCC/2 v2.4.5, freely available 
  283.    o IBM C-Set++ FirstStep (without optimization) $85 (CD-ROM) 
  284.    o IBM C-Set++, $595 
  285.    o Objective C, $249 (not to be confused with the Objective-C language 
  286.      included free with emx/gcc and GCC/2) 
  287.    o TopSpeed C Pro, $297 
  288.    o TopSpeed C Standard, $198 
  289.    o WATCOM C/C++ 16 9.5, $495 
  290.    o WATCOM C/C++ 32 9.5, $599 
  291.  
  292.  5. CSP 
  293.  
  294.    o IBM CSP/2, $??? 
  295.  
  296.  6. COBOL 
  297.  
  298.    o MicroFocus Workbench with COBOL, tools and editor, $1,250. Call 1 
  299.      800-872-6265 for more information 
  300.  
  301.  7. FORTRAN 
  302.  
  303.    o f2c [Fortran to C translator], freely available 
  304.    o IBM Fortran/2 OS/2, $761 
  305.    o WATCOM FORTRAN 77 16 9.5, $495 
  306.    o WATCOM FORTRAN 77 32 9.5, $599 
  307.  
  308.  8. LISP 
  309.  
  310.    o CLISP, freely available (ma2s2.mathematik.uni-karlsruhe.de) 
  311.    o XLisp, freely available 
  312.  
  313.  9. Pascal 
  314.  
  315.    o Borland Pascal v7.0, $495 (requires patch) 
  316.    o MicroWay, $??? 
  317.    o Power Pascal/2, freely available, req. MASM 6.00 
  318.    o p2c [Pascal to C translator], freely available 
  319.    o pasos2, freely available, supports EMX/GCC (ftp.eb.ele.tue.nl) 
  320.    o TopSpeed, $??? 
  321.  
  322. 10. PERL 
  323.  
  324.    o GNU PERL v4.0pl36, freely available 
  325.  
  326. 11. PL/I 
  327.  
  328.    o IBM PL/I for OS/2 
  329.  
  330. 12. Modula-2 
  331.  
  332.    o TopSpeed, $??? 
  333.    o Stonybrook, $??? 
  334.  
  335. 13. Scheme 
  336.  
  337.    o XScheme for OS/2, freely available 
  338.  
  339. 14. SmallTalk 
  340.  
  341.    o SmallTalk/V PM, $995 
  342.    o Parc Place Smalltalk, $??? 
  343.  
  344.  
  345. RelatedInformation :
  346.  
  347. The two GNU C/C++/ObjC packages
  348.  
  349.  
  350. ΓòÉΓòÉΓòÉ 4.3. The two GNU C/C++/ObjC packages ΓòÉΓòÉΓòÉ
  351.  
  352. The two versions of GNU C that are available were ported to OS/2 with different 
  353. goals and philosophies in mind and therefore have different characteristics. 
  354. However, both systems include a fairly complete C library and can be used to 
  355. compile useful programs, although their support of Unix-specific semantics 
  356. differs.  Furthermore, both systems are being actively developed and are 
  357. constantly improving. 
  358.  
  359. The goal of GCC/2 is to create a pure, freely redistributable OS/2 2.x 
  360. development environment.  It is based on GNU C 2.5.4, supports C, C++, and 
  361. Objective C, and can create PM programs.  It produces "native" 32 bit .OBJ 
  362. files that are linked with OS/2's LINK386.EXE, and can be linked together with 
  363. .OBJ files produced by IBM C-Set++ and other compatible compilers.  The mailing 
  364. list os2gcc@netcom.com exists for discussion of this port; send mail to 
  365. os2gcc-request@netcom.com for subscription information. 
  366.  
  367. emx/gcc 0.8h, based on GNU C 2.5.7, supports C, C++, and Objective C and can 
  368. create PM programs.  emx's goal is to make porting Unix programs easier by 
  369. emulating Unix semantics as closely as possible. It produces programs that can 
  370. run under OS/2 using EMX.DLL, it produces programs that can run under OS/2 
  371. without any DLL requirements (linked with OS/2's LINK386), and it can produce 
  372. MS-DOS 32-bit executables (emx.exe DOS extender required for MS-DOS 
  373. executables).  emx/gcc uses standard Unix development tools like ld and nm, and 
  374. fully supports Unix-isms like select() and fork().  A version of gdb exists 
  375. that can debug emx/gcc programs. An emx-related mailing list exists; send mail 
  376. to LISTSERV@eb.ele.tue.nl with a message body of "help" for subscription 
  377. information. 
  378.  
  379.  
  380. ΓòÉΓòÉΓòÉ 4.4. Which of these compilers can be used to generate PM apps? ΓòÉΓòÉΓòÉ
  381.  
  382. Basically, all the compilers except the following can generate PM applications: 
  383.  
  384. o CLISP 
  385. o XLisp 
  386. o PERL 
  387. o XScheme 
  388.  
  389.  
  390. ΓòÉΓòÉΓòÉ 4.5. What is REXX?  How do I write and run a REXX program? ΓòÉΓòÉΓòÉ
  391.  
  392. REXX is the IBM SAA (Systems Application Architecture) standard, user-friendly 
  393. programming language.  It is available for IBM mainframes, Unix, the Amiga, DOS 
  394. (Quercus's Personal REXX), Windows, and other platforms.  It has been a part of 
  395. standard OS/2 since Version 1.3.  Programs written in REXX that do not use 
  396. system-specific libraries are fully portable. 
  397.  
  398. OS/2 2.x comes with an online REXX reference, and printed REXX documentation is 
  399. available (Mike Cowlishaw's REXX book, IBM's twin guides).  The Usenet group 
  400. comp.lang.rexx discusses REXX programming. 
  401.  
  402. It should be stressed, however, that OS/2's online REXX reference is a 
  403. reference, not really a tutor.    Paul Prescod 
  404. (papresco@undergrad.math.uwaterloo.ca) is working on a free REXX tutor, which 
  405. will be available on cdrom.com. 
  406.  
  407. Watcom also makes VX REXX and Hockware makes VisPro/REXX.  Both of these 
  408. products allow quick and easy development of REXX PM programs. 
  409.  
  410.  
  411. ΓòÉΓòÉΓòÉ 4.6. What debuggers are available for OS/2? ΓòÉΓòÉΓòÉ
  412.  
  413. IPMD, a PM-based debugger, ships with C-Set++.  It is capable of source- and 
  414. assembly-level debugging multithreaded 16 bit and 32 bit OS/2 applications 
  415.  
  416. emx/gcc comes with gdb 4.11, the GNU debugger. 
  417.  
  418. Borland C++/2 comes with a PM-based debugger called Turbo Debugger GX which has 
  419. the same basic functionality as IPMD. 
  420.  
  421. There are also several commercial debuggers on the market.  WATCOM C and 
  422. FORTRAN come with WVIDEO, a full-screen source or assembly level debugger that 
  423. handles multithreaded 16 and 32 bit OS/2 programs. Multiscope (no longer 
  424. available for 32-bit OS/2) and Periscope are others.  CodeView is still 
  425. applicable for 16-bit OS/2 apps, but it is not recommended for 32-bit apps. 
  426.  
  427.  
  428. ΓòÉΓòÉΓòÉ 4.7. Which assemblers can produce OS/2 32-bit code? ΓòÉΓòÉΓòÉ
  429.  
  430. o Masm 5.2 and 6.0 can produce 32 bit, 2.x compatible code. 
  431. o Masm 6.1 no longer supports OS/2. 
  432. o Tasm 1.0 (OS/2) generates 2.x code, when proper options are given. 
  433. o Tasm 3.2 (DOS) can produce OS/2 compatible .OBJ files with the /oi option. 
  434. o IBM has an assembler for 2.x, but they won't release it to the public. 
  435.  
  436.  
  437. ΓòÉΓòÉΓòÉ 5. Tools, Toolkits, Accessories ΓòÉΓòÉΓòÉ
  438.  
  439. This section covers tools, toolkits, and accessories available to OS/2 
  440. programmers. 
  441.  
  442.  
  443. ΓòÉΓòÉΓòÉ 5.1. How do I use PATCH, maybe with my own programs? ΓòÉΓòÉΓòÉ
  444.  
  445. The file format is actually quite simple - you just need a text file which 
  446. consists of lines each starting with one of the following commands: 
  447.  
  448.   FILE <filename>     e.g. FILE test.exe 
  449.  
  450. specifies the file to which the following instructions are to be applied. A 
  451. patch file may contain multiple FILE directives. 
  452.  
  453.   VER <offset> <data>   e.g. VER 00001234 abcdef 
  454.  
  455. checks if the specified data is present at the given file offset [all values in 
  456. hex, data can be just a string of digits with no blanks in between; up to 16 
  457. bytes are allowed in one statement]. If the check fails, the patch process is 
  458. aborted resp. the program skips to the next FILE statement. 
  459.  
  460.   CHA <offset> <data>   e.g. CHA 00001234 012345 
  461.  
  462. changes the data at the given offset - syntax is same as in VER. It is a good 
  463. idea to do all VERification before starting the first CHA. 
  464.  
  465. Blank lines and data lines starting with a ";" are ignored. 
  466.  
  467. As you can see from this, there seems to be no way to _insert_ or _delete_ 
  468. bytes in the file. To make patches applicable to multiple versions of the same 
  469. file, you can specifiy more than one FILE directive for the same filename - 
  470. only a patch with all VER commands matching is executed. 
  471.  
  472. Credit:  Marcus Groeber 
  473.  
  474.  
  475. ΓòÉΓòÉΓòÉ 5.2. What programming editors are available for OS/2? ΓòÉΓòÉΓòÉ
  476.  
  477. OS/2 2.x comes with the Enhanced Editor (EPM). 
  478.  
  479. GNU Emacs 19.22 is available.  It supports PM and text mode programming. Emacs 
  480. is available on cdrom.com in os2/2_x/unix/gnu/emacs.  (If you want to recompile 
  481. emacs, you will need the full emx distribution; see question 1.2.) Also, you 
  482. must have HPFS installed to use GNU emacs. You can read, write, and edit files 
  483. that exist on a DOS partition, but you must have GNU emacs installed on an HPFS 
  484. partition. 
  485.  
  486. Several public-domain vi clones are available, including elvis, Stevie and 
  487. levee.  The MKS Toolkit also includes vi. 
  488.  
  489. Many other text editors are available. 
  490.  
  491. Epsilon, by Luguru, (412) 421-5678.  DOS upgrade to OS/2 is $90.  Character 
  492. based editor. 
  493.  
  494. QEdit 3.0, by SemWare, (404) 641-9002.  Character based editor. Supports long 
  495. filenames and extended attributes. Semware can be reached by EMail: 
  496. tech.support@semware.atl.ga.us or sales@semware.atl.ga.us. 
  497.  
  498. Brief, KEDIT, others? [Vendors, phone numbers, prices?] 
  499.  
  500. EHP, a text mode editor, was recently ported by Axel Uhl to PM, and is 
  501. available on cdrom.com. 
  502.  
  503. THE (The Hessling Editor), is a free text-mode editor, based on IBM's VM/CMS 
  504. XEDIT and Mansfield Software's KEDIT.  THE has full REXX macro capabilities. 
  505. Versions also exist for DOS and most Unices. 
  506.  
  507. BOXER 6.0 for OS/2. Shareware and commercial versions available. Some features; 
  508. multi-level undo, multiple windows, syntax highlighting. Commercial version 
  509. priced at $89. Boxer Software can be contacted at; phone: 800-982-6937, 
  510. Internet: 70242.2126@compuserve.com 
  511.  
  512.  
  513. ΓòÉΓòÉΓòÉ 5.3. What programming tools/toolkits/accessories are available for OS/2? ΓòÉΓòÉΓòÉ
  514.  
  515. C-Set++ includes the following tools (excluding the compiler & debugger 
  516. themselves): 
  517.  
  518. o EXTRA - Execution trace analyzer 
  519. o A Class browser 
  520.  
  521. The IBM Programmer's Toolkit, included in Workset/2 and also in C-Set++, 
  522. includes many tools: 
  523.  
  524. o A dialog editor 
  525. o A SOM compiler 
  526. o A font editor 
  527. o An icon editor 
  528. o An IPF compiler 
  529. o Message compile & bind tools 
  530. o Resource compile & bind tools 
  531. o KwikInf 
  532. o ...and a couple others 
  533.  
  534. Borland C++ for OS/2 also includes a number of utilities, such as the Resource 
  535. Workshop. 
  536.  
  537. The MKS Toolkit, available from MKS ($299 USD, 800-265-2797 or 
  538. inquiry@mks.com), has over 160 Unix tools, including Korn shell, tar, vi, awk, 
  539. grep, tail, cpio, and so forth.  It also contains a Lex and Yacc capable of 
  540. generating C, C++, and Turbo Pascal code. 
  541.  
  542. There is a product called ARGO/UX which provides a BSD environment for OS/2. 
  543. [details?] 
  544.  
  545. SOFTPRO GmbH has announced its 32bit C++ class library TOUCH-GUI 2.0 for OS/2 
  546. 2.x. 
  547.  
  548.  
  549. ΓòÉΓòÉΓòÉ <hidden> TOUCH-GUI 2.0 for OS/2 2.x ΓòÉΓòÉΓòÉ
  550.  
  551. SOFTPRO GmbH has announced its 32bit C++ class library TOUCH-GUI 2.0 for OS/2 
  552. 2.x. The product contains more than 130 classes which support windows, menu 
  553. bars, multi-threading, controls, dialog boxes, graphics, printer control, MDI, 
  554. DDE, Drag and Drop, loadable resources from DLL's, and management of profiles 
  555. (.INI files). Other features include auxiliary classes for data manipulation 
  556. and storage management. Additionally, TOUCH-GUI 2.0 contains high-level classes 
  557. like toolbars, formatted entry fields, tables, and complete NLS. 
  558.  
  559. Supported C++ compilers are: Borland, GNU (emx), IBM, and WATCOM 
  560.  
  561. The product includes online (.INF) and printed documentation, a demo program, 
  562. and samples. 
  563.  
  564. TOUCH-GUI 2.0 costs DM 1.720,00 excl. VAT (ca. $1075), the runtime DLL's may be 
  565. distributed royalty free. Special project licenses are available, contact the 
  566. supplier. 
  567.  
  568. Contact:
  569. SOFTPRO GmbH, Stadtgrabenstr. 21, 71032 Boeblingen, Germany
  570. Tel.: +49 7031 6606-0
  571. Fax: +49 7031 6606-66
  572. Mr. Frank Fuchs (extension -50)
  573. Internet email: ffu@softpro.de
  574. IBMMAIL (IEA): DEJP9SK9
  575.  
  576.  
  577. ΓòÉΓòÉΓòÉ 5.4. What GNU tools are available and where can I find them? ΓòÉΓòÉΓòÉ
  578.  
  579. Nearly all the GNU utilities have been ported to OS/2 2.x - and nearly all of 
  580. those ports are located on cdrom.com in os2/2_x/unix/gnu. Other, more involved 
  581. (or independent) ports of GNU software is scattered about cdrom.com, including 
  582. a PM version of GhostView and GhostScript. 
  583.  
  584.  
  585. ΓòÉΓòÉΓòÉ 5.5. Is a socket library available?  How can I use it? ΓòÉΓòÉΓòÉ
  586.  
  587. IBM's TCP/IP 2.0 ($200) includes an optional Programmer's Toolkit ($500, part 
  588. #02G6973).  It includes a socket library, and support for Sun RPC, NCS RPC, and 
  589. a limited Kerberos capability.  It requires IBM C-Set++ or another compiler 
  590. that understands 16-bit code.  The 32-bit version is in beta right now. 
  591. (contact IBM for details) 
  592.  
  593. For REXX programs there is a socket library called REXXSOCK available from 
  594. cdrom.com as os2/ibm/ews/rxsock.zip.  It can be used to write TCP/IP 
  595. applications such as Gopher, IRC, etc. 
  596.  
  597. FTP Software, Inc., has an OS/2 version of its TCP/IP product.  They can be 
  598. reached at (617) 246-0900 or info@ftp.com. 
  599.  
  600. If you have the IBM TCP/IP 2.0 base package and IBM C-Set++, you can use the 
  601. TCPIPDLL.DLL directly. 
  602.  
  603.  
  604. ΓòÉΓòÉΓòÉ 6. Compiling ΓòÉΓòÉΓòÉ
  605.  
  606. This section covers compiling OS/2 programs and accessories.  The following 
  607. topics are available: 
  608.  
  609. Can I distribute the C-Set++ runtime DLL?
  610. How big should my stacksize be?
  611. How do I perform parallel compilation?
  612. What is an RC of 87 (invalid param) from the API?
  613. GCC/2 crashes with trap when I try to compile a program. Why?
  614. How do I recompile EPM (easily)?
  615. How to I get BC++ for DOS/Windows to run?
  616.  
  617.  
  618. ΓòÉΓòÉΓòÉ 6.1. Can I distribute the C-Set++ runtime DLL? ΓòÉΓòÉΓòÉ
  619.  
  620. Yes, you can! (But it is not as simple as that really...) 
  621.  
  622. You can not distribute the runtime DLL that comes with C-Set++ in its native 
  623. form, you must rebuild the DLLs you want to distribute and delete functions in 
  624. the .DEF files, so that your DLL files only contains functions your program 
  625. need. Read more about this topic in C/C++ Tools - Programming Guide pages 
  626. 195-222, that comes with C-Set++ (2.x). 
  627.  
  628.  
  629. ΓòÉΓòÉΓòÉ 6.2. How do I determine what C/C++ compilator is compiling my code? ΓòÉΓòÉΓòÉ
  630.  
  631. If your source code is written for several compilers, one need to know what 
  632. uniqe defines these compilers use. 
  633.  
  634.  
  635.  IBM C/C++            __IBMCPP__
  636.  
  637.  Borland C++ for OS/2 __BORLANDC__
  638.  
  639.  EMX/GCC              __EMX__
  640.  
  641.  
  642. ΓòÉΓòÉΓòÉ 6.3. How big should my stacksize be? ΓòÉΓòÉΓòÉ
  643.  
  644. o For non-PM programs: At least 8k for every thread. 
  645. o It is critical to avoid stack sizes where byte 2 has a value of 2 or 4, e.g.: 
  646.  
  647.    0x00020000 (128k) 
  648.    0x00040000 (256k) 
  649.    0x33023678 
  650.    0x11041111 
  651.  
  652. Otherwise, when executing under OS/2 2.0GA there may be various and always 
  653. differing runtime error behaviors.  (This is documented in OMF.INF, an online 
  654. reference from IBM concerning OBJ/EXE file formats for 16 and 32 bits.)  If you 
  655. are using IBM's C-Set your stacksize can be as big as you want. C-set is using 
  656. a sparse stack, so go ahead, allocate 100kb. (Credit: Bob?) 
  657.  
  658.  
  659. ΓòÉΓòÉΓòÉ 6.4. How do I perform parallel compilation? ΓòÉΓòÉΓòÉ
  660.  
  661. You can accomplish parallel compilation in one of two ways. The first involves 
  662. GNU Make, the second involves DMAKE. 
  663.  
  664. GNU Make: 
  665.  
  666. To perform parallel compilation with GNU Make simply do two things: 
  667.  
  668. o Make sure your make file does not execute the make utility (again) from 
  669.   inside the make file. 
  670. o On the GNU Make command line, specify '--jobs x', where 'x' is the maximum 
  671.   number of concurrent jobs you will allow GNU Make to execute. If you do not 
  672.   wish to have a maximum, then you may specify simply '--jobs' and GNU Make 
  673.   will execute as many jobs as possible at one time. 
  674.  
  675. DMAKE: 
  676.  
  677. The ini file comes in the dmake archive in a few different flavours.  Take the 
  678. file with the extension .msc and rename it to dmake.ini.  Set an environment 
  679. variable in config.sys 
  680.  
  681. SET MAKESTARTUP=d:\COMPILER\DMAKE.INI 
  682.  
  683. ====== Makefile 
  684.  
  685. CC=icc
  686. COPTS=/Sm /Gt+ /Ti+ /O- /Gs+
  687. CONLY=-c
  688.  
  689. LIBS=os2
  690.  
  691. INCS=psfax2.h
  692.  
  693. MAXPROCESS=2
  694.  
  695. all: psfax2.exe sendfax.exe
  696.  
  697. modem.obj:  modem.c $(INCS)
  698.    $(CC) $(CONLY) $(COPTS) modem.c
  699.  
  700. psfax2.obj: psfax2.c $(INCS)
  701.    $(CC) $(CONLY) $(COPTS) psfax2.c
  702.  
  703. psfax2.exe: psfax2.obj modem.obj
  704.    link386 /ST:32768 /CO psfax2+modem;
  705.  
  706. sendfax.obj: sendfax.c $(INCS)
  707.    $(CC) $(CONLY) $(COPTS) sendfax.c
  708.  
  709. sendfax.exe: sendfax.obj modem.obj
  710.    link386 /ST:32768 /CO sendfax+modem;
  711.  
  712. ====== End of makefile 
  713.  
  714. Couple of gotchas.  There is a bug in the MAXPROCESS handling of the copy I 
  715. use.  Set it to 1, and you get a typical make, ie one at a time. Set it to 2, 
  716. and the thing launches 3 processes. Ie with more than 1, you actually get n+1 
  717. processes running. 
  718.  
  719. Another caveat 
  720.  
  721. xxx.yy: aaa.bbb
  722.     command1
  723.     command2
  724.     command3
  725.  
  726. The above structure does not work.  The reason is that all 3 commands will be 
  727. spawned together in parallel sessions.  To serialize them you must make up 
  728. dependancies in the makefile.  I ran into this becuase I have one makefile that 
  729. completes every link stage by copying the result onto a network drive.  I had 
  730. to take all the links that previously had 2 commands, and break them into 2 
  731. blocks with the second being a dependancy of the remote file on the local file, 
  732. and the copy command. 
  733.  
  734. One more word of warning, dmake is not to pleased with those convoluted things 
  735. that workframe spits out in the name of makefiles.  You may have to do a 
  736. significant amount of makefile editing, depending on how you makefile look now. 
  737.  
  738. Provided that 3 simultaneous copies of your compiler doesn't push your machine 
  739. into excessive swapping, the improvements in build speed are amazing.  Before 
  740. dmake I'd never seen a build actually top the cpu meter here, the process was 
  741. always waiting for disk as it loaded compilers/headers etc.    Now the compiler 
  742. sits in ram and just gets re-used, and the headers are coming directly from 
  743. cache all the time. Build time cut in half, and my cpu guage is pegged at 100% 
  744. when a build is running. 
  745.  
  746.  
  747. ΓòÉΓòÉΓòÉ 6.5. What is an RC of 87 (invalid param) from the API? ΓòÉΓòÉΓòÉ
  748.  
  749. You are (most likely) not including the prototype.  Use the following flags to 
  750. get a good balance of warning messages: 
  751.  
  752.     /Kbperc 
  753.  
  754. For C Set++, I use these flags as the approximate equivalent 
  755.  
  756.     /Wall /Wext- /Wgnr- /Wgot- /Wpor- /Wppt- /Wtrd /Wuni- /Wvft- 
  757.  
  758. I have these set as part of my ICC string in CONFIG.SYS, so I don't have to add 
  759. them to each compile.  I have found that these settings give me a good 
  760. combination of thorough warning messages without too many warnings. 
  761.  
  762.  
  763. ΓòÉΓòÉΓòÉ 6.6. GCC/2 crashes with a trap when I try to compile a program.  Why? ΓòÉΓòÉΓòÉ
  764.  
  765. Because you didn't read the README or INSTALL files, probably.  There are three 
  766. general reasons GCC/2 will crash: 
  767.  
  768.  1. You did not set up the environment variables in CONFIG.SYS properly.  Read 
  769.     doc/INSTALL for instructions. 
  770.  
  771.  2. Some program that gcc expects to be in the PATH is not; unfortunately, gcc 
  772.     crashes instead of just printing an error message.  You may have forgotten 
  773.     to install something, or your PATH may be wrong; see above.  Giving gcc the 
  774.     -v option will cause it to print each command line as it executes it; this 
  775.     will tell you which program is missing. 
  776.  
  777.  3. You are trying to get gcc to link your program for you. It cannot because 
  778.     ld does not exist, and so it crashes (see item 2).  You must specify -c, 
  779.     -E, or -S on every invokation of gcc, and then use LINK386.EXE to create an 
  780.     executable.  See the sample makefiles for an example of how to do this. 
  781.  
  782. [Colin Jensen, the current maintainer of GCC/2, also adds the following...] 
  783.  
  784. Not true as of gcc/2 2.3.3.  Gcc will invoke a small stub program called ld.exe 
  785. that in turn will invoke link386 for you.  If the command line is too long for 
  786. the ever-pathetic link386 to handle, ld will properly create a response file. 
  787.  
  788. It is easier to use gcc/2 to call link386 than to do it yourself since gcc/2 
  789. will also arrange to call a subprogram called "collect" that is required before 
  790. linking a C++ program. 
  791.  
  792. Also, gcc/2 is just plain easier to use than link386, for example: 
  793.  
  794.          gcc -o foobar.exe mydef.def foobar.cpp mylib.lib
  795.  
  796. will compile foobar.cpp, link with mylib.lib, and pass the linker definition 
  797. file mydef.def to link386 in the correct order.  Link386 demands that you know 
  798. which types of files can be put between which sets of commas on the command 
  799. line. 
  800.  
  801.  
  802. ΓòÉΓòÉΓòÉ 6.7. How do I recompile EPM (easily)? ΓòÉΓòÉΓòÉ
  803.  
  804. I have a small CMD file to automatically compile all needed macros.  It is from 
  805. Larry Margolis (IBM), one of the authros of EPM. 
  806.  
  807. You need to have at aleast minimum knowledge of EPM.  The online manual 
  808. describes most things.    Concerning the E macros (.E) the best thing to do is, to 
  809. look in the online documentation for general questions (like: What does 
  810. 'getpminfo' do?) and then look into the supplied standard E macros for detailed 
  811. reference on hwo to use the EPM functions exactly. 
  812.  
  813. Online documentation files are: EPMTECH.INF and EPMUSERS.INF 
  814.  
  815. Here is MAKEEPM.CMD: 
  816.  
  817. @echo off
  818. set EPMPATH=h:\e;h:\e\emacros;h:\e\ebookie;h:\e\lamacros;h:\e\mye;
  819. rem Command file to call ETPM and beep in case of error.  Can be given
  820. rem a list of macro files to compile; the default is to compiler all of
  821. rem the distributed .ex files.            by Larry Margolis
  822. setlocal
  823. @if .%1 == . goto all
  824. :loop
  825. etpm %1 /v || echo 'Error in %1!'
  826. @shift
  827. @if .%1 == . goto end
  828. @goto loop
  829. :all
  830. etpm EPM /v      || echo 'Error in EPM!'
  831. etpm EPMLIST /v  || echo 'Error in EPMLIST!'
  832. etpm LAMEXTRA /v || echo 'Error in LAMEXTRA!'
  833. etpm MAILLIST /v || echo 'Error in MAILLIST!'
  834. etpm EXTRA /v    || echo 'Error in EXTRA!'
  835. etpm BKEYS /v    || echo 'Error in BKEYS!'
  836. etpm E3EMUL /v   || echo 'Error in E3EMUL!'
  837. etpm BOX /v      || echo 'Error in BOX!'
  838. etpm DRAW /v     || echo 'Error in DRAW!'
  839. etpm GET /v      || echo 'Error in GET!'
  840. etpm MATHLIB /v  || echo 'Error in MATHLIB!'
  841. etpm PUT /v      || echo 'Error in PUT!'
  842. etpm HELP /v     || echo 'Error in HELP!'
  843. etpm EPMLEX /v   || echo 'Error in EPMLEX!'
  844. etpm MAKETAGS /v || echo 'Error in MAKETAGS!'
  845. :end
  846. endlocal
  847.  
  848.  
  849. ΓòÉΓòÉΓòÉ 6.8. How to I get BC++ for DOS/Windows to run? ΓòÉΓòÉΓòÉ
  850.  
  851. Open up the Settings folder for the executable, and under "DOS Settings" set 
  852. DPMI_DOS_API to ENABLED. 
  853.  
  854.  
  855. ΓòÉΓòÉΓòÉ 7. Documentation, Help ΓòÉΓòÉΓòÉ
  856.  
  857. This section covers documentation and help available for OS/2 programming. 
  858.  
  859.  
  860. ΓòÉΓòÉΓòÉ 7.1. Where can I get information on OS/2 APIs and programming? ΓòÉΓòÉΓòÉ
  861.  
  862. The IBM Programmer's Toolkit, included in Workset/2, includes a complete 
  863. on-line syscall reference. 
  864.  
  865. You can FTP the documentation for the 16-bit calls (IBM does not supply them), 
  866. such as Vio*(), Kbd*(), Mou*(), from cdrom.com as os2/2_x/program/inf16bit.zip. 
  867.  
  868. You can order the seventeen volume IBM OS/2 Technical Library (possibly at a 
  869. discount, see question 1.2) and/or order various volumes individually. 
  870.  
  871. Most of these volumes are now published by Que books also, and can be found in 
  872. many bookstores. 
  873.  
  874. All this information is also on the OS/2 Online Book Collection CD-ROM (see the 
  875. User's Edition for details), and the Professional Developer's Kit CD-ROMs have 
  876. this information as well. 
  877.  
  878.  
  879. Related Information:
  880.  
  881. What are good reference books for programming in OS/2 and PM?
  882.  
  883.  
  884. ΓòÉΓòÉΓòÉ 7.2. Where can I get sample code? ΓòÉΓòÉΓòÉ
  885.  
  886. There is a lot of sample code included in the IBM Toolkit, and four sample 
  887. programs (with source) included with C-Set++.  GNU C/C++, from cdrom.com, 
  888. includes a sample C, C++, and C++ PM program.  The OS/2 Redbooks also have some 
  889. sample code.  cdrom.com also has little bits of OS/2 and PM source code lying 
  890. around in the os2/2_x/program directory. 
  891.  
  892.  
  893. Related Information:
  894.  
  895. What are the OS/2 redbooks, and how do I get them?
  896.  
  897.  
  898. ΓòÉΓòÉΓòÉ 7.3. Are there any OS/2 programming classes or seminars? ΓòÉΓòÉΓòÉ
  899.  
  900. Yes.  Call IBM at either 1-800-3-IBM-OS2 in U.S. (or the PS/2 Help Center). 
  901. Local IBM branches frequently hold OS/2 classes and seminars. 
  902.  
  903. See os2/2_x/info/ivleague.txt on cdrom.com or the User's Edition for a list of 
  904. third-party support organizations. 
  905.  
  906. Make sure to check your local software companies.  Many of them offer OS/2 
  907. specific classes also. 
  908.  
  909.  
  910. ΓòÉΓòÉΓòÉ 7.4. What are good ref. books for programming in OS/2 and PM? ΓòÉΓòÉΓòÉ
  911.  
  912. Van Nostrand Reinhold publishes a number of books on OS/2 2.x.  Those that 
  913. relate to programming are: 
  914.  
  915. INTEGRATING APPLICATIONS WITH OS/2 2.0
  916. By William H. Zack
  917. 0-422-01234-9
  918.  
  919. CLIENT/SERVER PROGRAMMING WITH OS/2 2.0, 2nd Edition
  920. By Robert Orfali and Daniel Harkey, IBM Corporation
  921. 0-422-01219-5
  922.  
  923. WRITING OS/2 2.0 DEVICE DRIVERS IN C
  924. By Steven J. Mastrianni; Foreword by John Soyring, IBM Corporation
  925. 0-442-01141-5
  926.  
  927. OS/2 2.0 PRESENTATION MANAGER GPI: A Programming Guide to Text, Graphics, And Printing
  928. By Graham C.E. Winn, IBM Corporation
  929. 0-442-00739-6
  930.  
  931. THE COBOL PRESENTATION MANAGER PROGRAMMING GUIDE
  932. By David M. Dill, Consultant
  933. 0-442-01293-4
  934.  
  935. LEARNING TO PROGRAM OS/2 2.0 PRESENTATION MANAGER BY EXAMPLE: Putting the Pieces Together
  936. By Stephen Knight, IBM Corportaion
  937. 0-442-01292-6
  938.  
  939. THE ART OF OS/2 2.1 C PROGRAMMING
  940. By Panov, Salomon, and Panov
  941. 620p, $39.95 US (suggested) includes disk with samples
  942. ISBN 0-89435-446-9
  943.  
  944. OS/2 PRESENTATION MANAGER PROGRAMMING
  945. By Petzold, Ziff-Davis Press
  946. 1-56276-123-4
  947.  
  948. DESIGN OF OS/2, SECOND EDITION
  949. By Kogan & Deitel, Addison-Wesley,
  950. 0-201-52886-X
  951.  
  952. ULTIMATE OS/2 PROGRAMMER's MANUAL
  953. Mueller, McGraw-Hill Professional Computing
  954. 0-07-043972-9
  955.  
  956. EFFECTIVE MULTITHREADING IN OS/2
  957. By Dorfman & Neuberger, McGraw-Hill Professional Computing
  958. 0-07-017841-0,
  959.  
  960. OS/2 REMOTE COMMUNICATIONS: Async to sync
  961. By Stonecipher, Van Nostrand Reinhold
  962. 0-0442-01814-2,
  963.  
  964. OS/2 V2 C++ CLASS LIBRARY: Power GUI Programming
  965. By Law et al, Van Nostrand Reinhold
  966. 0-442-01795-2
  967.  
  968. OBJECTS FOR OS/2 2.1
  969. By Tate et al, Van Nostrand Reinhold
  970. 0-442-01738-3,
  971.  
  972. OS/2 AND NETWARE PROGRAMMING: Netware Client API
  973. By Gauthier, Van Nostrand Reinhold
  974. 0-442-01815-0
  975.  
  976. OS/2 PROGRAMMING: Your Fast-Track Guide to OS/2
  977. By Herbert Schildt & Robert Goosey
  978. 306p, $29.95
  979. ISBN 0-07-881910-5
  980.  
  981. ADVANCED ASSEMBLY LANGUAGE
  982. Steven Holzner and Peter Norton Computing Inc.
  983. Brady Books, A division of Simon & Schuster, New York, NY, USA
  984. 1991  ISBN 0-13-633014-6
  985.  
  986. OBJECT-ORIENTED PROGRAMMING WITH SOM AND DSOM
  987. Christina Lau
  988. Van Nostrand Reinhold
  989. OSBN 0-442-01948-3
  990.  
  991. IBM has a .INF file where all IBM OS/2 related books are listed. 
  992.  
  993.  
  994. Related Information:
  995.  
  996. What are the OS/2 redbooks, and how do I get them?
  997.  
  998.  
  999. ΓòÉΓòÉΓòÉ 7.5. What are good OS/2 programming magazines? ΓòÉΓòÉΓòÉ
  1000.  
  1001. OS/2 Developer 
  1002.  
  1003. (subscription info?) 
  1004.  
  1005. Electronic Developers' Magazine/2 
  1006.  
  1007. Excellent electronic magazine for OS/2 developers.  Available somewhat monthly 
  1008. from ftp-os2.cdrom.com in 2_x/program/newsltr/edmi*.zip. 
  1009.  
  1010. PC Magazine 
  1011.  
  1012. While this is not by any means a dedicated OS/2 programming magazine, it 
  1013. includes several gems from Charles Petzold, most notably a nice series on font 
  1014. handling. 
  1015.  
  1016.  
  1017. ΓòÉΓòÉΓòÉ 7.6. What are the OS/2 redbooks, and how do I get them? ΓòÉΓòÉΓòÉ
  1018.  
  1019. (see end note for FTP information) 
  1020.  
  1021. IBM publishes so-called "redbooks" on many products, including OS/2 2.x.  They 
  1022. seem to be a combination of power-user's guides and design information that may 
  1023. be of use to both users and programmers [I haven't received my copies yet, so I 
  1024. cannot say for sure.]  These are usually intended only for special IBM 
  1025. customers and contain documentation that is generally unavailable anywhere 
  1026. else.  You can order these books directly from IBM (see below).  All of the 
  1027. following names are implicitly preceeded by "OS/2 Version 2.0." 
  1028.  
  1029. Volume 1: Control Program: GG24-3730, $4.15 
  1030.      Technical information on Memory Management, Task Mangement, Support, 
  1031.      Installation Considerations, Hardware Considerations, Boot Manager, 
  1032.      National Language Considerations, Intel 386 architecture, Channel 
  1033.      Architecture and SCSI.    Documents config.sys. 
  1034.  
  1035. Volume 2: DOS and Windows Environment, GG24-3731, $6.20 
  1036.      MVDM,8086 Emulation,MVDM DOS emulation, Device Drivers, Memory Extender 
  1037.      Support, Installing and Migrating Applications, Windows Applications, 
  1038.      DPMI, Running DOS apps,DOS settings, VMB. 
  1039.  
  1040. Volume 3:  PM and Workplace Shell GG24-3732, $3.65 
  1041.      Available now, but I don't know precisely what's in it. 
  1042.  
  1043. Volume 4: Application Development GG24-3774, $5.25 
  1044.      Technical programming info (includes list in C) Overview, Object-Oriented 
  1045.      Apps, PM application model, flat memory model, building PM app, Workplace 
  1046.      AOAShell and System Object Model, Direct Manipulation (Drag/drop), PM 
  1047.      resources, Multitasking Considerations, SAA CUA considerations, App 
  1048.      Migration, Mixing 16 and 32 bit application modules, compiling and link 
  1049.      editing (SOM), Adding Online Help, Problem Determination, Managing 
  1050.      Development, Naming conventions. 
  1051.  
  1052. Volume 5: Print Subsystem, GG24-3775, $5.20 
  1053.      Information on programming the print subsystem. 
  1054.  
  1055. The special part number GBOF-2254 is for all currently available volumes 
  1056. (presently 1-5). 
  1057.  
  1058. ORDERING INFORMATION: 
  1059.  
  1060. The OS/2 2.x Redbooks are available from IBM's TeleServices customer support 
  1061. number.  The number is 1-800-7654-IBM (1-800-765-4426).  You can pay by credit 
  1062. card or mail in a check after calling.  The order will take about 2 weeks but 
  1063. can be sped up by paying for faster shipping. 
  1064.  
  1065. You can also order the redbooks from your local IBM Branch Office library. 
  1066. Some possibly useful phone numbers are included here. 
  1067.  
  1068.     IBM Central Library, Los Angeles CA: (213) 621-6710
  1069.         P.O. Box 60737
  1070.         Los Angeles, CA 90060
  1071.     Canada: (800) 465-1234, ext 4205 ($33.52)
  1072.     UK: (0256) 478166, (#36.51, credit cards accepted)
  1073.     Australia (Victoria): 698-1234 ($46.80 A)
  1074.         IBM Australia
  1075.         The Library
  1076.         211 Sturt Street
  1077.         South Melbourne, 3205
  1078.         Att: Kate Seeley
  1079.     Denmark: 33 32 40 55 (dkk 310)
  1080.  
  1081. The redbooks are also FTP'able from cdrom.com as the os2/ibm/misc/redbk*.zip. 
  1082. The source code that accompanies the first three redbooks can FTP'able from 
  1083. cdrom.com as os2/2_x/program/rb37*.zip. 
  1084.  
  1085. Various OS/2 technical programming books can be found on the Developers 
  1086. Connection CDROM.  The entire OS/2 Library can be found on the "OS/2 Online 
  1087. Book Collection CDROM", Order Number S53G-2166-00. 
  1088.  
  1089.  
  1090. ΓòÉΓòÉΓòÉ 7.7. How can I view the GNU C documentation? ΓòÉΓòÉΓòÉ
  1091.  
  1092. GNU C/C++ comes with documentation from the Free Software Foundation in texinfo 
  1093. (.texi) format.  This documentation is about gcc in general, and has no 
  1094. OS/2-specific information. 
  1095.  
  1096. All utilities needed to compile/view/tex the texinfo files are readily 
  1097. available for OS/2.  The GNU texinfo package, available on cdrom.com in 
  1098. os2/all/unix/gnu/gnuinfo.zip, includes makeinfo.exe for compiling texinfo, 
  1099. info.exe for viewing them, and texinfo.tex and texindex.exe for TeXing them. 
  1100.  
  1101. An ASCII text version of the gcc documentation is also available on cdrom.com, 
  1102. in the file os2/2_x/unix/gnu/gcc2_233/gcc_inf.zip. 
  1103.  
  1104. An INF hypertext version of the gcc (and related programs) documentation was 
  1105. uploaded recently to cdrom.com. 
  1106.  
  1107. emx/gcc includes its own hypertext style reader and texinfo files for all the 
  1108. GNU tools that come with it. 
  1109.  
  1110. GCC/2 includes the hypertext manuals for gcc, gas, and gnumake as well as a PM 
  1111. reader for the manuals. 
  1112.  
  1113. GNU Emacs for OS/2 reads GNU info files in their native format, with no 
  1114. conversion necessary on the user's part. 
  1115.  
  1116.  
  1117. ΓòÉΓòÉΓòÉ 7.8. Where can I get documentation on the OBJ/LIB/EXE format used by OS/2 2.x? ΓòÉΓòÉΓòÉ
  1118.  
  1119. o The .EXE format was described briefly in PC Magazine, Vol 11 No. 12 (June 30, 
  1120.   1992?); it was also described in a 1988 issue. 
  1121. o The glib source code contains a full description of the 32 bit OBJ and LIB 
  1122.   formats.  It is found at cdrom.com:/os2/2_x/unix/gnu/gcc2_233/glibs115.zip. 
  1123. o It is available in text form from cdrom.com as os2/2_x/program/lxexe.doc. 
  1124. o OMF.INF from IBM (the IBM BBS) comes highly recommended. 
  1125.  
  1126.  
  1127. ΓòÉΓòÉΓòÉ 7.9. Where can I find information on HPFS? ΓòÉΓòÉΓòÉ
  1128.  
  1129. There is a Microsoft Systems Journal article about it (64k ZIPped, so it has a 
  1130. lot of information) in ftp-os2.cdrom.com in all/info.hpfs.zip. 
  1131.  
  1132.  
  1133. ΓòÉΓòÉΓòÉ 8. PM Programming ΓòÉΓòÉΓòÉ
  1134.  
  1135. This section covers Presentation Manager programming. 
  1136.  
  1137.  
  1138. ΓòÉΓòÉΓòÉ 8.1. Printing ΓòÉΓòÉΓòÉ
  1139.  
  1140. This section covers Presentation Manager printing. 
  1141.  
  1142.  
  1143. ΓòÉΓòÉΓòÉ 8.1.1. Are there any SIMPLE examples of printing? ΓòÉΓòÉΓòÉ
  1144.  
  1145. Here is some sample code, but also check out PRINTQ12.ZIP on cdrom.com in 
  1146. 2_x/program. PRINTQ12.ZIP contains a DLL that encapselates alot of the messy 
  1147. details. 
  1148.  
  1149. Here is the working code for allowing the user to change the printer setup. 
  1150. I've also included the code that I use to start and end printing, so you can 
  1151. see how it all works. 
  1152.  
  1153. If you have any questions or comments, feel free to write. 
  1154.  
  1155. PrinterSetup() is the routine that gets the printer setup information from the 
  1156. user. 
  1157.  
  1158. GetPrinterHPS() is the routine that gets the DC and PS for the printer, and 
  1159. starts the document. 
  1160.  
  1161. EndPrint() is the routine that ends the document, and closes the DC. 
  1162.  
  1163. First, here's a little sample of how to use PrinterSetup(), GetPrinterHPS(), 
  1164. and EndPrint(): 
  1165.  
  1166. {
  1167.    HPS          hPrinterPS;
  1168.    HDC          hPrinterDC;
  1169.    DEVOPENSTRUC dops;
  1170.  
  1171.    ...
  1172.  
  1173.    dops->pszLogAddress = NULL;  // in case PrinterSetup fails, this will tell
  1174.                                 // GetPrinterHPS() to use default printer info
  1175.  
  1176.    PrinterSetup(&dops);
  1177.  
  1178.    hPrinterPS = GetPrinterHPS(&dops, &hPrinterDC,
  1179.                               "Document Name", 0L, 0L);
  1180.    if (hPrinterPS != GPI_ERROR) {
  1181.       // do your printing here
  1182.  
  1183.       EndPrint(hPrinterPS, hPrinterDC, "Document Name");
  1184.    }
  1185.  
  1186.    ...
  1187. }
  1188.  
  1189.  
  1190. /*
  1191. ******************************************************************************
  1192. **  FUNCTION: PrinterSetup
  1193. **  PURPOSE :   This function allows the user to change printer settings.
  1194. **
  1195. **  PARAMS  :   lpdos - the printer info
  1196. **  RETURN  :   BOOL   (TRUE = success)
  1197. **
  1198. **  DATE    :   11-Dec-1992
  1199. **  AUTHOR  :   Carl Samos
  1200. ******************************************************************************
  1201. **  Modified: Date:     Description of changes
  1202. **  CNS     :   11-Dec-1992 Initial version
  1203. ******************************************************************************
  1204. */
  1205. BOOL PrinterSetup(DEVOPENSTRUC FAR *lpdos)
  1206. {
  1207.    PDRIVDATA     pDriveData;      /*  The drive data  */
  1208.    unsigned long ulSize;          /*  The buffer size required  */
  1209.    char          szPrinter[32];   /*  The printer name  */
  1210.    PSZ           pszDriver;       /*  The driver name  */
  1211.    PSZ           pszLogicalPort;  /*  The logical port  */
  1212.    char          szDeviceName[32];/*  The printer's name */
  1213.  
  1214.  
  1215.    // get the printer driver, name and logical port
  1216.    // GetPrinterInformation allocates space for pszDriver and pszLogicalPort
  1217.    if (!GetPrinterInformation(szPrinter, &pszDriver,
  1218.                               szDeviceName,&pszLogicalPort))
  1219.       return(FALSE);
  1220.  
  1221.  
  1222.    // get the size needed for the DRIVDATA struct
  1223.    ulSize = DevPostDeviceModes(habMain, NULL, pszDriver, NULL, szPrinter, 0L);
  1224.  
  1225.  
  1226.    if (ulSize != DPDM_NONE && ulSize != DPDM_ERROR) {
  1227.       pDriveData = (PDRIVDATA) _fmalloc(ulSize);
  1228.       pDriveData->cb = ulSize;
  1229.  
  1230.       // bring up the dialog boxes, and fill the DRIVDATA struct
  1231.       ulSize = DevPostDeviceModes(habMain, pDriveData, pszDriver, NULL,
  1232.                                   szPrinter, 0L);
  1233.  
  1234.       if (ulSize == DEV_OK) {
  1235.           // if there is a printer name, copy it into the DRIVDATA
  1236.           if (szDeviceName[0] != '\0')
  1237.              strcpy(pDriveData->szDeviceName, szDeviceName);
  1238.  
  1239.           // remove the old information
  1240.           if (lpdos->pszLogAddress != NULL) {
  1241.              _ffree(lpdos->pszLogAddress);
  1242.           }
  1243.           if (lpdos->pszDriverName != NULL) {
  1244.              _ffree(lpdos->pszDriverName);
  1245.           }
  1246.           if (lpdos->pdriv != NULL)
  1247.              _ffree(lpdos->pdriv);
  1248.  
  1249.           /*  Setup the DEVOPENSTRUC  */
  1250.           lpdos->pszLogAddress = pszLogicalPort;
  1251.           lpdos->pszDriverName = pszDriver;
  1252.           lpdos->pszDataType   = NULL;
  1253.           lpdos->pdriv         = pDriveData;
  1254.       }
  1255.       else {
  1256.           _ffree(pszDriver);
  1257.           _ffree(pszLogicalPort);
  1258.           _ffree(pDriveData);
  1259.       }
  1260.    }
  1261.    else {
  1262.       _ffree(pszDriver);
  1263.       _ffree(pszLogicalPort);
  1264.    }
  1265.  
  1266.    return(TRUE);
  1267. }
  1268.  
  1269.  
  1270. /*
  1271. ******************************************************************************
  1272. **  FUNCTION:   GetPrinterInformation
  1273. **  PURPOSE :   This function gets the current printer information from the
  1274. **                    os2.ini file.
  1275. **
  1276. **  PARAMS  :   PSZ pszPrinter
  1277. **              PSZ pszDriver
  1278. **              PSZ pszDeviceName
  1279. **              PSZ pszLogicalPort
  1280. **
  1281. **  RETURN  :   void
  1282. **
  1283. **  DATE    :   11-Dec-1992
  1284. **  AUTHOR  :   Carl Samos
  1285. ******************************************************************************
  1286. **  Modified: Date:     Description of changes
  1287. **  CNS     :   11-Dec-1992 Initial version
  1288. ******************************************************************************
  1289. */
  1290. BOOL GetPrinterInformation(PSZ pszPrinter, PSZ FAR *lpszDriver,
  1291.                            PSZ pszDeviceName, PSZ FAR *lpszLogicalPort)
  1292. {
  1293.    int  cb;
  1294.    char szDetails[256];
  1295.    PSZ  pszBegin;
  1296.    PSZ  pszTemp;
  1297.    char szPort[64];
  1298.    char szDriver[64];
  1299.    char szLogPort[64];
  1300.  
  1301.    /*  Get the printer name  */
  1302.    cb = WinQueryProfileString(habMain, "PM_SPOOLER",
  1303.                               "PRINTER", "", pszPrinter,32);
  1304.    pszPrinter[cb-2] = 0;
  1305.  
  1306.  
  1307.    /*  Get the other details  */
  1308.    WinQueryProfileString(habMain, "PM_SPOOLER_PRINTER", pszPrinter, "",
  1309.                          szDetails, 256);
  1310.  
  1311.    // the profile string has the following format:
  1312.    // PORT;DRIVER;LOGICAL PORT;NETWORK INFO;
  1313.    // fields can have more than one entry, separated by a comma
  1314.    // the printer's name will follow the driver, separated by a period.
  1315.  
  1316.    pszBegin = szDetails;
  1317.  
  1318.    // get the printer port
  1319.    pszTemp = strchr(pszBegin, ';');
  1320.    if (pszTemp != NULL) {
  1321.       *pszTemp = '\0';
  1322.       strcpy(szPort, pszBegin);
  1323.       *pszTemp = ';';
  1324.       pszBegin = pszTemp + 1;
  1325.  
  1326.       // check for a comma in the string
  1327.       pszTemp = strchr(szPort, ',');
  1328.       if (pszTemp != NULL) *pszTemp = '\0';
  1329.    }
  1330.    else {
  1331.       return(FALSE);
  1332.    }
  1333.  
  1334.    // now get the driver and printer name
  1335.    pszTemp = strchr(pszBegin, ';');
  1336.    if (pszTemp != NULL) {
  1337.       *pszTemp = '\0';
  1338.       strcpy(szDriver, pszBegin);
  1339.       *pszTemp = ';';
  1340.       pszBegin = pszTemp + 1;
  1341.  
  1342.       // check for a period (printer name follows it)
  1343.       pszTemp = strchr(szDriver, '.');
  1344.       if (pszTemp != NULL) {
  1345.          strcpy(pszDeviceName, pszTemp+1);
  1346.          *pszTemp = '\0';
  1347.       }
  1348.       else {
  1349.          pszDeviceName[0] = '\0';
  1350.       }
  1351.  
  1352.       // check for a comma in the string
  1353.       pszTemp = strchr(szDriver, ',');
  1354.       if (pszTemp != NULL)
  1355.         *pszTemp = '\0';
  1356.    }
  1357.    else {
  1358.       return(FALSE);
  1359.    }
  1360.  
  1361.  
  1362.    // now get the logical port
  1363.    pszTemp = strchr(pszBegin, ';');
  1364.    if (pszTemp != NULL) {
  1365.       *pszTemp = '\0';
  1366.       strcpy(szLogPort, pszBegin);
  1367.       *pszTemp = ';';
  1368.       pszBegin = pszTemp + 1;
  1369.  
  1370.       // check for a comma in the string
  1371.       pszTemp = strchr(szLogPort, ',');
  1372.       if (pszTemp != NULL)
  1373.         *pszTemp = '\0';
  1374.    }
  1375.    else {
  1376.       return(FALSE);
  1377.    }
  1378.  
  1379.    *lpszDriver = _fmalloc(sizeof(char) * (strlen(szDriver)+1));
  1380.    strcpy(*lpszDriver, szDriver);
  1381.  
  1382.    *lpszLogicalPort = _fmalloc(sizeof(char) * (strlen(szLogPort)+1));
  1383.    strcpy(*lpszLogicalPort, szLogPort);
  1384.  
  1385.    return(TRUE);
  1386. }
  1387.  
  1388.  
  1389. /*
  1390. ******************************************************************************
  1391. **  FUNCTION: GetPrinterHPS
  1392. **  PURPOSE :   Gets the presentation space for a printer, and starts the doc
  1393. **  PARAMS  :   lpdos
  1394. **          :   lphDC           - the printer's hdc
  1395. **          :   pszDocName      - the name of the document
  1396. **          :   lWidth          - the width of the document
  1397. **          :   lHeight         - the height of the document
  1398. **  RETURN  : hPS
  1399. **  DATE    :   11-Dec-1992
  1400. **  AUTHOR  :   Carl Samos
  1401. ******************************************************************************
  1402. **  Modified: Date:     Description of changes
  1403. **  CNS     :   11-Dec-1992 Initial version
  1404. ******************************************************************************
  1405. */
  1406. HPS GetPrinterHPS(DEVOPENSTRUC FAR *lpdos, HDC FAR* lphDC, PSZ pszDocName,
  1407.           LONG lWidth, LONG lHeight)
  1408. {
  1409.    LONG  lReturn;
  1410.    SIZEL sizl;
  1411.    HPS   hPS;
  1412.  
  1413.    if (lpdops->pszLogAddress == NULL) {  // get the default settings
  1414.       char szPrinter[32];   /*  The printer name    */
  1415.       PSZ  pszDriver;       /*  The driver name  */
  1416.       PSZ  pszLogicalPort;  /*  The logical port    */
  1417.       char szDeviceName[32];/*  The printer's name */
  1418.  
  1419.       // GetPrinterInformation allocates space for pszDriver and pszLogicalPort
  1420.       if (!GetPrinterInformation(szPrinter, &pszDriver, szDeviceName,
  1421.                                  &pszLogicalPort))
  1422.       return(GPI_ERROR);
  1423.  
  1424.       lpdops->pszLogAddress = pszLogicalPort;
  1425.       lpdops->pszDriverName = pszDriver;
  1426.       lpdops->pszDataType   = NULL;
  1427.       lpdops->pdriv         = NULL;
  1428.    }
  1429.  
  1430.    // open the printer DC
  1431.    *lphDC = DevOpenDC (habMain, OD_QUEUED, "*", 4L, lpdops, (HDC) NULL);
  1432.    if (*lphDC == DEV_ERROR) {
  1433.       return(GPI_ERROR);
  1434.    }
  1435.  
  1436.    // start the document
  1437.    lReturn = DevEscape(*lphDC, DEVESC_STARTDOC, strlen(pszDocName),
  1438.                        pszDocName,NULL, NULL);
  1439.  
  1440.    // get the PS for the printer
  1441.    if (lReturn == DEV_OK) {
  1442.        sizl.cx = lWidth;
  1443.        sizl.cy = lHeight;
  1444.  
  1445.        if (lWidth == 0) {
  1446.           hPS =  GpiCreatePS (habMain, *lphDC, &sizl,
  1447.                               PU_LOENGLISH | GPIF_DEFAULT |
  1448.                               GPIT_NORMAL | GPIA_ASSOC);
  1449.           return(hPS);
  1450.        }
  1451.        else {
  1452.           hPS = GpiCreatePS (habMain, *lphDC, &sizl,
  1453.                               PU_ARBITRARY | PU_LOENGLISH |
  1454.                               GPIF_DEFAULT | GPIT_NORMAL |
  1455.                               GPIA_ASSOC);
  1456.           return(hPS);
  1457.       }
  1458.    }
  1459.  
  1460.    return(GPI_ERROR);
  1461. }
  1462.  
  1463.  
  1464. /*
  1465. ******************************************************************************
  1466. **  FUNCTION: EndPrint
  1467. **  PURPOSE : To close the hdc and end the document
  1468. **  PARAMS  : hpsPrinter - the printer's presentation space
  1469. **     : hdcPrinter - the printer's device context
  1470. **     : pszDocName - the name of the document
  1471. **  RETURN  : nothing
  1472. **  DATE    :   11-Dec-1992
  1473. **  AUTHOR  :   Carl Samos
  1474. ******************************************************************************
  1475. **  Modified: Date:     Description of changes
  1476. **  CNS     :   11-Dec-1992 Initial version
  1477. ******************************************************************************
  1478. */
  1479. void EndPrint(HPS hpsPrinter, HDC hdcPrinter, PSZ pszDocName)
  1480. {
  1481. DevEscape(hdcPrinter, DEVESC_ENDDOC, strlen(pszDocName),
  1482. pszDocName, NULL,NULL);
  1483. GpiAssociate(hpsPrinter, (HDC) NULL);
  1484. DevCloseDC(hdcPrinter);
  1485. GpiDestroyPS(hpsPrinter);
  1486. }
  1487.  
  1488. Credit:  Carl Samos 
  1489.  
  1490.  
  1491. ΓòÉΓòÉΓòÉ 8.1.2. Is there an easy way to get printer output (another opinion)? ΓòÉΓòÉΓòÉ
  1492.  
  1493. A reader who desires to remain anonymous writes: 
  1494.  
  1495. Generally:  My understanding was that OS/2 would handle printing for me.  That 
  1496. is to say that I wouldn't have to create separate printer drivers for every 
  1497. printer under the sun (or any for that matter).  Since I am creating an image 
  1498. on the screen that is device independent (well, mostly anyway), is there an 
  1499. easy way to get printer output? 
  1500.  
  1501. PM achieves a level of device independence by defining a logical output space. 
  1502. This logical output space is then bound to a physical output space, which 
  1503. creates a mapping of logical characteristics to their physical counterparts. 
  1504. The logical and physical output spaces are referred to as the presentation 
  1505. space and the device context (HPS and HDC) and are bound to one another by 
  1506. using either the GpiAssociate function or by specifying GPIA_ASSOC to the 
  1507. GpiCreatePS function. 
  1508.  
  1509. The easiest way to accomplish what you desire is to organize your drawing code 
  1510. into one or more functions with a single entrypoint that accepts an HPS as a 
  1511. parameter.  Then, when you want to draw to the screen, you can call 
  1512. WinGetPS/WinBeginPaint to get an HPS and call the function. When you want 
  1513. hardcopy, you call DevOpenDC to get an HDC and GpiCreatePS to get an HPS and 
  1514. call the function. 
  1515.  
  1516. Note that to get hardcopy, you need to perform some additional setup to get 
  1517. things to work properly.  The two most important things are that you initialize 
  1518. the DEVOPENSTRUC structure properly before calling DevOpenDC and that you send 
  1519. the following escape codes (via DevEscape) at the following times: 
  1520.  
  1521.   hdcPrn=DevOpenDC(...);
  1522.   hpsPrn=GpiCreatePS(...);
  1523.  
  1524.   DevEscape(...,DEVESC_STARTDOC,...);
  1525.  
  1526.   if (!doDraw(hpsPrn)) {
  1527.      DevEscape(...,DEVESC_ABORTDOC,...);
  1528.   } /* endif */
  1529.  
  1530.   DevEscape(...,DEVESC_ENDDOC,...);
  1531.  
  1532.   GpiDestroyPS(hpsPrn);
  1533.   DevCloseDC(hdcPrn);
  1534.  
  1535. I'm not sure because I can't seem to find my copy anywhere, but I belive that 
  1536. the book by Graham Winn (entitled something to the effect of "Building 
  1537. applications using the OS/2 Presentation Manager") dedicates a chapter to the 
  1538. nuances of printing. 
  1539.  
  1540. (Quoted almost directly from EDMI/2 Edition 1) 
  1541.  
  1542.  
  1543. Related Information:
  1544.  
  1545. What are good reference books for programming in OS/2 and PM?
  1546.  
  1547.  
  1548. ΓòÉΓòÉΓòÉ 8.1.3. How do I print a bitmap? ΓòÉΓòÉΓòÉ
  1549.  
  1550. Here's my code for sending a bitmap to the printer I'm leaving out the part 
  1551. where I maintain an aspect ratio between the screen and the printer page. 
  1552.  
  1553.     SIZEL sizl = {0,0};
  1554.     // Get DC/PS for printer
  1555.     hdcPrinter = GetPrinterDC( hab, PM_Q_STD );
  1556.     hpsPrinter = GpiCreatePS( hab, hdcPrinter, &sizl,
  1557.                               PU_PELS | GPIF_DEFAULT |
  1558.                               GPIT_NORMAL | GPIA_ASSOC);
  1559.  
  1560.     // Get DC/PS for memory DC compatible with printer
  1561.     hdcPrtMem = DevOpenDC( hab, OD_MEMORY, "*", 0, NULL, hdcPrinter );
  1562.     hpsPrtMem = GpiCreatePS( hab, hdcPrtMem, &sizl,
  1563.                              PU_PELS | GPIF_DEFAULT |
  1564.                              GPIT_MICRO | GPIA_ASSOC );
  1565.  
  1566.     // Get DC/PS for memory DC compatible with display
  1567.     hdcMemory = DevOpenDC( hab, OD_MEMORY, "*", 0, NULL, NULLHANDLE );
  1568.     hpsMemory = GpiCreatePS( hab, hdcMemory, &sizl,
  1569.                              PU_PELS | GPIF_DEFAULT |
  1570.                              GPIT_MICRO | GPIA_ASSOC );
  1571.  
  1572.     // Get PS for a window to be printed
  1573.     hpsToPrint = WinGetPS( hwndToPrint );
  1574.  
  1575.     // Set up memory BitBlt
  1576.     BITMAPINFOHEADER2 bmih;
  1577.     LONG alBitmapStuff[ 2 ];
  1578.     WinQueryWindowPos( hwndToPrint, &swp );
  1579.     bmih.cbFix = sizeof( BITMAPINFOHEADER2 );
  1580.     bmih.cx = swp.cx;
  1581.     bmih.cy = swp.cy;
  1582.     GpiQueryDeviceBitmapFormats( hpsToPrint, 2L, alBitmapStuff );
  1583.     bmih.cPlanes = (USHORT) alBitmapStuff[ 0 ];
  1584.     bmih.cBitCount = (USHORT) alBitmapStuff[ 1 ];
  1585.  
  1586.     // ....Set up aptl[0],[1],[2],[3] for the memory BitBlt
  1587.  
  1588.     // Do BitBlt from Display memory PS to Printer memory PS
  1589.     hbmToPrint = GpiCreateBitmap( hpsMemory, &bmih, 0, NULL, NULL );
  1590.     GpiSetBitmap( hpsMemory, hbmToPrint );
  1591.     GpiBitBlt( hpsMemory, hpsToPrint, 3L, aptl, ROP_SRCCOPY, BBO_IGNORE );
  1592.     GpiSetBitmap( hpsMemory, NULLHANDLE );
  1593.  
  1594.     GpiSetBitmap( hpsPrtMem, hbmToPrint );
  1595.  
  1596.     // ....Set up aptl[0],[1],[2],[3] for the printer BitBlt
  1597.  
  1598.     // BitBlt to printer PS from Printer memory PS
  1599.     DevEscape( hdcPrinter, DEVESC_STARTDOC,strlen( szDocName ), szDocName,
  1600.                &lBytes, NULL );
  1601.     GpiBitBlt( hpsPrinter, hpsPrtMem, 4L, aptl, ROP_SRCCOPY,BBO_IGNORE );
  1602.     DevEscape( hdcPrinter, DEVESC_ENDDOC, 0, NULL, &lBytes, NULL );
  1603.     GpiSetBitmap( hpsPrtMem, NULLHANDLE );
  1604.     GpiDeleteBitmap( hbmToPrint );
  1605.  
  1606.     // Release all hdc's and hps's
  1607.  
  1608. Credit:  Rick Fishman 
  1609.  
  1610.  
  1611. ΓòÉΓòÉΓòÉ 8.1.4. How do I do my own Print Screen? ΓòÉΓòÉΓòÉ
  1612.  
  1613. The following code segments are drawn from a much larger system that I manage 
  1614. at work.  The intent is to show how to provide a graphical print screen 
  1615. capability in a PM program.  We install a hook to watch for the print screen 
  1616. key and then take a bit map snapshot of the screen.  This bit map is then sent 
  1617. to the printer. Forgive me if I don't go into all the details about the 
  1618. non-related data structures -- it's late and my mind is a bit foggy. 
  1619.  
  1620. Feel free to use anything here.  Please add some kind of acknowledgement, if 
  1621. you use them as is, like: 
  1622.  
  1623.   "Print routines (c) 1990, 1991 Applied Signal Technology, Inc." 
  1624.  
  1625. Comment, questions, ridicule should be directed to:
  1626.  
  1627.   Jeff Hitchcock
  1628.   CompuServe 71601,260
  1629.  
  1630.   or U.S. Mail to
  1631.  
  1632.   Applied Signal Technology, Inc.
  1633.   470 Spring Park Place, Suite 700
  1634.   Herndon, VA 22070
  1635.  
  1636.   or phone to
  1637.  
  1638.   703/478-5619
  1639.  
  1640. /*****************************************************************************/ 
  1641.  
  1642. 1.  During the WM_CREATE message processing, add the following: 
  1643.  
  1644.    // Set the print screen hook
  1645.  
  1646.    WinSetHook (hab, HMQ_CURRENT, HK_INPUT, (PFN) PrintScreenHook,
  1647.                (HMODULE) NULL);
  1648.  
  1649. /*****************************************************************************/ 
  1650.  
  1651. 2.  Somewhere, have this function: 
  1652.  
  1653. BOOL CALLBACK PrintScreenHook (HAB hab, PQMSG pQmsg, USHORT fs)
  1654. {
  1655.    if ( pQmsg->msg == WM_CHAR )
  1656.       if ( ( SHORT1FROMMP(pQmsg->mp1) & KC_KEYUP) &&
  1657.            ( SHORT1FROMMP(pQmsg->mp1) & KC_VIRTUALKEY ) &&
  1658.            ( SHORT2FROMMP(pQmsg->mp2) == VK_PRINTSCRN) )
  1659.              PrintScreen (hab);
  1660.    return FALSE;
  1661. }
  1662.  
  1663. /*****************************************************************************/ 
  1664.  
  1665. 3.  Here's the "driver:" 
  1666.  
  1667. VOID EXPENTRY PrintScreen (HAB hab)
  1668. {
  1669.     HBITMAP     hbm;
  1670.  
  1671.     hbm = ScreenToBitmap (hab);
  1672.     PrintBitMap(hbm);
  1673. }
  1674.  
  1675. /*****************************************************************************/ 
  1676.  
  1677. 4.  Here's a general print-related structure we use.  We often have many print 
  1678. threads running concurrently, but we only allow one to "run" at a time.  We use 
  1679. a semaphore to show availability of the printer (so to speak), and only one 
  1680. thread at a time gets it.    If we didn't do this, and more than a few print 
  1681. threads are running (especially graphical prints), even a 486/33 with 16 MB of 
  1682. RAM begins to C-R-A-W-L.  So, for what it's worth, these are the structures 
  1683. that we use: 
  1684.  
  1685. /**************************************************************
  1686. *                                                             *
  1687. *   PRINTTHREADPARAMS structure                               *
  1688. *                                                             *
  1689. *   Parameters that are used to manage separate print threads *
  1690. *                                                             *
  1691. *   Item             Contents/Use                             *
  1692. *   --------------   ---------------------------------------- *
  1693. *                                                             *
  1694. *   sJobNumber       Print job number, used for cancelling    *
  1695. *   aiThreadStack    Thread's stack                           *
  1696. *   hwndNotify       Window to which notif. msgs are sent     *
  1697. *   tidPrint         System task id                           *
  1698. *   hssmPrinter...   Semaphore for printer available          *
  1699. *   fSemSet          TRUE if semaphore was made and cleared   *
  1700. *   szSummary        Print summary (e.g., fax printout)       *
  1701. *   fStart           Can't start until TRUE (default FALSE)   *
  1702. *   fContinue        Quit if FALSE (default is TRUE)          *
  1703. *   fHold            Hold if TRUE (default is FALSE)          *
  1704. *   sStartingPage    For multipage, start here                *
  1705. *   sEndingPage      For multipage, end here                  *
  1706. *   usParam          Module-dependent USHORT                  *
  1707. *   ulParam          Module-dependent ULONG                   *
  1708. *   pPrintData       PVOID to the print data                  *
  1709. *                                                             *
  1710. *   PAGESETUP structure                                       *
  1711. *                                                             *
  1712. *   Parameters used to describe the appearance                *
  1713. *                                                             *
  1714. *   Item             Contents/Use                             *
  1715. *   --------------   ---------------------------------------- *
  1716. *                                                             *
  1717. *   szFont           The name of the font to use              *
  1718. *   sLinesPerPage    Used to scale font                       *
  1719. *   sCharsPerLine    Used to scale font                       *
  1720. *   sLeft            Used to position on page, in chars       *
  1721. *   sRight           Used to position on page, in char        *
  1722. *   sTop             Used to position on page, in lines       *
  1723. *   sBottom          Used to position on page, in lines       *
  1724. *   szHeader         Text to place on top of each page        *
  1725. *   fIncludeSummary  If TRUE, include SRI summary on page 1   *
  1726. *   fHeaderEveryPage TRUE for every page, false for pg 1      *
  1727. *   fHeaderUnderline TRUE for underline                       *
  1728. *   szFooter         Text to place at bottom of each page     *
  1729. *   fFooterEveryPage TRUE for every page, false for pg 1      *
  1730. *   fOverlineFooter  TRUE for overline                        *
  1731. *                                                             *
  1732. *   HEADER AND FOOTER OPTIONS:                                *
  1733. *                                                             *
  1734. *   Special Flags that should be supported in each module:    *
  1735. *                                                             *
  1736. *           &l  Left justify                                  *
  1737. *           &c  Center                                        *
  1738. *           &r  Right justify                                 *
  1739. *           &d  Date                                          *
  1740. *           &t  Time                                          *
  1741. *           &p  Page number                                   *
  1742. *                                                            *
  1743. **************************************************************/
  1744.  
  1745. typedef struct
  1746.     {
  1747.     CHAR       szFont[FACESIZE] ;
  1748.     SHORT      sLinesPerPage ;
  1749.     SHORT      sCharsPerLine ;
  1750.     SHORT      sLeft ;
  1751.     SHORT      sRight ;
  1752.     SHORT      sTop ;
  1753.     SHORT      sBottom ;
  1754.     BOOL       fIncludeSummary ;
  1755.     CHAR       szHeader[HEADERFOOTERLENGTH] ;
  1756.     BOOL       fHeaderEveryPage ;
  1757.     BOOL       fUnderlineHeader ;
  1758.     CHAR       szFooter[HEADERFOOTERLENGTH] ;
  1759.     BOOL       fFooterEveryPage ;
  1760.     BOOL       fOverlineFooter ;
  1761.     }
  1762.     PAGESETUP ;
  1763.  
  1764. typedef PAGESETUP FAR *PPAGESETUP ;
  1765.  
  1766. typedef struct
  1767.     {
  1768.     SHORT        sJobNumber ;
  1769.     int          aiThreadStack[STACKSIZE / sizeof (int)] ;
  1770.     HWND         hwndNotify ;
  1771.     HSYSSEM      hssmPrinterAvailable ;
  1772.     BOOL         fSemSet ;
  1773.     CHAR         szSummary[HEADERFOOTERLENGTH] ;
  1774.     BOOL         fStart ;
  1775.     BOOL         fRunning ;
  1776.     BOOL         fContinue ;
  1777.     BOOL         fHold ;
  1778.     SHORT        sStartingPage ;
  1779.     SHORT        sEndingPage ;
  1780.     PAGESETUP    page ;
  1781.     USHORT       usParam ;
  1782.     ULONG        ulParam ;
  1783.     VOID huge    *pPrintData ;
  1784.     }
  1785.     PRINTTHREADPARAMS ;
  1786.  
  1787. typedef PRINTTHREADPARAMS FAR *PPRINTTHREADPARAMS ;
  1788.  
  1789. /*****************************************************************************/ 
  1790.  
  1791. 5.  This function saves the screen display to a bitmap. 
  1792.  
  1793. HBITMAP ScreenToBitmap (HAB hab)
  1794. {
  1795.      BITMAPINFOHEADER bmp ;
  1796.      HBITMAP          hbm ;
  1797.      HDC              hdcMemory ;
  1798.      HPS              hpsScreen, hpsMemory ;
  1799.      LONG             alBitmapFormats [2] ;
  1800.      POINTL           aptl[3] ;
  1801.      SIZEL            sizl ;
  1802.      SHORT            cxScreen;
  1803.      SHORT            cyScreen;
  1804.      BOOL             fMonochrome = FALSE;
  1805.                       // Create memory DC and PS
  1806.  
  1807.      cxScreen = (SHORT) WinQuerySysValue (HWND_DESKTOP, SV_CXSCREEN);
  1808.      cyScreen = (SHORT) WinQuerySysValue (HWND_DESKTOP, SV_CYSCREEN);
  1809.  
  1810.      hdcMemory = DevOpenDC (hab, OD_MEMORY, "*", 0L, NULL, NULL) ;
  1811.  
  1812.      sizl.cx = sizl.cy = 0 ;
  1813.      hpsMemory = GpiCreatePS (hab, hdcMemory, &sizl,
  1814.                               PU_PELS | GPIF_DEFAULT |
  1815.                               GPIT_MICRO | GPIA_ASSOC) ;
  1816.  
  1817.                               // Create bitmap for destination
  1818.  
  1819.      bmp.cbFix = sizeof bmp ;
  1820.  
  1821.      if (fMonochrome)
  1822.      {
  1823.         bmp.cPlanes = 1 ;
  1824.         bmp.cBitCount = 1 ;
  1825.      }
  1826.      else
  1827.      {
  1828.         GpiQueryDeviceBitmapFormats (hpsMemory, 2L, alBitmapFormats) ;
  1829.  
  1830.         bmp.cPlanes = (USHORT) alBitmapFormats[0] ;
  1831.         bmp.cBitCount = (USHORT) alBitmapFormats[1] ;
  1832.      }
  1833.  
  1834.      bmp.cx = cxScreen ;
  1835.      bmp.cy = cyScreen ;
  1836.  
  1837.      hbm = GpiCreateBitmap (hpsMemory, &bmp, 0L, NULL, NULL) ;
  1838.  
  1839.                               // Copy from screen to bitmap
  1840.  
  1841.      if (hbm != NULL)
  1842.      {
  1843.         GpiSetBitmap (hpsMemory, hbm) ;
  1844.         hpsScreen = WinGetScreenPS (HWND_DESKTOP) ;
  1845.  
  1846.         aptl[0].x = 0 ;
  1847.         aptl[0].y = 0 ;
  1848.         aptl[1].x = cxScreen ;
  1849.         aptl[1].y = cyScreen ;
  1850.         aptl[2].x = 0 ;
  1851.         aptl[2].y = 0 ;
  1852.  
  1853.         WinLockVisRegions (HWND_DESKTOP, TRUE) ;
  1854.  
  1855.         GpiBitBlt (hpsMemory, hpsScreen, 3L, aptl,
  1856.                    fMonochrome ? ROP_NOTSRCCOPY : ROP_SRCCOPY, BBO_IGNORE) ;
  1857.  
  1858.         WinLockVisRegions (HWND_DESKTOP, FALSE) ;
  1859.  
  1860.         WinReleasePS (hpsScreen) ;
  1861.         GpiDestroyPS (hpsMemory) ;
  1862.         DevCloseDC (hdcMemory) ;
  1863.      }
  1864.  
  1865.      return hbm ;
  1866. }
  1867.  
  1868. /***************************************************************************** 
  1869.  
  1870. 6.  The "core" function: 
  1871.  
  1872. This function prints a bitmap to the printer.  The bitmap is scaled according 
  1873. to the size of the printer.  No distortion is allowed of the bitmap image. 
  1874.  
  1875. Returns False : if an error occurrs 
  1876. Returns True : no Error occurred 
  1877.  
  1878. Known bug(s): 
  1879.  
  1880. Areas on the screen that have a black foreground and a gray background are 
  1881. completely black when printed.  For example, when a window does not have the 
  1882. focus, it's title bar becomes black lettering on a gray background.  When this 
  1883. window is printed, the entire title bar is black and no title can be read. 
  1884. This is using the Hewlett Packard LaserJet Series II printer. 
  1885.  
  1886. According to MicroSoft online help this is a known bug with the printer device 
  1887. driver.    To fix the bug you must go to the control panel and change the colors 
  1888. of the inactive window. 
  1889.  
  1890. ************************************************************************/
  1891. SHORT  sBitmapToPrinter(PPRINTTHREADPARAMS pptp,
  1892. HPS   hpsPrinter,
  1893. HDC   hdcPrinter,
  1894. HAB   habPrinter,
  1895. SIZEL *psizlPage,
  1896. SIZEL *psizlChar)
  1897. {
  1898.     HDC    hdcPrinterMemory;
  1899.     HPS    hpsPrinterMemory;
  1900.     POINTL ptl;
  1901.     SHORT  sPage = 1;
  1902.     RECTL  rcl;     // Coordinates of region
  1903.  
  1904.     long  lCapsHRes;
  1905.     long  lCapsVRes;
  1906.     float fYAspectRatio;
  1907.     float fXAspectRatio;
  1908.     SIZEL sizl;
  1909.  
  1910.     HBITMAP hbm;
  1911.     POINTL  aptl [4] ;
  1912.     SHORT   cxScreen;
  1913.     SHORT   cyScreen;
  1914.     float   fltScale;
  1915.  
  1916.     // Skip down top margin, ...
  1917.  
  1918.     ptl.x = pptp->page.sLeft * psizlChar->cx ;
  1919.     ptl.y = psizlPage->cy - (pptp->page.sTop * psizlChar->cy) ;
  1920.  
  1921.     // Print header, if requested
  1922.  
  1923.     if (pptp->page.szHeader[0] != '\0')
  1924.     {
  1925.        PrintHeaderFooter (hpsPrinter, &ptl, pptp,
  1926.                           psizlPage, psizlChar,
  1927.                           pptp->page.szHeader,
  1928.                           sPage, PRINT_HEADER) ;
  1929.     }
  1930.  
  1931.     hbm = pptp->pPrintData;
  1932.  
  1933.     // Find the aspect ratio of the printer
  1934.  
  1935.     DevQueryCaps(hdcPrinter,CAPS_HORIZONTAL_RESOLUTION,1L,&lCapsHRes);
  1936.     DevQueryCaps(hdcPrinter,CAPS_VERTICAL_RESOLUTION,1L,&lCapsVRes);
  1937.  
  1938.     if ( (lCapsVRes == 0) || (lCapsHRes == 0) ) {
  1939.        fXAspectRatio = (float) 1;
  1940.        fYAspectRatio = (float) 1;
  1941.     }
  1942.     else {
  1943.        fXAspectRatio = (float) ((float) lCapsVRes / (float) lCapsHRes);
  1944.        fYAspectRatio = (float) ((float) lCapsHRes / (float) lCapsVRes);
  1945.     }
  1946.  
  1947.     // determine coordinates to print on printer
  1948.  
  1949.     rcl.xLeft =  pptp->page.sLeft * psizlChar->cx; // Printer left
  1950.  
  1951.     rcl.xRight = psizlPage->cx -
  1952.                  (pptp->page.sRight * psizlChar->cx); // Printer right
  1953.  
  1954.     rcl.yBottom = (pptp->page.sBottom + 1) * psizlChar->cy; // Printer bottom
  1955.  
  1956.     rcl.yTop = psizlPage->cy -
  1957.               ( (pptp->page.sTop + 1) * psizlChar->cy);     // Printer top
  1958.  
  1959.     cxScreen = (SHORT) WinQuerySysValue (HWND_DESKTOP, SV_CXSCREEN);
  1960.     cyScreen = (SHORT) WinQuerySysValue (HWND_DESKTOP, SV_CYSCREEN);
  1961.  
  1962.     ScaleToWindowSize ((SHORT) (rcl.xRight - rcl.xLeft),   // sXtarget
  1963.                        (SHORT) (rcl.yTop - rcl.yBottom),   // sYTarget
  1964.                        cxScreen,                           // sXSource
  1965.                        cyScreen,                           // sYSource
  1966.                        &fltScale) ;
  1967.  
  1968.     // Create a memory device context
  1969.     // Memory device contexts are used to contain bitmaps
  1970.  
  1971.     hdcPrinterMemory = DevOpenDC (habPrinter, OD_MEMORY, "*", 0L,
  1972.                                   NULL, hdcPrinter);
  1973.  
  1974.     if ( hdcPrinterMemory == DEV_ERROR ) return FALSE;
  1975.  
  1976.     sizl.cx = 0;
  1977.     sizl.cy = 0;
  1978.  
  1979.     // Create a presentation space and associate it the memory device context
  1980.  
  1981.     hpsPrinterMemory = GpiCreatePS (habPrinter, hdcPrinterMemory, &sizl,
  1982.                                     PU_PELS | GPIF_DEFAULT |
  1983.                                     GPIT_NORMAL | GPIA_ASSOC);
  1984.  
  1985.     if( ! hpsPrinterMemory) {
  1986.        DevCloseDC (hdcPrinterMemory);
  1987.        return FALSE;
  1988.     }
  1989.  
  1990.     GpiSetBitmap(hpsPrinterMemory,hbm);
  1991.  
  1992.     aptl [0].x = rcl.xRight - (long) ((float) cxScreen * fltScale);
  1993.     aptl [0].y = rcl.yTop - (long) ((float) cyScreen * fltScale *
  1994.                  fYAspectRatio);
  1995.     aptl [1].x = rcl.xRight;
  1996.     aptl [1].y = rcl.yTop;
  1997.     aptl [2].x = 0;
  1998.     aptl [2].y = 0;
  1999.     aptl [3].x = cxScreen;
  2000.     aptl [3].y = cyScreen;
  2001.  
  2002.     GpiBitBlt(hpsPrinter,hpsPrinterMemory,4L,aptl,ROP_SRCCOPY,BBO_IGNORE);
  2003.  
  2004.     GpiAssociate   (hpsPrinterMemory, NULL) ;
  2005.     GpiDestroyPS   (hpsPrinterMemory);
  2006.     DevCloseDC     (hdcPrinterMemory);
  2007.  
  2008.     // If a footer is defined, ...
  2009.  
  2010.     if (pptp->page.szFooter[0] != '\0')
  2011.     {
  2012.        // ... compute its position ...
  2013.  
  2014.        ptl.x = pptp->page.sLeft * psizlChar->cx ;
  2015.        ptl.y = pptp->page.sBottom * psizlChar->cy ;
  2016.  
  2017.        // ... and print it.
  2018.  
  2019.        PrintHeaderFooter (hpsPrinter, &ptl, pptp,
  2020.                           psizlPage, psizlChar,
  2021.                           pptp->page.szFooter,
  2022.                          sPage, PRINT_FOOTER) ;
  2023.    }
  2024.    return( TRUE);
  2025. }
  2026.  
  2027.  
  2028. ΓòÉΓòÉΓòÉ 8.2. Menus ΓòÉΓòÉΓòÉ
  2029.  
  2030. This section covers Presentation Manager menus. 
  2031.  
  2032.  
  2033. ΓòÉΓòÉΓòÉ 8.2.1. How do I add a menu to a dialog box? ΓòÉΓòÉΓòÉ
  2034.  
  2035. Do a WinLoadMenu and then WM_UPDATEFRAME. 
  2036.  
  2037.  
  2038. ΓòÉΓòÉΓòÉ 8.2.2. How do I make a dynamically changing menu? ΓòÉΓòÉΓòÉ
  2039.  
  2040. Create the menu with all the items that it will ever contain, then dynamically 
  2041. remove and insert the items as required. After loading menu, Query and maintain 
  2042. a copy of the menuitem(s) that will be removed. 
  2043.  
  2044.  // Obtain and keep a copy of the convert submenuitem
  2045.   if (!WinSendMsg (pwd->hwndAB, MM_QUERYITEM,
  2046.       MPFROM2SHORT (IDM_KanCnvMnu, TRUE), MPFROMP (&pwd->miCnvMnu))) {
  2047.  
  2048.   // And the convert submenu text
  2049.   if (!WinSendMsg (pwd->hwndAB, MM_QUERYITEMTEXT,
  2050.     MPFROM2SHORT (IDM_KanCnvMnu, sizeof (pwd->szCnvMnuTxt)),
  2051.                   MPFROMP (&pwd->szCnvMnuTxt)) ){
  2052.  
  2053. When menu is to updated, insert/remove as necessary 
  2054.  
  2055.     // This is layout, is the submenu already in place?
  2056.     if (!pwd->fCnvMenu) {
  2057.  
  2058.       // The submenu is not installed, so insert the submenu
  2059.       WinSendMsg (pwd->hwndAction, MM_INSERTITEM,
  2060.                   MPFROMP (&pwd->miCnvMnu), MPFROMP (pwd->szCnvMnuTxt));
  2061.  
  2062.       // And remove the convert menuitem
  2063.       WinSendMsg (pwd->hwndAB, MM_REMOVEITEM,
  2064.                   MPFROM2SHORT (IDM_KanCnv, TRUE), 0L);
  2065.  
  2066.       // Set the submenu flag
  2067.       pwd->fCnvMenu = TRUE;
  2068.     }
  2069.  
  2070. Credit:  Matthew S. Osborn 
  2071.  
  2072.  
  2073. ΓòÉΓòÉΓòÉ 8.2.3. How do I create a conditional cascade menu? ΓòÉΓòÉΓòÉ
  2074.  
  2075. The following works for me to set a submenu as a conditional-cascade menu, then 
  2076. set it's default id (hwndMenu is the hwnd of the top-level menu): 
  2077.  
  2078.    MENUITEM mi;
  2079.  
  2080.    WinSendMsg( hwndMenu, MM_QUERYITEM,
  2081.                MPFROM2SHORT( idSubMenu, TRUE ), &mi );
  2082.  
  2083.    // Set the MS_CONDITIONALCASCADE bit for the submenu.
  2084.  
  2085.    WinSetWindowBits( mi.hwndSubMenu, QWL_STYLE, MS_CONDITIONALCASCADE,
  2086.                      MS_CONDITIONALCASCADE );
  2087.  
  2088.    // Set cascade menu default
  2089.  
  2090.    WinSendMsg( mi.hwndSubMenu, MM_SETDEFAULTITEMID,
  2091.                MPFROMSHORT( idDefaultItem ), NULL );
  2092.  
  2093. Then I do this to query the default item: 
  2094.  
  2095.  MENUITEM mi;
  2096.  
  2097.  WinSendMsg( hwndMenu, MM_QUERYITEM, MPFROM2SHORT( idSubMenu, TRUE ),
  2098.              &mi );
  2099.  
  2100.  id = (USHORT) WinSendMsg( mi.hwndSubMenu,
  2101.                            MM_QUERYDEFAULTITEMID, NULL, NULL );
  2102.  
  2103. Credit:  Rick Fishman 
  2104.  
  2105.  
  2106. ΓòÉΓòÉΓòÉ 8.2.4. How do I remove a separator from a menu? ΓòÉΓòÉΓòÉ
  2107.  
  2108. Here are two methods of doing that.  The first is from the PMHINTS file, and 
  2109. the second is from Gpf.  PMHINTS takes the approach of removing SC_CLOSE and 
  2110. the nearby separator.  The Gpf solution takes the approach of deleting 
  2111. everything that it doesn't explicitly want.  I've extended it to, among other 
  2112. things, conditionally delete the "Window List" menu item as well. 
  2113.  
  2114. The deletion problems get messier in application menus when there are multiple 
  2115. separaters in different pull-downs.  That is when assigning the separators an 
  2116. id really pays off. 
  2117.  
  2118. Both examples are 16-bit OS/2 1.x code. 
  2119.  
  2120. PMHINTS: 
  2121.  
  2122.  VOID  DelClose(HWND hwnd)
  2123.  {
  2124.    HWND        hSysMenu,
  2125.                hSysSubMenu;
  2126.    MENUITEM    SysMenu;
  2127.    SHORT       idItem,
  2128.                idSep,
  2129.                idSysMenu;
  2130.  
  2131.    hSysMenu = WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT, FALSE),
  2132.                               FID_SYSMENU);
  2133.  
  2134.    idSysMenu = SHORT1FROMMR(WinSendMsg(hSysMenu, MM_ITEMIDFROMPOSITION,
  2135.                             NULL, NULL));
  2136.  
  2137.    WinSendMsg(hSysMenu, MM_QUERYITEM, MPFROM2SHORT(idSysMenu, FALSE),
  2138.               MPFROMP(&SysMenu));
  2139.  
  2140.    hSysSubMenu = SysMenu.hwndSubMenu;
  2141.  
  2142.    idItem = SHORT1FROMMR(WinSendMsg(hSysSubMenu, MM_ITEMPOSITIONFROMID,
  2143.                          MPFROM2SHORT(SC_CLOSE, FALSE), NULL));
  2144.    if (idItem != MIT_ERROR)
  2145.    {
  2146.      idSep = idItem + 1;  // Get separator ID
  2147.  
  2148.      idSep  = SHORT1FROMMR(WinSendMsg(hSysSubMenu, MM_ITEMIDFROMPOSITION,
  2149.                            MPFROMSHORT(idSep), NULL));
  2150.  
  2151.      WinSendMsg(hSysMenu, MM_DELETEITEM, MPFROM2SHORT(SC_CLOSE, TRUE),
  2152.                 MPFROMSHORT(NULL));
  2153.  
  2154.      WinSendMsg(hSysSubMenu, MM_DELETEITEM, MPFROM2SHORT(idSep, FALSE), NULL);
  2155.    }
  2156.  }
  2157.  
  2158. Derived from Gpf, adapted for a client, with some of my changes expurgated (so 
  2159. it won't compile as is): 
  2160.  
  2161.  /*****
  2162.   *
  2163.   *  UtilDlgSysMenu
  2164.   *
  2165.   *      Remove unavailable items from system menu of dialog box.
  2166.   *
  2167.   *  History:
  2168.   *      8/31/92  gts  Adapted from Gpf's GpfSetDialogBoxSysMenu
  2169.   *               with slight modifications.
  2170.   *
  2171.   *****/
  2172.  
  2173.  void _export UtilDlgSysMenu (          /* Remove unwanted system menu items */
  2174.  HWND hwndFrame)                      /* I - Handle to dialog window */
  2175.  {
  2176.     HWND     hwndSubMenu;             /* sys menu pull-down handle  */
  2177.     MENUITEM miTemp;                  /* menu item template         */
  2178.     SHORT    sItemId;                 /* system menu item ID        */
  2179.     SHORT    sItemIndex;              /* system menu item index     */
  2180.     MRESULT  mresult;
  2181.  
  2182.     /********************************************************************/
  2183.     /* Get the handle of the system menu pull-down.            */
  2184.     /********************************************************************/
  2185.     hwndSubMenu = WinWindowFromID( hwndFrame, FID_SYSMENU );
  2186.     WinSendMsg( hwndSubMenu,
  2187.                 MM_QUERYITEM,
  2188.                 MPFROM2SHORT( SC_SYSMENU, FALSE ),
  2189.                 MPFROMP( (PSZ)&miTemp ) );
  2190.     hwndSubMenu = miTemp.hwndSubMenu;
  2191.  
  2192.     /********************************************************************/
  2193.     /* Remove all items from the system menu pull-down that are no    */
  2194.     /* longer wanted.                            */
  2195.     /********************************************************************/
  2196.     mresult = WinSendMsg( hwndSubMenu,
  2197.                          MM_QUERYITEMCOUNT,
  2198.                          MPFROMSHORT(0),
  2199.                          MPFROMSHORT(0) );
  2200.     sItemIndex = SHORT1FROMMR(mresult);
  2201.     for (sItemId = 0; sItemIndex != -1; sItemIndex--)
  2202.     {
  2203.        mresult = WinSendMsg( hwndSubMenu,
  2204.                              MM_ITEMIDFROMPOSITION,
  2205.                              MPFROMSHORT(sItemIndex),
  2206.                              MPFROMSHORT(0) );
  2207.        sItemId = SHORT1FROMMR(mresult);
  2208.        if ( sItemId != MIT_ERROR
  2209.              &&sItemId != SC_MOVE
  2210.              &&sItemId != SC_CLOSE
  2211.              &&(sItemId != SC_TASKMANAGER
  2212.              || (flFlags & MAXONLY)) )   // <- application controls
  2213.        {
  2214.           WinSendMsg( hwndSubMenu,
  2215.                       MM_DELETEITEM,
  2216.                       MPFROM2SHORT(sItemId,FALSE),
  2217.                       MPFROMSHORT(0) );
  2218.        }
  2219.     }
  2220.  }
  2221.  
  2222. Credit:  Guy Scharf 
  2223.  
  2224.  
  2225. ΓòÉΓòÉΓòÉ 8.3. Container Controls ΓòÉΓòÉΓòÉ
  2226.  
  2227. This section covers Presentation Manager container controls. 
  2228.  
  2229.  
  2230. ΓòÉΓòÉΓòÉ 8.3.1. How do I stop a container from flashing every time I add a record? ΓòÉΓòÉΓòÉ
  2231.  
  2232. Disable/Enable the container window before and after the insertion/deletion. 
  2233.  
  2234.  
  2235. ΓòÉΓòÉΓòÉ 8.3.2. How do I get my containers to use Mini-icons? ΓòÉΓòÉΓòÉ
  2236.  
  2237. Here is some sample code that displays mini icons.  First, supply a missing 
  2238. #define: 
  2239.  
  2240.  #ifndef CCS_MINIICONS
  2241.      #define CCS_MINIICONS 0x0800
  2242.  #endif // not CCS_MINIICONS
  2243.  
  2244. Use CCS_MINIICONS as part of your container style (when you create the 
  2245. container).  Now, fill in the RECORDCORE structure pointed to by 'pRecordCore'; 
  2246. 'pUserRecord' also points to 'pRecordCore', which is part of a "user data" 
  2247. structure: 
  2248.  
  2249.  // Fill in fields of container record.
  2250.  #ifdef USE_MINIRECORDCORE
  2251.      pRecordCore->cb = sizeof (MINIRECORDCORE) ;
  2252.  #else
  2253.      pRecordCore->cb = sizeof (RECORDCORE) ;
  2254.  #endif // USE_MINIRECORDCORE
  2255.      pRecordCore->flRecordAttr = 0 ; // CRA_DROPONABLE ;
  2256.      // pRecordCore->ptlIcon is left to zeros.
  2257.      pRecordCore->pszIcon = pUserRecord->szName ;
  2258.      if (*DDirRecord.szIconName)
  2259.         LoadIcon (pUserRecord) ;
  2260.      // pRecordCore->hptrMiniIcon is left to zeros.
  2261.      // pRecordCore->hbmBitmap is left to zeros.
  2262.      // pRecordCore->hbmMiniBitmap is left to zeros.
  2263.      // pRecordCore->pTreeItemDesc is left to zeros.
  2264.  
  2265.  #ifndef USE_MINIRECORDCORE
  2266.      pRecordCore->pszText = pUserRecord->szName ;
  2267.      pRecordCore->pszName = pUserRecord->szName ;
  2268.      pRecordCore->pszTree = pUserRecord->szName ;
  2269.  #endif // not USE_MINIRECORDCORE
  2270.  
  2271. Now, if your user asks for mini-icons (via a popup menu, presumably), you send 
  2272. a CM_SETCNRINFO message to your container, after ORing in the CV_MINI style to 
  2273. CnrInfo.flWindowAttr, or removing it to restore full-size icons.  Hope this 
  2274. helps. 
  2275.  
  2276. Credit:  Wayne Kovsky 
  2277.  
  2278.  
  2279. ΓòÉΓòÉΓòÉ 8.3.3. How do I sort a container control? ΓòÉΓòÉΓòÉ
  2280.  
  2281. /*
  2282.  * Note that PSESSION is my own instance data structure.
  2283.  * I use it here to retrieve the type of field comparison I should do.
  2284.  */
  2285.  
  2286.  static SHORT APIENTRY Compare (PMINIRECORDCORE pmrc1,
  2287.                                 PMINIRECORDCORE pmrc2,
  2288.                                 PVOID pvStorage)
  2289.  {
  2290.     PSESSION pSession = (PSESSION) pvStorage ;
  2291.     PFIELDINFO pFieldInfo = pSession->pFieldInfoSort ;
  2292.     PPVOID pField1 = (PPVOID) ((PBYTE) pmrc1 +
  2293.        pFieldInfo->offStruct) ;
  2294.     PPVOID pField2 = (PPVOID) ((PBYTE) pmrc2 +
  2295.        pFieldInfo->offStruct) ;
  2296.     SHORT sResult = 0 ;
  2297.  
  2298.     if (pFieldInfo->flData & CFA_STRING) {
  2299.        sResult = strcmp ((PCHAR) *pField1, (PCHAR) *pField2) ;
  2300.     }
  2301.     else if (pFieldInfo->flData & CFA_ULONG) {
  2302.        if ((ULONG) *pField1 < (ULONG) *pField2)
  2303.           sResult = -1 ;
  2304.        else if ((ULONG) *pField1 > (ULONG) *pField2)
  2305.           sResult = 1 ;
  2306.        else
  2307.           sResult = 0 ;
  2308.     }
  2309.     else if (pFieldInfo->flData & CFA_DATE) {
  2310.        sResult = CompareDate ((PCDATE) (PVOID) pField1,
  2311.                               (PCDATE) (PVOID) pField2) ;
  2312.     }
  2313.     else if (pFieldInfo->flData & CFA_TIME) {
  2314.        sResult = CompareTime ((PCTIME) (PVOID) pField1,
  2315.                               (PCTIME) (PVOID) pField2) ;
  2316.     }
  2317.  
  2318.     // Any other data type gets treated as equal;
  2319.     // no sorting can be done. Now handle reverse sequence.
  2320.     if (pSession->fSortReverse && sResult)
  2321.        sResult = -sResult ;
  2322.     return sResult ;
  2323.  }
  2324.  
  2325. Here is how I invoke the sort: 
  2326.  
  2327.  // Send container a sort message.
  2328.  ulRC = LONGFROMMR (WinSendMsg (
  2329.                     pSession->hwndContainer,
  2330.                     CM_SORTRECORD,
  2331.                     MPFROMP (Compare), MPFROMP (pSession))) ;
  2332.  if (!ulRC) {
  2333.     // Report error.
  2334.  }
  2335.  
  2336. Credit:  Wayne Kovsky 
  2337.  
  2338.  
  2339. ΓòÉΓòÉΓòÉ 8.3.4. How do I query all records in a container - tree view? ΓòÉΓòÉΓòÉ
  2340.  
  2341. The following code works for querying all records in a tree structure but 
  2342.  
  2343.  USHORT usParentCmd = CMA_FIRST, usChildCmd;
  2344.  PUSERREC purParent = NULL, purChild;
  2345.  
  2346.  for( ; ; )
  2347.  {
  2348.     purParent = (PUSERREC) WinSendMsg( hwndCnr, CM_QUERYRECORD,
  2349.                                        MPFROMP( purParent ),
  2350.                                        MPFROM2SHORT( usParentCmd, CMA_ITEMORDER ) );
  2351.     if( !purParent )
  2352.        break;
  2353.  
  2354.     DoWhatever( purParent );
  2355.  
  2356.     usChildCmd = CMA_FIRSTCHILD;
  2357.     purChild = NULL;
  2358.     for( ; ; )
  2359.     {
  2360.        purChild = (PUSERREC) WinSendMsg( hwndCnr, CM_QUERYRECORD,
  2361.                                          MPFROMP( purChild ),
  2362.                                          MPFROM2SHORT( usChildCmd, CMA_ITEMORDER ));
  2363.        if( !purChild )
  2364.           break;
  2365.  
  2366.        DoWhatever( purChild );
  2367.        usChildCmd = CMA_NEXT;
  2368.     }
  2369.  
  2370.     usCmdParent = CMA_NEXT;
  2371.  }
  2372.  
  2373. Credit:  Rick Fishman 
  2374.  
  2375.  
  2376. ΓòÉΓòÉΓòÉ 8.4. I can't get different colors in text control windows ΓòÉΓòÉΓòÉ
  2377.  
  2378. I've finally got static text control windows (WS_STATIC, SS_TEXT) working with 
  2379. a different color pres. parameter set ! Thanks, Rick, Dan and Wayne. Code as 
  2380. follows: 
  2381.  
  2382.  RGB2 rgb2 ;   // RGB2 structure
  2383.  HWND hwnd ;   // window handle
  2384.  
  2385.  // Set RGB values for a SYSCLR_BACKGROUND (light gray) color
  2386.  rgb2.bred = 204 ;     // Found these in 'WinSetSysColors' API
  2387.  rgb2.bgreen = 204 ;
  2388.  rgb2.bblue = 204 ;
  2389.  rgb2.fcOptions = 0 ;
  2390.  // Set background color
  2391.  WinSetPresParam (hwnd, PP_BACKGROUNDCOLOR, (ULONG) sizeof (RGB2),
  2392.                   &rgb2) ;
  2393.  // Set RGB values for black
  2394.  rgb2.bred = 0 ;
  2395.  rgb2.bgreen = 0 ;
  2396.  rgb2.bblue = 0 ;
  2397.  rgb2.fcOptions = 0 ;
  2398.  // Set text foreground color
  2399.  WinSetPresParam (hwnd, PP_FOREGROUNDCOLOR, (ULONG) sizeof (RGB2),
  2400.                   &rgb2) ;
  2401.  // Set text border color (important for outline fonts)
  2402.  WinSetPresParam (hwnd, PP_BORDERCOLOR, (ULONG) sizeof (RGB2), &rgb2) ;
  2403.  
  2404. Three big caveats here: 
  2405.  
  2406.  1. The OS/2 internal code for static text control windows is *definitely* 
  2407.     using RGB colors, not index colors when it draws the text string. Thus, the 
  2408.     PP_*INDEX presentation parameter values will *not* work. 
  2409.  2. You *must* use a set of colors that are already loaded in the color table. 
  2410.     If the RGB color is not found, the background will be dithered affecting 
  2411.     the text appearance (washed out). If you are not sure the RGB color is 
  2412.     loaded do a GpiQueryNearestColor to get the nearest color. 
  2413.  3. You *must* use the RGB2 structure and *not* the RGB structure. This is 
  2414.     *NOT* documented, but it appears in general that all OS/2 2.0 APIs should 
  2415.     use RGB2 *instead* of RGB. 
  2416.  
  2417. Credit:  Bill Kenning 
  2418.  
  2419.  
  2420. ΓòÉΓòÉΓòÉ 8.5. How can I toggle my titlebar on and off? ΓòÉΓòÉΓòÉ
  2421.  
  2422. Basically, move frame window controls from being children of the frame to being 
  2423. children of the background HWND_OBJECT.  You can then reverse the process to 
  2424. bring them back into view.  Following function implements this code. 
  2425.  
  2426. /* --------------------------------------------------------------
  2427. -- Function:  ToggleFrame
  2428. --
  2429. -- Description:  Toggles frame control visible/invisible
  2430. --
  2431. -- Notes: Code stolen from someone who stole it from an MS sample
  2432. ----------------------------------------------------------------- */
  2433. void ToggleFrame(HWND hwndFrame) {
  2434.  
  2435.  if (! Hidden) {     /* hide contorls */
  2436.     hwndTitle = WinWindowFromID( hwndFrame, FID_TITLEBAR );
  2437.     hwndSys   = WinWindowFromID( hwndFrame, FID_SYSMENU );
  2438.         ... repeat for FID_MINMAX, etc ...
  2439.     WinSetParent(hwndTitle, HWND_OBJECT, FALSE );
  2440.     WinSetParent(hwndSys,   HWND_OBJECT, FALSE );
  2441.         ... repeat for FID_MINMAX, etc ...
  2442.  }
  2443.  else { /* restore controls */
  2444.     WinSetParent( hwndTitle, hwndFrame, FALSE );
  2445.     WinSetParent( hwndSys, hwndFrame, FALSE );
  2446.         ... basically reverse of above ...
  2447.  }
  2448.  WinSendMsg( hwndFrame, WM_UPDATEFRAME,
  2449.       (MPARAM)(FCF_TITLEBAR | FCF_SYSMENU | ...), NULL);
  2450.  SizeTheWindow( hwndFrame );
  2451.  Hidden = ! Hidden;
  2452.  return;
  2453. }
  2454.  
  2455. Credit:  Mike Thompson 
  2456.  
  2457.  
  2458. ΓòÉΓòÉΓòÉ 8.6. How can I get transparent regions in bitmaps? ΓòÉΓòÉΓòÉ
  2459.  
  2460. Currently, you can get the same effect with PM if you use the method used with 
  2461. icons: 
  2462.  
  2463.  1. Use a monochrome mask to prep the destination area. The mask would define 
  2464.     which areas would be transparent and which would show the bitmap. The bits 
  2465.     would be defined as 1=transparent,0=bitmap. You would blit the mask to the 
  2466.     destination using ROP_SRCAND. This would blacken out the area that would 
  2467.     display the non-transparent bits of the bitmap. 
  2468.  2. Now blit the bitmap to the destination using ROP_SRCPAINT. Note that the 
  2469.     "transparent" areas of the bitmap must have the color black (i.e. bits=0). 
  2470.     This ORs the bitmap onto the prep area. Viola - "transparent" bitmap. 
  2471.  
  2472. Credit:  John Webb 
  2473.  
  2474.  
  2475. ΓòÉΓòÉΓòÉ 8.7. How do I create a status bar at the bottom of my window? ΓòÉΓòÉΓòÉ
  2476.  
  2477. You need to intercept several frame messages: 
  2478.  
  2479. WM_CALCFRAMERECT to calculate the new location of the client.  You should send 
  2480. it to the frame superclass then modify the result.  This message is invoked 
  2481. during frame formatting and whenever WinCalcFrameRect is called against your 
  2482. frame window handle. 
  2483.  
  2484. WM_FRAMECTLCOUNT to tell the frame superclass the number of frame controls you 
  2485. expect to format.  If you're adding a status line as a child of the frame 
  2486. (below the client, I suspect), you would add 1 to the result returned by your 
  2487. frame superclass. 
  2488.  
  2489. WM_FORMATFRAME is where you actually position/size the frame controls. The 
  2490. message gives you an array of SWP's.  Call your frame superclass and modify the 
  2491. result (in your case, I would expect only FID_CLIENT and your status line). 
  2492.  
  2493. Sample follows... 
  2494.  
  2495.     /*
  2496.      * FYI, WinDefFrameProc is just a macro I defined to
  2497.      * call my superclass frame window procedure, ie,
  2498.      *    (*vpfnFrameWndProc) (h,m,p1,p2).
  2499.      *
  2500.      * This example splits the client area space 1/3
  2501.      * and 2/3 horizontally with the old client area
  2502.      * and a new sibling.
  2503.      */
  2504.  
  2505.     case WM_CALCFRAMERECT:
  2506.       mr = WinDefFrameProc(hwnd, msg, mp1, mp2);
  2507.  
  2508.       /*
  2509.        * Calculate the position of the client rectangle
  2510.        * Otherwise,  we'll see a lot of redraw when we move the
  2511.        * client during WM_FORMATFRAME.
  2512.        */
  2513.  
  2514.       if (mr && mp2)
  2515.       {
  2516.          prectl = (PRECTL) mp1;
  2517.          prectl->xLeft += ((prectl->xRight - prectl->xLeft) / 3);
  2518.       }
  2519.       break;
  2520.  
  2521.     case WM_FORMATFRAME:
  2522.       sCount = (SHORT) WinDefFrameProc(hwnd, msg, mp1, mp2);
  2523.  
  2524.       /*
  2525.        * Reformat the frame to move the client
  2526.        * over and make room for the his/her sibling.
  2527.        */
  2528.  
  2529.       pswp = (PSWP) mp1;
  2530.       pswpClient = pswp + sCount - 1;
  2531.       pswpNew = pswpClient + 1;
  2532.  
  2533.       *pswpNew = *pswpClient;
  2534.       swpClient = *pswpClient;
  2535.  
  2536.       pswpNew->hwnd = WinWindowFromID(hwnd, ID_SIBLING);
  2537.       pswpNew->cx = pswpClient->cx / 3;
  2538.  
  2539.       pswpClient->x = pswpNew->x + pswpNew->cx - 1;
  2540.       pswpClient->cx = swpClient.cx - pswpNew->cx + 1;
  2541.  
  2542.       sCount++;
  2543.       mr = MRFROMSHORT(sCount);
  2544.       break;
  2545.  
  2546.     case WM_QUERYFRAMECTLCOUNT:
  2547.       sCount = (SHORT) WinDefFrameProc(hwnd, msg, mp1, mp2);
  2548.       sCount++;
  2549.       mr = MRFROMSHORT(sCount);
  2550.       break;
  2551.  
  2552. Credit:  Dan Kehn 
  2553.  
  2554.  
  2555. ΓòÉΓòÉΓòÉ 8.8. How to have a frame/client and still have a std window? ΓòÉΓòÉΓòÉ
  2556.  
  2557.  FRAMECDATA fcdata;
  2558.  
  2559.  fcdata.cb          = sizeof( FRAMECDATA );
  2560.  fcdata.flCreateFlags = FCF_TASKLIST | FCF_MENU, etc.;
  2561.  fcdata.hmodResources = 0; // or the hmod of the DLL containing the resources
  2562.  fcdata.idResources   = ID_RESOURCES;  // ID of the resources, as usual
  2563.  
  2564.  hwndFrame = WinCreateWindow( HWND_DESKTOP, WC_FRAME, NULL, 0, 0, 0, 0, 0,
  2565.                               NULLHANDLE, HWND_TOP, ID_RESOURCES,
  2566.                               &fcdata, NULL);
  2567.  
  2568.  hwndClient = WinCreateWindow( hwndFrame, szClientClass, NULL, 0, 0, 0, 0, 0,
  2569.                                NULLHANDLE, HWND_TOP, FID_CLIENT, NULL, NULL );
  2570.  
  2571.  WinSetWindowPos( hwndFrame, HWND_TOP, x, y, cx, cy,
  2572.                   SWP_ZORDER | SWP_SIZE | SWP_MOVE |
  2573.                   SWP_SHOW | SWP_ACTIVATE );
  2574.  
  2575. If you want to then add new controls, like the system menu, you would do this: 
  2576.  
  2577.  fcdata.flCreateFlags = FCF_SYSMENU;
  2578.  WinCreateFrameControls( hwndFrame, &fcdata, NULL );
  2579.  WinSendMsg( hwndFrame, WM_UPDATEFRAME,
  2580.              MPFROMLONG( FCF_SYSMENU ), NULL );
  2581.  
  2582. The same thing applies to all the other controls like FCF_SIZEBORDER, 
  2583. FCF_TITLEBAR, FCF_HORZSCROLL, FCF_MINMAX, etc. You could also OR more than one 
  2584. together if you wanted to add more than one frame control in the same shot. On 
  2585. the titlebar, you need to also send this message: 
  2586.  
  2587.  WinSendMsg( WinWindowFromID( hwndFrame, FID_TITLEBAR ),
  2588.              TBM_SETHILITE, MPFROMSHORT( TRUE ), NULL );
  2589.  
  2590. If you want to delete frame controls, you would do this (assuming system menu): 
  2591.  
  2592.  WinDestroyWindow( WinWindowFromID( hwndFrame, FID_SYSMENU ) );
  2593.  WinSendMsg( hwndFrame, WM_UPDATEFRAME,
  2594.              MPFROMLONG( FCF_SYSMENU ), NULL );
  2595.  
  2596. Unfortunately this doesn't fit completely well with OOP, since the controls 
  2597. really are not themselves objects independent of the frame window. One of the 
  2598. problems here is that in order to make them independent objects, you need to 
  2599. know the internals of the frame window proc. For instance, you would think that 
  2600. the MIN and MAX are two WC_BUTTON controls, but they are really one menu with 
  2601. two bitmap menuitems (at least in 1.x they were). So if you were to do a 
  2602. WinCreateWindow for either, you'd have to know where to get the bitmaps, and 
  2603. hope that doesn't change. 
  2604.  
  2605. Similarly you'd have to be able to construct the system menu after creating a 
  2606. WC_MENU window. This isn't a tough feat, but if a later version of OS/2 adds a 
  2607. new menu item to the system menu, you'd have to become aware of it. 
  2608.  
  2609. The titlebar and the scrollbars aren't a problem since they have their own 
  2610. public window classes - WC_TITLEBAR and WC_SCROLLBAR respectively. You can, for 
  2611. instance, do a WinCreateWindow( ..., WC_SCROLLBAR,..., FID_HORZSCROLL, ..), 
  2612. then send the frame a WM_UPDATEFRAME message for FCF_HORZSCROLL and this would 
  2613. work. But there is no WC_SIZEBORDER so you couldn't use this method to add the 
  2614. sizing border later. So for the sizing border you need to use the method I 
  2615. first posted above. 
  2616.  
  2617. I spoke too soon about the sizing border. If you want to add or remove it from 
  2618. a frame window, you need to add or remove the FS_SIZEBORDER style from the 
  2619. frame, then send the frame an UPDATEFRAME message for FCF_SIZEBORDER. 
  2620.  
  2621. To change the style, here is a technique that John Webb just turned me on to. 
  2622. To add the style: 
  2623.  
  2624.  WinSetWindowBits( hwndFrame, QWL_STYLE, FS_SIZEBORDER, FS_SIZEBORDER );
  2625.  
  2626. To remove it: 
  2627.  
  2628.  WinSetWindowBits( hwndFrame QWL_STYLE, 0, FS_SIZEBORDER );
  2629.  
  2630. Also, if you want to add or remove just one of the MIN or the MAX, you 
  2631. basically need to get the window handle of the MINMAX menu, then do a 
  2632. MM_REMOVEITEM for the one you want to remove. I did this in 1.x but haven't yet 
  2633. in 2.0. 
  2634.  
  2635. Credit:  Rick Fishman 
  2636.  
  2637.  
  2638. ΓòÉΓòÉΓòÉ 8.9. How do I use printf() in a PM program? ΓòÉΓòÉΓòÉ
  2639.  
  2640. Use PMPRINTF, check your local BBS's, CIS, BIX or cdrom.com or redirect stdout 
  2641. and stderr to files. 
  2642.  
  2643.     // Redirect 'stderr'.
  2644.     (void) freopen ("stderr.txt", "w", stderr) ;
  2645.  
  2646.     // Redirect 'stdout'.
  2647.     (void) freopen ("stdout.txt", "w", stdout) ;
  2648.  
  2649.  
  2650. ΓòÉΓòÉΓòÉ 8.10. I have a SOM DLL. How do I register it? ΓòÉΓòÉΓòÉ
  2651.  
  2652. Here's an example I use for registering.  It checks if the DLL is valid before 
  2653. continuing: 
  2654.  
  2655. #define INCL_WPCLASS
  2656. #define INCL_WIN
  2657. #define INCL_DOS
  2658. #include <os2.h>
  2659. #include <string.h>
  2660. #include <stdio.h>
  2661.  
  2662. int main(int argc, char *argv[]) {
  2663.    HMQ hmq;
  2664.    HAB hab;
  2665.    CHAR szText[256];
  2666.    USHORT usResponse;
  2667.    CHAR szLoadError[128];
  2668.    HMODULE hmod;
  2669.    APIRET rc;
  2670.  
  2671.    if (argc != 3)
  2672.      return 0;
  2673.  
  2674.    hab = WinInitialize(0);
  2675.    hmq = WinCreateMsgQueue(hab, 0);
  2676.  
  2677.    WinDeregisterObjectClass(argv[1]);
  2678.  
  2679.    sprintf(szText, "Register %s DLL '%s'?", argv[1], argv[2]);
  2680.    usResponse = WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szText,
  2681.       "Register WPS Class", 0, MB_YESNO | MB_MOVEABLE | MB_ICONQUESTION);
  2682.  
  2683.    if (usResponse != MBID_YES)
  2684.      return 0;
  2685.  
  2686.    rc = DosLoadModule(szLoadError, sizeof(szLoadError), argv[2], &hmod);
  2687.  
  2688.    if (rc != 0)
  2689.    {
  2690.      sprintf(szText, "Return code = %u, error module = '%s'.",
  2691.              rc, szLoadError);
  2692.      WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szText,
  2693.                    "DosLoadModule Failed", 0,
  2694.                    MB_ENTER | MB_MOVEABLE | MB_ERROR);
  2695.  
  2696.      return 0;
  2697.   }
  2698.  
  2699.  
  2700.   if (WinRegisterObjectClass(argv[1], argv[2]))
  2701.   {
  2702.     if (WinCreateObject(argv[1], argv[1], " ",
  2703.         "<WP_DESKTOP>", CO_REPLACEIFEXISTS))
  2704.       WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, "Created.",argv[1],
  2705.                     0, MB_ENTER | MB_MOVEABLE | MB_INFORMATION);
  2706.     else
  2707.     {
  2708.       DosFreeModule(hmod);
  2709.       WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, "Failed.",argv[1],
  2710.                     0,MB_ENTER | MB_MOVEABLE | MB_ERROR);
  2711.     }
  2712.   }
  2713.   else
  2714.   {
  2715.     DosFreeModule(hmod);
  2716.     WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, "Registration failed.",
  2717.                   argv[1], 0,MB_ENTER | MB_MOVEABLE | MB_ERROR);
  2718.   }
  2719.  
  2720.   return 0; }
  2721.  
  2722. FYI, when WPS registers your DLL with SOM, SOM checks if your DLL has a module 
  2723. entry point called SOMInitModule.  If it does, it is called (most use 
  2724. SOMInitModule for registering DLLs that have more than one class). Otherwise, 
  2725. it checks for YourClassNewClass, and tries to call it (where 'YourClass' is the 
  2726. parameter you specified on the WinRegisterObjectClass). SOM generates 
  2727. 'YourClassNewClass' in the .IH file; if you're still stuck, verify it is being 
  2728. called and that it doesn't fail (eg, because of version number check). 
  2729.  
  2730. I suggest registering with a full DLL filespec, eg, C:\MYSTUFF\MYCAR.DLL. Saves 
  2731. on the length of the LIBPATH. 
  2732.  
  2733. Credit:  Dan Kehn 
  2734.  
  2735.  
  2736. ΓòÉΓòÉΓòÉ 8.11. How do I save and restore my window size and position? ΓòÉΓòÉΓòÉ
  2737.  
  2738. Here is code I use to restore a saved window position, which includes checks to 
  2739. make sure the user hasn't saved a window position at one screen resolution and 
  2740. then restored it at a different screen resolution (which might cause the 
  2741. window's frame controls to be completely off the display -- we've all seen 
  2742. that, right???): 
  2743.  
  2744.  BOOL SetWindowPosition (const HAB hab, const HWND hwndFrame,
  2745.                          const SWP swpConfig)
  2746.  {
  2747.      SWP swp ;
  2748.      APIRET ulRC ;
  2749.  
  2750.      // Initialize the window positioning flags.
  2751.      swp.fl = SWP_ACTIVATE | SWP_MOVE | SWP_SIZE | SWP_SHOW ;
  2752.  
  2753.      /* Check for saved user preferences for screen width/height in
  2754.       * config file.  Did user want to start maximized?
  2755.       */
  2756.      if (swpConfig.fl & SWP_MAXIMIZE)
  2757.      {
  2758.          // Get maximized frame window position and size.
  2759.          ulRC = WinGetMaxPosition (hwndFrame, &swp) ;
  2760.          if (!ulRC)
  2761.          {
  2762.              // Report error, and then ...
  2763.              return TRUE ;
  2764.          }
  2765.          swp.fl |= SWP_MAXIMIZE ;
  2766.      }
  2767.  
  2768.      // Did user want to start minimized?
  2769.      else if (swpConfig.fl & SWP_MINIMIZE)
  2770.      {
  2771.          // Get minimized frame window position and size.
  2772.          ulRC = WinGetMinPosition (hwndFrame, &swp, (PPOINTL) NULL) ;
  2773.          if (!ulRC)
  2774.          {
  2775.              // Report error, and then ...
  2776.              return TRUE ;
  2777.          }
  2778.          swp.fl |= SWP_MINIMIZE ;
  2779.      }
  2780.  
  2781.      // Did user have a saved starting position and size?
  2782.      else if (swpConfig.cy || swpConfig.cx || swpConfig.x || swpConfig.y)
  2783.      {
  2784.          LONG cxClientMax ;
  2785.          LONG cyClientMax ;
  2786.          LONG cyTitleBar ;
  2787.          LONG cxSizeBorder ;
  2788.          LONG cySizeBorder ;
  2789.  
  2790.          // Get maximum client window size.
  2791.          cxClientMax = WinQuerySysValue (HWND_DESKTOP, SV_CXFULLSCREEN) ;
  2792.          cyClientMax = WinQuerySysValue (HWND_DESKTOP, SV_CYFULLSCREEN) ;
  2793.          cyTitleBar = WinQuerySysValue (HWND_DESKTOP, SV_CYTITLEBAR) ;
  2794.          cxSizeBorder = WinQuerySysValue (HWND_DESKTOP, SV_CXSIZEBORDER) ;
  2795.          cySizeBorder = WinQuerySysValue (HWND_DESKTOP, SV_CYSIZEBORDER) ;
  2796.  
  2797.          // Maximum client window size excludes title bar.
  2798.          cyClientMax += cyTitleBar ;
  2799.  
  2800.          // Make sure x origin is within display boundaries.
  2801.          swp.x = swpConfig.x ;
  2802.          if (swp.x < -cxSizeBorder)
  2803.              swp.x = 0 ;
  2804.  
  2805.          // Make sure window isn't too wide, or negative value.
  2806.          swp.cx = swpConfig.cx ;
  2807.          if (swp.cx >= cxClientMax || swp.cx < 0)
  2808.          {
  2809.              swp.cx = cxClientMax ;
  2810.              swp.x = 0 ;
  2811.          }
  2812.  
  2813.           if ((swp.x + swp.cx) > (cxClientMax + cxSizeBorder))
  2814.              swp.x = cxClientMax + cxSizeBorder - swp.cx ;
  2815.  
  2816.          // Make sure y origin is within display boundaries.
  2817.          swp.y = swpConfig.y ;
  2818.          if (swp.y < -cySizeBorder)
  2819.              swp.y = 0 ;
  2820.  
  2821.          // Make sure window isn't too high, or negative value.
  2822.          swp.cy = swpConfig.cy ;
  2823.          if (swp.cy > cyClientMax || swp.cy < 0)
  2824.          {
  2825.              swp.cy = cyClientMax ;
  2826.              swp.y = 0 ;
  2827.          }
  2828.  
  2829.          if ((swp.y + swp.cy) > (cyClientMax + cySizeBorder))
  2830.              swp.y = cyClientMax + cySizeBorder - swp.cy ;
  2831.      }
  2832.  
  2833.      // No saved position -- move window to FCF_SHELLPOSITION location.
  2834.      else
  2835.      {
  2836.          // Get default window size and position.
  2837.          ulRC = WinQueryTaskSizePos (hab, 0, &swp) ;
  2838.          if (ulRC)
  2839.          {
  2840.              // Report error, and then ...
  2841.              return TRUE ;
  2842.          }
  2843.          swp.fl = SWP_ACTIVATE | SWP_MOVE | SWP_SIZE | SWP_SHOW ;
  2844.      }
  2845.  
  2846.      // Position and size this frame window.
  2847.      ulRC = WinSetWindowPos (hwndFrame, HWND_TOP,
  2848.        swp.x, swp.y, swp.cx, swp.cy, swp.fl) ;
  2849.      if (!ulRC)
  2850.      {
  2851.          // Report error, and then ...
  2852.          return TRUE ;
  2853.      }
  2854.  
  2855.      return FALSE ;
  2856.  }
  2857.  
  2858. Credit:  Wayne Kovsky 
  2859.  
  2860.  
  2861. ΓòÉΓòÉΓòÉ 8.12. How do you make a window float above all others? ΓòÉΓòÉΓòÉ
  2862.  
  2863. OK.  Here's a sample program showing floating windows (derived from dvipm). 
  2864. The advantages over the WM_TIMER approach [which was presented in v2.2 -ed] 
  2865. are: 
  2866.  
  2867. o there's no delay 
  2868. o repainting is minimized 
  2869. o avoids timing problems 
  2870. o the floating windows are not unconditionally moved to the very top (that is, 
  2871.   when moving the base window B (with floating window F) behind a window W, the 
  2872.   order of the windows is this: BFW, not BWF!) 
  2873.  
  2874. The excessive repainting caused by other solutions was quite annoying with 
  2875. dvipm as recomputing the dvipm status window is slow. 
  2876.  
  2877. Eberhard 
  2878.  
  2879. /* floatwin.c */
  2880.  
  2881. /* This program shows how to implement floating windows.  The source
  2882.    code works with both 16-bit and 32-bit C compilers.
  2883.  
  2884.    If the Z-order of the base window is changed, the floating window
  2885.    will be moved on top of the base window.
  2886.  
  2887.    Generalizing this approach to many windows floating on many windows
  2888.    (floating on many windows ...) is left as exercise. */
  2889.  
  2890. #define INCL_WIN
  2891. #define INCL_GPI
  2892. #include <os2.h>
  2893.  
  2894. /* Syntactic sugar for supporting both 16-bit and 32-bit compilers. */
  2895.  
  2896. #ifdef __32BIT__
  2897. #define MSG ULONG
  2898. #define FLAGS fl
  2899. #else
  2900. #define MSG USHORT
  2901. #define FLAGS fs
  2902. #endif
  2903. #ifndef NULLHANDLE
  2904. #define NULLHANDLE NULL
  2905. #endif
  2906.  
  2907. /* The original frame window procedure. */
  2908. static PFNWP pfOldBaseFrameProc = NULL;
  2909.  
  2910. /* The handle of the floating window. */
  2911. static HWND hwndFloat = NULLHANDLE;
  2912.  
  2913. /* This frame window procedure is used for subclassing base windows.
  2914.    When changing the Z-order of the frame window, the floating window
  2915.    is moved instead of the base window and the hwndInsertBehind field
  2916.    is modified to move the base window behind the floating window. */
  2917.  
  2918. MRESULT EXPENTRY
  2919. BaseFrameProc (HWND hwnd, MSG msg, MPARAM mp1, MPARAM mp2)
  2920. {
  2921.   PSWP pswp;
  2922.  
  2923.   switch (msg)
  2924.     {
  2925.     case WM_ADJUSTWINDOWPOS:
  2926.       pswp = PVOIDFROMMP (mp1);
  2927.       if ((pswp->FLAGS & SWP_ZORDER) && hwndFloat != NULLHANDLE
  2928.            && WinIsWindowVisible (hwndFloat))
  2929.         {
  2930.           WinSetWindowPos (hwndFloat, pswp->hwndInsertBehind,
  2931.                            0, 0, 0, 0, SWP_ZORDER);
  2932.           /* This is the trick! */
  2933.           pswp->hwndInsertBehind = hwndFloat;
  2934.         }
  2935.       break;
  2936.     }
  2937.   return pfOldBaseFrameProc (hwnd, msg, mp1, mp2);
  2938. }
  2939.  
  2940.  
  2941. /* Common client window procedure for base windows and floating
  2942.    windows.  Display TXT and use CLR for filling the background. */
  2943.  
  2944. MRESULT CommonClientWndProc (HWND hwnd, MSG msg, MPARAM mp1, MPARAM mp2,
  2945.                              PCH txt, COLOR clr)
  2946. {
  2947.   HPS hps;
  2948.   RECTL rcl;
  2949.  
  2950.   switch (msg)
  2951.     {
  2952.     case WM_PAINT:
  2953.       hps = WinBeginPaint (hwnd, 0L, 0L);
  2954.       WinQueryWindowRect (hwnd, &rcl);
  2955.       GpiSetColor (hps, CLR_DARKCYAN);
  2956.       GpiSetBackColor (hps, clr);
  2957.       WinDrawText (hps, -1, txt, &rcl, 0, 0,
  2958.                    DT_TEXTATTRS | DT_CENTER | DT_VCENTER | DT_ERASERECT);
  2959.       WinEndPaint (hps);
  2960.       return 0;
  2961.     }
  2962.   return WinDefWindowProc (hwnd, msg, mp1, mp2);
  2963. }
  2964.  
  2965.  
  2966. /* Client window procedure for floating windows. */
  2967.  
  2968. MRESULT EXPENTRY FloatClientWndProc (HWND hwnd, MSG msg, MPARAM mp1, MPARAM mp2)
  2969. {
  2970.   return CommonClientWndProc (hwnd, msg, mp1, mp2, "Floating Window", CLR_RED);
  2971. }
  2972.  
  2973. /* Client window procedure for base windows. */
  2974.  
  2975. MRESULT EXPENTRY BaseClientWndProc (HWND hwnd, MSG msg, MPARAM mp1, MPARAM mp2)
  2976. {
  2977.   return CommonClientWndProc (hwnd, msg, mp1, mp2, "Base Window", CLR_YELLOW);
  2978. }
  2979.  
  2980.  
  2981. /* Start here. */
  2982.  
  2983. int main (void)
  2984. {
  2985.   static char szBaseClientClass[] = "floatwin.base";
  2986.   static char szFloatClientClass[] = "floatwin.float";
  2987.   ULONG flFrameFlags;
  2988.   HAB hab;
  2989.   HMQ hmq;
  2990.   QMSG qmsg;
  2991.   HWND hwndBase;
  2992.  
  2993.   /* Initialize Presentation Manager. */
  2994.  
  2995.   hab = WinInitialize (0);
  2996.   hmq = WinCreateMsgQueue (hab, 0);
  2997.  
  2998.   /* Create client window classes. */
  2999.  
  3000.   WinRegisterClass (hab, szBaseClientClass, BaseClientWndProc,
  3001.                     CS_SIZEREDRAW, 0);
  3002.   WinRegisterClass (hab, szFloatClientClass, FloatClientWndProc,
  3003.                     CS_SIZEREDRAW, 0);
  3004.  
  3005.   /* Create the base window and the floating window.  Note: the
  3006.      windows are initially invisible. */
  3007.  
  3008.   flFrameFlags = (FCF_TITLEBAR      | FCF_SYSMENU |
  3009.                   FCF_SIZEBORDER    | FCF_MINMAX  |
  3010.                   FCF_TASKLIST);
  3011.  
  3012.   /* Create and subclass the base window. */
  3013.  
  3014.   hwndBase = WinCreateStdWindow (HWND_DESKTOP, 0,
  3015.                                  &flFrameFlags, szBaseClientClass,
  3016.                                  "floatwin - Base Window",
  3017.                                  0L, 0, 1, NULL);
  3018.   pfOldBaseFrameProc = WinSubclassWindow (hwndBase, BaseFrameProc);
  3019.  
  3020.   /* Create the floating window. */
  3021.  
  3022.   hwndFloat = WinCreateStdWindow (HWND_DESKTOP, 0,
  3023.                                   &flFrameFlags, szFloatClientClass,
  3024.                                   "floatwin - Floating Window",
  3025.                                   0L, 0, 1, NULL);
  3026.  
  3027.   /* Set the position, size and Z-order of the windows and make them
  3028.      visible.  It's important to use SWP_ZORDER for the base
  3029.      window. */
  3030.  
  3031.   WinSetWindowPos (hwndFloat, HWND_TOP, 10, 10, 300, 80,
  3032.                    SWP_SHOW | SWP_MOVE | SWP_SIZE | SWP_ZORDER);
  3033.   WinSetWindowPos (hwndBase, HWND_TOP, 100, 50, 300, 80,
  3034.                    SWP_SHOW | SWP_MOVE | SWP_SIZE | SWP_ZORDER | SWP_ACTIVATE);
  3035.  
  3036.   /* The message loop. */
  3037.  
  3038.   while (WinGetMsg (hab, &qmsg, 0L, 0, 0))
  3039.     WinDispatchMsg (hab, &qmsg);
  3040.  
  3041.   /* Clean up. */
  3042.  
  3043.   WinDestroyWindow (hwndBase);
  3044.   WinDestroyWindow (hwndFloat);
  3045.   WinDestroyMsgQueue (hmq);
  3046.   WinTerminate (hab);
  3047.  
  3048.   return 0;
  3049. }
  3050.  
  3051.  
  3052. ΓòÉΓòÉΓòÉ 8.13. How to ensure the sizing's correct so the dlg "fits" in the notebook...? ΓòÉΓòÉΓòÉ
  3053.  
  3054. Override wpclsQuerySettingsPageSize (or some such verbage, I don't have docs at 
  3055. home).  I don't know if this API made it into the on-line docs, but it is 
  3056. definitely public (see \TOOLKT20\C\OS2H\WPOBJECT.H). There you are given the 
  3057. opportunity to adjust the size up to accomodate your dialog, if necessary. 
  3058.  
  3059. The PAGEINFO structure is used by the Settings page code to delay the loading 
  3060. of the dialog required for a page until the user turns to it for the first 
  3061. time.  It has the resource ID, module handle (which is incorrectly named in the 
  3062. structure, 'resid' or some nonsense, grr-r), dialog procedure, and pointer of 
  3063. your choice to receive on WM_INITDLG (most choose the object pointer, somSelf). 
  3064. When the user selects the notebook tab, WPS calls WinLoadDlg based on the 
  3065. parameters in PAGEINFO. 
  3066.  
  3067.  
  3068. ΓòÉΓòÉΓòÉ 8.14. How do I prevent Shutdown from stopping my app? ΓòÉΓòÉΓòÉ
  3069.  
  3070. In our application, the WM_CLOSE message processor determines the state of the 
  3071. application, issues all the "Are you sure?" questions, etc. If the close is to 
  3072. be continued, a WM_QUIT message is posted and a value of FALSE is returned. 
  3073. Otherwise a value of TRUE is returned. 
  3074.  
  3075. The window receiving the WMU_EndTask message handles it by posting a WM_CLOSE 
  3076. message to itself, and letting the WM_CLOSE processing handle it. The only 
  3077. reason it is not translated to a WM_CLOSE within the message loop is allow 
  3078. future use. This message requires no special handling. 
  3079.  
  3080. The window receiving the WMU_ShutDown message handles it by sending (not 
  3081. posting) a WM_CLOSE message to itself. If the WM_CLOSE message returns TRUE, 
  3082. then a WinCancelShutdown (hmq, FALSE) call is issued to cancel this instance of 
  3083. the shutdown. 
  3084.  
  3085. If you issue a WinCancelShutdown (hmq, TRUE), a WM_QUIT message will never be 
  3086. sent to your message queue, so will not have an opportunity to stop the 
  3087. shutdown.  This is intended for secondary message queues that do not have a 
  3088. message loop. 
  3089.  
  3090.   while (1) {
  3091.  
  3092.     HWND hwndClient;
  3093.  
  3094.     // Get next message from queue
  3095.     if (!WinGetMsg (hab, &qmsg, NULLHANDLE, 0, 0)) {
  3096.  
  3097.       // The WM_QUIT message has three sources:
  3098.       //   1. The task manager 'End task' pulldown
  3099.       //   2. System shutdown from desktop manager
  3100.       //   3. Posted by the application
  3101.  
  3102.       // This is a WM_QUIT message.  Check the window handle, if the
  3103.       // handle matches mp2, it is from switch list close
  3104.       if (qmsg.hwnd == HWNDFROMMP (qmsg.mp2)) {
  3105.  
  3106.         // This is from close on the task list, convert to our message
  3107.         qmsg.msg = WMU_EndTask;
  3108.  
  3109.         // Get the intended client's window handle
  3110.         if (!(hwndClient = WinWindowFromID (qmsg.hwnd, FID_CLIENT))) {
  3111.  
  3112.           // Failed to find client. No idea who this belongs to,
  3113.           // give it to default window for processing
  3114.           hwndClient = hwndDefault
  3115.         }
  3116.  
  3117.         // Otherwise, readdress the message to the appropriate client
  3118.         qmsg.hwnd = hwndClient;
  3119.  
  3120.         // We can use mp1 and mp2 for anything we want.
  3121.         // Currently, just clear both
  3122.         qmsg.mp1  = qmsg.mp2 = 0L;
  3123.  
  3124.       } else if (qmsg.hwnd == NULLHANDLE) {
  3125.  
  3126.         // This message is from shutdown,
  3127.         // Address it to default window for processing
  3128.         qmsg.hwnd = hwndDefault;
  3129.  
  3130.         // And set the message to our shutdown message,
  3131.         qmsg.msg = WMU_SysShutdown;
  3132.  
  3133.       } else {
  3134.  
  3135.         // If here, we posted the WM_QUIT message, so break out of
  3136.         // the message loop
  3137.         break;
  3138.       }
  3139.     }
  3140.  
  3141.     // This is not a WM_QUIT message, intercept all other
  3142.     // messages intended for the NULL window
  3143.     if (qmsg.hwnd == NULLHANDLE) {
  3144.  
  3145.       // Pass all NULL window messages to the NULL window handler
  3146.       NullMsg (qmsg.hwnd, qmsg.msg, qmsg.mp1, qmsg.mp2);
  3147.  
  3148.     } else {
  3149.  
  3150.       // This is not a WM_QUIT message, nor is it intended for the NULL
  3151.       // window.  Pass this message to the message filter hook for
  3152.       // processing.
  3153.       if (!WinCallMsgFilter (hab, (PQMSG) &qmsg, 0)) {
  3154.  
  3155.         // Filter hook has not cancelled the message, so dispatch
  3156.         // the message to the proper window
  3157.         WinDispatchMsg (hab, &qmsg);
  3158.       }
  3159.     }
  3160.   }
  3161.  
  3162. Credit:  Matt Osborn 
  3163.  
  3164.  
  3165. ΓòÉΓòÉΓòÉ 8.15. When I pass a structure to WinCreateWindow, sometimes it doesn't work! ΓòÉΓòÉΓòÉ
  3166.  
  3167. Put the size of the structure as the first word. 
  3168.  
  3169.  
  3170. ΓòÉΓòÉΓòÉ 8.16. How do I use type filtering in 2.0's open dlg? ΓòÉΓòÉΓòÉ
  3171.  
  3172. It's broken in 2.0GA, fixed in 2.0's service pak. 
  3173.  
  3174.  
  3175. ΓòÉΓòÉΓòÉ 8.17. When minimizing, my dialog box is overwriting my icon! ΓòÉΓòÉΓòÉ
  3176.  
  3177. In the WM_MINMAXFRAME message hide the offending control. 
  3178.  
  3179.     case WM_MINMAXFRAME:
  3180.       {
  3181.         PSWP pswp; /* pos change structure */
  3182.  
  3183.         /* hide list box when minimized so it doesn't overwrite icon */
  3184.         pswp = PVOIDFROMMP( mp1 );
  3185.         WinShowWindow(
  3186.           WinWindowFromID( hwnd, IDD_FILES ),
  3187.           !(pswp->fs & SWP_MINIMIZE)
  3188.         );
  3189.       }
  3190.       break;
  3191.  
  3192.  
  3193. ΓòÉΓòÉΓòÉ 8.18. How do I make a multi-column listbox? ΓòÉΓòÉΓòÉ
  3194.  
  3195. Use the container in details view.  If you just have to use a list box: 
  3196.  
  3197. Here is an extract from my dialog box procedure that produces a two-column list 
  3198. box. 
  3199.  
  3200. In this example there is only one list box, so I don't have to worry about 
  3201. which control is involved.  In this example, a blank is used to separate the 
  3202. first and second column.  You could use tabs or any other sort of separator 
  3203. character.  You could also draw anything you wanted in the list box item, 
  3204. including bit maps, colors, other fonts, etc. 
  3205.  
  3206. This is not a complete program, of course, but does show the details of 
  3207. handling a multi-column list box. 
  3208.  
  3209. /******************** Dialog Box Procedure ******************************/
  3210.  
  3211. MRESULT EXPENTRY SelectDlgProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  3212. {
  3213.     HPS     hPS;                 /* Handle to the presentation space */
  3214.     FONTMETRICS FontMetrics;     /* Metrics of default font */
  3215.     CHAR    pszItemText[MAX_ITEM_TEXT_LENGTH];
  3216.     CHAR    *s;
  3217.     OWNERITEM FAR *poi;          /* Pointer to owner item structure */
  3218.     RECTL   rcl;                 /* Rectangle for writing */
  3219.     COLOR   clrForeGround;
  3220.     COLOR   clrBackGround;
  3221.  
  3222.     switch (msg)
  3223.         {
  3224.         case WM_INITDLG:   /* Initialize the list box */
  3225.  
  3226.             FillCfgListBox (hwnd);     /* Fill the list box */
  3227.  
  3228.             return (FALSE);
  3229.  
  3230.  
  3231.         case WM_MEASUREITEM:     /* Measure text height */
  3232.  
  3233.             hPS = WinGetPS (hwnd);     /* Get handle to presentation space */
  3234.             GpiQueryFontMetrics (hPS, (LONG) sizeof (FONTMETRICS),
  3235.                                  &FontMetrics);
  3236.             WinReleasePS (hPS);        /* Release the presentation space */
  3237.  
  3238.             return (FontMetrics.lMaxBaselineExt);
  3239.  
  3240.  
  3241.         case WM_DRAWITEM:      /* Draw a list box entry */
  3242.  
  3243.             poi = mp2;               /* Get address of owner item */
  3244.  
  3245.             if (poi->fsState == TRUE)  /* Is this cell to be highlighted? */
  3246.             {                          /* Yes, use highlight attributes */
  3247.                 clrForeGround = SYSCLR_HILITEFOREGROUND;
  3248.                 clrBackGround = SYSCLR_HILITEBACKGROUND;
  3249.             }
  3250.             else                       /* No, use normal attributes */
  3251.             {
  3252.                 clrForeGround = CLR_NEUTRAL;
  3253.                 clrBackGround = CLR_BACKGROUND;
  3254.             }
  3255.  
  3256.             WinSendMsg (poi->hwnd,     /* Get item text */
  3257.                         LM_QUERYITEMTEXT,
  3258.                         (MPARAM) MAKEULONG (poi->idItem,
  3259.                         MAX_ITEM_TEXT_LENGTH),
  3260.                         (MPARAM) pszItemText);
  3261.  
  3262.             rcl.xLeft    = poi->rclItem.xLeft;  /* Set co-ordinates */
  3263.             rcl.xRight    = poi->rclItem.xRight; /* of rectangle */
  3264.             rcl.yTop    = poi->rclItem.yTop;
  3265.             rcl.yBottom = poi->rclItem.yBottom;
  3266.  
  3267.             s = strchr (pszItemText, ' ');  /* Find first blank */
  3268.             if (s)
  3269.               *s = '\0';               /* Terminate first column here */
  3270.  
  3271.             WinDrawText (poi->hps,     /* Draw the first column */
  3272.                          -1,           /* Null-terminated string */
  3273.                          pszItemText,  /* File name is here */
  3274.                          &rcl,     /* Rectangle to draw in */
  3275.                          clrForeGround,/* Foreground color */
  3276.                          clrBackGround,/* Background color */
  3277.                          DT_LEFT | DT_VCENTER | DT_ERASERECT);
  3278.  
  3279.             if (s)               /* If there is a second column */
  3280.             {
  3281.               rcl.xLeft = 100;         /* It starts out here */
  3282.                                        /* Spacing calculations could be */
  3283.                                        /* much cleverer than this very */
  3284.                                        /* crude use of an absolute position */
  3285.                                        /* (which is not transportable */
  3286.                                        /* to different display types, as */
  3287.                                        /* between 8514 and VGA) */
  3288.                 s++;                   /* Point to beginning of text */
  3289.                 WinDrawText (poi->hps, /* Draw the second column */
  3290.                              -1,       /* Also a null-terminated string */
  3291.                              s,        /* File Description */
  3292.                              &rcl, /* Rectangle to draw in */
  3293.                              clrForeGround,  /* Colors are same as */
  3294.                              clrBackGround,  /* before */
  3295.                              DT_LEFT | DT_VCENTER);
  3296.             }
  3297.  
  3298.                 /* If fsState || fsStateOld and return TRUE, then */
  3299.                 /* control will invert the rectangle -- not what */
  3300.                 /* we want.  Tell control not do do anything like that! */
  3301.  
  3302.             poi->fsState = poi->fsStateOld = FALSE;
  3303.  
  3304.             return (TRUE); /* Say we did it */
  3305.  
  3306. ... case statements for rest of program ...
  3307.  
  3308. Credit:  Guy Scharf 
  3309.  
  3310.  
  3311. ΓòÉΓòÉΓòÉ 8.19. How do I create my own Master Help Index? ΓòÉΓòÉΓòÉ
  3312.  
  3313. I talked with the owner of the Master Index, and she said there is no problem 
  3314. with using a like index to view online documentation for your application. 
  3315. There are just a few catches: 
  3316.  
  3317.  1. The documentation must be compiled as an .HLP file and not an .INF file. 
  3318.     Note that this is the default for IPFC. 
  3319.  
  3320.  2. The tagged indexed entries must have the "global" attribute. For example: 
  3321.  
  3322.    :i1 global.giving examples 
  3323.  
  3324.    or: 
  3325.  
  3326.    :i1 id=examp global.giving examples 
  3327.  
  3328.  3. The Index executable is a WPS object, not a standalone application. You 
  3329.     will need to create your own copy of the object (instance) of class Mindex, 
  3330.     either by using a REXX script  (e.g. SysCreateObject()) or within your app 
  3331.     (e.g. WinCreateObject()). 
  3332.  
  3333.     For a REXX example: 
  3334.  
  3335.             CALL   SysCreateObject  "Mindex", "Title", "<WP_DESKTOP>",
  3336.                                     "INDEX=MYFILE;OBJECTID=<MY_INDEX>"
  3337.  
  3338.     where MYFILE can be an environmental variable set to the path or filespec 
  3339.     of your .HLP files, or it can be the actual filespec itself (e.g. 
  3340.     INDEX=c:\myapp\myfile.hlp ). Note too that files can be concatenated (e.g. 
  3341.     INDEX=c:\myapp\myfile.hlp+c:\yourapp\yourfile.hlp). 
  3342.  
  3343.  4. Objects of Mindex class CAN NOT be subclassed. There are no public methods 
  3344.     in this class and it must be used as is. 
  3345.  
  3346. Credit:  John Webb 
  3347.  
  3348.  
  3349. ΓòÉΓòÉΓòÉ 8.20. How do I change the font in an MLE? ΓòÉΓòÉΓòÉ
  3350.  
  3351. How do I change the font in an MLE?  WinSetPresParms doesn't work. 
  3352.  
  3353. This is a function I used in 1.x to set the font for an MLE (haven't ported it 
  3354. yet but it should be the same). I pass it the parent hwnd of the MLE, the MLE's 
  3355. id, a facename, a pointsize, the maximum height for an outline font, and 
  3356. fsSelection (FATTR_SEL_BOLD, etc). It first tries to match on pointsize and 
  3357. facename. If it can't it uses an outline font with the height requested. 
  3358.  
  3359.  VOID EXPENTRY UtlSetMleFont( HWND hwndParent, USHORT usMleId, PSZ szFacename,
  3360.                               USHORT usPointSize, LONG lMaxHeight,
  3361.                               USHORT fsSelection )
  3362.  {
  3363.      PFONTMETRICS pfm;
  3364.      HDC          hdc;
  3365.      HPS          hps;
  3366.      HWND         hwndMle;
  3367.      LONG         lHorzRes, lVertRes, lRequestFonts = 0, lNumberFonts;
  3368.      FATTRS       fat;
  3369.      SHORT        sOutlineIndex = -1;
  3370.      INT          i;
  3371.  
  3372.      (void) memset( &fat, 0, sizeof( FATTRS ) );
  3373.      fat.usRecordLength  = sizeof( FATTRS );
  3374.      fat.fsSelection     = fsSelection;
  3375.      strcpy( fat.szFacename, szFacename );
  3376.      hwndMle = WinWindowFromID( hwndParent, usMleId );
  3377.      hps = WinGetPS( hwndMle );
  3378.      hdc = GpiQueryDevice( hps );
  3379.      DevQueryCaps( hdc, CAPS_HORIZONTAL_FONT_RES, 1L, &lHorzRes );
  3380.      DevQueryCaps( hdc, CAPS_VERTICAL_FONT_RES,   1L, &lVertRes );
  3381.      lNumberFonts = GpiQueryFonts( hps, QF_PUBLIC, szFacename,
  3382.                                    &lRequestFonts, 0L, NULL);
  3383.      pfm = malloc( (SHORT) lNumberFonts * sizeof( FONTMETRICS ) );
  3384.      GpiQueryFonts( hps, QF_PUBLIC, szFacename,
  3385.                     &lNumberFonts, (LONG) sizeof( FONTMETRICS ), pfm );
  3386.      for( i = 0; i < (USHORT) lNumberFonts; i++ )
  3387.      {
  3388.          if( pfm[ i ].fsDefn & 1 )
  3389.          {
  3390.              sOutlineIndex = (SHORT) i;
  3391.              continue;
  3392.          }
  3393.  
  3394.          if (pfm[ i ].sXDeviceRes == (SHORT) lHorzRes &&
  3395.              pfm[ i ].sYDeviceRes == (SHORT) lVertRes &&
  3396.              pfm[ i ].sNominalPointSize == (SHORT) (usPointSize * 10) )
  3397.          {
  3398.              fat.lMatch          = pfm[ i ].lMatch;
  3399.              fat.lMaxBaselineExt = pfm[ i ].lMaxBaselineExt;
  3400.              fat.lAveCharWidth   = pfm[ i ].lAveCharWidth;
  3401.              break;
  3402.          }
  3403.      }
  3404.  
  3405.      if( i >= (USHORT) lNumberFonts )
  3406.          if( sOutlineIndex >= 0 )
  3407.              if( lMaxHeight )
  3408.              {
  3409.                  fat.fsFontUse = FATTR_FONTUSE_OUTLINE;
  3410.                  if( !(fat.usCodePage = pfm[ sOutlineIndex ].usCodePage) )
  3411.                      fat.usCodePage  = 850;
  3412.                  fat.lMaxBaselineExt = lMaxHeight;
  3413.                  WinSendMsg( hwndMle, MLM_SETFONT, MPFROMP( &fat ), 0 );
  3414.              }
  3415.      WinSendMsg( hwndMle, MLM_SETFONT, MPFROMP( &fat ), 0 );
  3416.      WinReleasePS( hps );
  3417.      free( pfm );
  3418.  }
  3419.  
  3420. Credit:  Rick Fishman 
  3421.  
  3422.  
  3423. ΓòÉΓòÉΓòÉ 8.21. Why can't I import files larger than 64KB into my MLE? ΓòÉΓòÉΓòÉ
  3424.  
  3425. A MLE can not import or export text in bigger chunks than 64K. The below code 
  3426. shows how to solve this. 
  3427.  
  3428. void Editor::impTxt(const char *filename)
  3429. {
  3430.   FILE *ptr;
  3431.   long dummy=-1;
  3432.   long result;
  3433.  
  3434.   ptr = fopen(filename,"rb");
  3435.   fseek(ptr,0,SEEK_END);
  3436.   unsigned long size = ftell(ptr);
  3437.  
  3438.   fseek(ptr,0,SEEK_SET);
  3439.   void *buf = malloc(0xF000);
  3440.  
  3441.   mle->sendEvent(MLM_SETIMPORTEXPORT, buf, (unsigned long)  0xF000);
  3442.  
  3443.   mle->sendEvent(MLM_FORMAT, MLFIE_CFTEXT, NULL);
  3444.  
  3445.   while (feof(ptr) == 0) {
  3446.     result = fread(buf, 1, 0xE000, ptr);
  3447.     mle->sendEvent(MLM_IMPORT, &dummy, result);
  3448.   }
  3449.   fclose(ptr);
  3450.   free(buf);
  3451. }
  3452.  
  3453. The same applies to export. If the MLE contains >64K text you have to export 
  3454. the text in chunks like this: 
  3455.  
  3456. void Editor:saveFile(void)
  3457. {
  3458.   IString filename;
  3459.   IEventData rc;
  3460.   IFileDialog:Settings settings;
  3461.  
  3462.   settings.setTitle("Save textfile");
  3463.   settings.setFileName(fname);
  3464.   settings.setOKButtonText("Save file");
  3465.   settings.setSaveAsDialog();
  3466.  
  3467.   IFileDialog file(desktopWindow(),this,settings,
  3468.                    IFileDialog:defaultStyle()
  3469.                    | IFileDialog:selectableListbox);
  3470.   if (file.pressedOK() == false)
  3471.     return ;
  3472.   filename = file.fileName();
  3473.   if (filename.size() == 0)
  3474.     return;
  3475.   mle->exportToFile(filename);
  3476.  
  3477.   void *buf = malloc(0xF000);
  3478.   long ppt=0;
  3479.  
  3480.   mle->sendEvent(MLM_SETIMPORTEXPORT, buf, (unsigned long)  0xF000);
  3481.  
  3482.   mle->sendEvent(MLM_FORMAT, MLFIE_NOTRANS, NULL);
  3483.   ofstream fil(filename);
  3484.  
  3485.   do
  3486.     {
  3487.       long amount = 0xE000;
  3488.       rc = mle->sendEvent(MLM_EXPORT, &ppt, &amount);
  3489.       fil.write((char *) buf, rc.asUnsignedLong());
  3490.     } while (rc.asUnsignedLong() > 0);
  3491. }
  3492.  
  3493. Credit: Ivar E. Hosteng 
  3494.  
  3495.  
  3496. ΓòÉΓòÉΓòÉ 8.22. How do I get PM screen size? ΓòÉΓòÉΓòÉ
  3497.  
  3498. By calling the function WinQuerySysValue() with the tags; SV_CYSCREEN and 
  3499. SV_CXSCREEN. One should always check screen size before creating windows in PM, 
  3500. and size to the right it width and height. PM does not guarantee that your 
  3501. window will be dimensioned right. Below is an example: 
  3502.  
  3503.         .
  3504.         .
  3505.         .
  3506.  
  3507.     lHeight = WinQuerySysValue(HWND_DESKTOP,SV_CYSCREEN);
  3508.     lWidth  = WinQuerySysValue(HWND_DESKTOP,SV_CXSCREEN);
  3509.  
  3510.         .
  3511.         .
  3512.         .
  3513.  
  3514. With these values you size and position your window with WinSetWindowPos(). 
  3515.  
  3516. Credit: Andreas Almroth 
  3517.  
  3518.  
  3519. ΓòÉΓòÉΓòÉ 8.23. How do I attach Instance data to window created with WinCreateStdWindow? ΓòÉΓòÉΓòÉ
  3520.  
  3521. I always use the two call to WinCreateWindow() method,    instead of the 
  3522. WinCreateStdWindow() method,  because the latter does not allow you to set 
  3523. instance data before your winproc is called for the first time. 
  3524.  
  3525. Here's a cset/2 program (icc /Ss+ /W3 /Se /B"/pm:pm" foo.c): 
  3526.  
  3527.  #define INCL_PM
  3528.  #include <os2.h>
  3529.  
  3530.  typedef struct _mydata {
  3531.      HWND hwndFrame;
  3532.      HWND hwndClient;
  3533.      char whatever[100];
  3534.  }MYDATA;
  3535.  
  3536.  static MRESULT EXPENTRY WinProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  3537.  {
  3538.      MYDATA *mine;
  3539.  
  3540.     mine = (MYDATA *)WinQueryWindowPtr(hwnd, 0);  // will be null for WM_CREATE
  3541.      switch(msg){
  3542.          case WM_CREATE:
  3543.              mine = (MYDATA *)mp1;
  3544.              WinSetWindowPtr(hwnd, 0, mine);
  3545.              break;
  3546.          case WM_ERASEBACKGROUND:
  3547.              return (MRESULT)TRUE;
  3548.          default:
  3549.             return WinDefWindowProc(hwnd, msg, mp1, mp2);
  3550.      }
  3551.      return 0;
  3552.  }
  3553.  
  3554.  void main(void)
  3555.  {
  3556.      HAB hab;
  3557.      HMQ hmq;
  3558.      QMSG qmsg;
  3559.      char *class = "foo";
  3560.      FRAMECDATA fcdata;  /* frame creation data */
  3561.      MYDATA mydat;
  3562.  
  3563.      hab = WinInitialize(0);
  3564.      hmq = WinCreateMsgQueue(hab, hmq);
  3565.  
  3566.      WinRegisterClass(hab, class, WinProc, 0, sizeof(MYDATA *));
  3567.  
  3568.      /* create frame window (WC_FRAME) */
  3569.      fcdata.cb = sizeof(FRAMECDATA);
  3570.      fcdata.flCreateFlags = FCF_TITLEBAR | FCF_SYSMENU |
  3571.                             FCF_SHELLPOSITION | FCF_TASKLIST |
  3572.                             FCF_SIZEBORDER | FCF_MINMAX ;
  3573.  
  3574.      fcdata.hmodResources = 0;
  3575.      fcdata.idResources   = 1;         /* resource id */
  3576.      mydat.hwndFrame = WinCreateWindow(HWND_DESKTOP, WC_FRAME, "Title",
  3577.                                        0, 0, 0, 0, 0,
  3578.                                        0,  /* no owner */
  3579.                                        HWND_TOP,fcdata.idResources,&fcdata,NULL);
  3580.  
  3581.      if(!mydat.hwndFrame)
  3582.          exit(3);
  3583.  
  3584.      /* WinProc() has not been called yet */
  3585.  
  3586.      /* Create Client window: */
  3587.      mydat.hwndClient = WinCreateWindow(mydat.hwndFrame, class, "text",
  3588.                          0, 0, 0, 0, 0,
  3589.                          mydat.hwndFrame,    /* frame is owner */
  3590.                          HWND_TOP, FID_CLIENT,
  3591.                          &mydat, /* passed as mp1 to wm_create */
  3592.                          NULL);
  3593.  
  3594.      WinShowWindow(mydat.hwndFrame, TRUE);
  3595.  
  3596.      while(WinGetMsg(hab, &qmsg, (HWND) NULL, 0, 0))
  3597.          WinDispatchMsg(hab, &qmsg);
  3598.  
  3599.  }
  3600.  
  3601. Credit:  Peter Fitzsimmons 
  3602.  
  3603.  
  3604. ΓòÉΓòÉΓòÉ 8.24. How do I get a list of fonts? ΓòÉΓòÉΓòÉ
  3605.  
  3606. Shown is code for For v1.3.  Petzold has had a nice series on fonts in PC MAG 
  3607. from about Nov 92-June 93. 
  3608.  
  3609. #define INCL_DEV
  3610. #define INCL_DOSMEMMGR
  3611. #define INCL_GPILCIDS
  3612. #define INCL_WINWINDOWMGR
  3613. #define INCL_WINLISTBOXES
  3614. #include <os2.h>
  3615. #include <stdio.h>
  3616.  
  3617. VOID EXPENTRY FntQueryList(hwnd)
  3618. HWND hwnd; // listbox handle
  3619.   {
  3620.   PFONTMETRICS pfm;
  3621.   HDC          hdc;
  3622.   HPS          hps;
  3623.   LONG         alDevInfo[2];
  3624.   LONG         lFonts;
  3625.   LONG         lFontCnt = 0L;
  3626.   CHAR         pch[64];
  3627.   SEL          sel;
  3628.   USHORT       i;
  3629.  
  3630.   hdc = WinOpenWindowDC(hwnd);
  3631.   DevQueryCaps(hdc, CAPS_HORIZONTAL_FONT_RES, 2L, alDevInfo);
  3632.   hps = WinGetPS(hwnd);
  3633.   lFonts = GpiQueryFonts(hps, QF_PUBLIC, (PSZ)0, &lFontCnt,
  3634.                          (LONG)sizeof(FONTMETRICS), (PFONTMETRICS)0 );
  3635.   DosAllocSeg((USHORT)lFonts * sizeof(FONTMETRICS), &sel, SEG_NONSHARED);
  3636.   pfm = (PFONTMETRICS)MAKEP(sel, 0);
  3637.   GpiQueryFonts(hps, QF_PUBLIC, (PSZ)0, &lFonts,
  3638.                 (LONG)sizeof(FONTMETRICS), pfm );
  3639.   for (i = 0; i < (USHORT)lFonts; i++) {
  3640.     if (!(pfm[i].fsDefn & FM_DEFN_OUTLINE)) {
  3641.       if ((pfm[i].sXDeviceRes == (SHORT)alDevInfo[0]) &&
  3642.           (pfm[i].sYDeviceRes == (SHORT)alDevInfo[1]) ) {
  3643.             sprintf(pch, "%2d.%s",
  3644.                     pfm[i].sNominalPointSize / 10,
  3645.                     pfm[i].szFacename );
  3646.         WinSendMsg(hwnd, LM_INSERTITEM,
  3647.                    MPFROMSHORT(LIT_END), MPFROMP(pch) );
  3648.         }
  3649.       }
  3650.     }
  3651.   DosFreeSeg(sel);
  3652.   WinReleasePS(hps);
  3653.   return;
  3654.   }
  3655.  
  3656.  
  3657. ΓòÉΓòÉΓòÉ 8.25. How do I create a folder in C and put my pgm in it? ΓòÉΓòÉΓòÉ
  3658.  
  3659. /* Create our folder on the desktop */
  3660.  
  3661. HOBJECT hFolder, hObject;
  3662.  
  3663. hFolder = WinCreateObject ("wpFolder", "My Folder",
  3664.                            "OBJECTID=<MY_FOLDER>", "<WP_DESKTOP>",
  3665.                            CO_REPLACEIFEXISTS);
  3666.  
  3667. /* Now, put our object into the folder. */
  3668.  
  3669. hObject = WinCreateObject ("wpProgram", "My Online Book",
  3670.                            "EXENAME=VIEW.EXE;PARAMETERS=MYBOOK.INF;\
  3671.                            OBJECTID=<MY_BOOK>", "<MY_FOLDER>",
  3672.                            CO_REPLACEIFEXISTS);
  3673.  
  3674. What that little code snippet does is create a folder called "My Folder"
  3675. on the desktop, and puts a program object for an online book in it.
  3676. Check out the documentation on the following functions for more
  3677. information:
  3678.  
  3679. WinCreateObject
  3680. wpSetup (for information on the setup string parameter to WinCreateObj)
  3681. WPFolder (for information on the setup strings of folders)
  3682. WPProgram programs etc.
  3683.  
  3684.  
  3685. ΓòÉΓòÉΓòÉ 8.26. How do I do it in REXX? ΓòÉΓòÉΓòÉ
  3686.  
  3687. You may have seen the Paradox 4.0 install script, which uses SysCreateObject to 
  3688. make a WPS object 
  3689.  
  3690. Hope they don't mind me posting a fragment of the script by: 
  3691.  
  3692. /* Rob Gordon  Borland International 6/8/92  */
  3693.  
  3694. title = "Paradox 4.0"
  3695. classname = 'WPProgram'
  3696. location = '<WP_DESKTOP>'
  3697. setup = 'PROGTYPE=WINDOWEDVDM;EXENAME='pdoxpath'paradox.exe;
  3698.   STARTUPDIR='pdoxpath';SET DPMI_DOS_API=ENABLED;
  3699.   SET DPMI_MEMORY_LIMIT=4;ICONFILE 'pdoxpath'pdoxos2.ico;'
  3700.  
  3701. BldObj:
  3702. call charout , 'Building : 'title
  3703. result = SysCreateObject(classname, title, location, setup)
  3704.  
  3705.  
  3706. ΓòÉΓòÉΓòÉ 8.27. How do I use the Font dialog (WinFontDlg)? ΓòÉΓòÉΓòÉ
  3707.  
  3708. FIRST:  make your stack huge (>32K)  It is sparsely allocated and you only use 
  3709. what you need. Here's some code: 
  3710.  
  3711.  FONTDLG fontdlg ;
  3712.  FONTMETRICS fm ;
  3713.  CHAR            szBuf [200] ;
  3714.  CHAR            szFamily [CCHMAXPATH] ;
  3715.  static CHAR     szTitle [] = "Fonts Dialog" ;
  3716.  static CHAR     szMsgBoxTitle [] = "Result from 'WinFontDlg ()'" ;
  3717.  static CHAR     szPreview [] = "We hold these truths to be self-evident ..." ;
  3718.  
  3719.  // Here, get an HPS and then do a WinQueryFontMetrics.
  3720.  // Continuing ...
  3721.  
  3722.  memset ((void *) &fontdlg, 0, sizeof (FONTDLG)) ;
  3723.  fontdlg.cbSize = sizeof (FONTDLG) ;
  3724.  fontdlg.hpsScreen = WinGetScreenPS (HWND_DESKTOP) ;
  3725.  fontdlg.hpsPrinter = NULLHANDLE ;
  3726.  fontdlg.pszTitle = szTitle ;
  3727.  fontdlg.pszPreview = szPreview ;
  3728.  fontdlg.pfnDlgProc = NULL ;
  3729.  strcpy (szFamily, fm.szFamilyname) ;
  3730.  fontdlg.pszFamilyname = szFamily ;
  3731.  fontdlg.usFamilyBufLen = sizeof (szFamily) ;
  3732.  fontdlg.fxPointSize = MAKEFIXED (fm.sNominalPointSize / 10, 0) ;
  3733.  fontdlg.fl = FNTS_CENTER | FNTS_HELPBUTTON |
  3734.      FNTS_INITFROMFATTRS | FNTS_NOSYNTHESIZEDFONTS |
  3735.      FNTS_RESETBUTTON ;
  3736.  fontdlg.sNominalPointSize = fm.sNominalPointSize ;
  3737.  fontdlg.flType = (LONG) fm.fsType ;
  3738.  fontdlg.clrFore = CLR_NEUTRAL ;
  3739.  fontdlg.clrBack = CLR_BACKGROUND ;
  3740.  fontdlg.usWeight = fm.usWeightClass ;
  3741.  fontdlg.usWidth = fm.usWidthClass ;
  3742.  
  3743.  hwndDlg = WinFontDlg (HWND_DESKTOP, hwnd, &fontdlg) ;
  3744.  
  3745. Credit: Wayne Kovsky 
  3746.  
  3747.  
  3748. ΓòÉΓòÉΓòÉ 8.28. How do I take control of frame sizing? ΓòÉΓòÉΓòÉ
  3749.  
  3750. I want to "subclass" the Window Frame Class to allow me to control the size of 
  3751. my main window when it's resized by the mouse. I want to control the steps it 
  3752. take to resize too, (ie: by 8x8 steps). 
  3753.  
  3754. --- CUT --- CUT ---- .H file --- CUT --- 
  3755.  
  3756. HWND APIENTRY WinCreateMBWindow(
  3757.  
  3758.   HWND hwndParent,
  3759.   ULONG flStyle,
  3760.   PULONG pflCreateFlags,
  3761.   PSZ pszClientClass,
  3762.   PSZ pszTitle,
  3763.   ULONG styleClient,
  3764.   HMODULE hmod,
  3765.   USHORT idResources,
  3766.   PHWND phwndClient);
  3767.  
  3768.  
  3769. #define HMODFROMMP(mp) ((USHORT)(ULONG)(mp))
  3770.  
  3771. #define MB_CHILD_SIZE  WM_USER+204
  3772.           //Sent from child to frame indicating the new
  3773.           //requested size of the child area.  (high&width in MP1)
  3774.           //If ChildMax is shrinking below current size,
  3775.           // frame is redused, and evt scroll bars is hidden.
  3776.           //If Child is growing
  3777.           //   MP2=True -> grows frame to contain maximized child
  3778.           //   MP2=False-> enables scroll bars, keeps size.
  3779.  
  3780. #define MB_FIX_N       0x1 //Fix north border when sizing
  3781. #define MB_FIX_E       0x2 //Fix east  border when sizing
  3782.  
  3783. #define MB_FIX_NE       0x3 //Fix north east corner when sizing
  3784. #define MB_FIX_SE       0x2 //Fix south east corner when sizing
  3785. #define MB_FIX_NW       0x1 //Fix north west corner when sizing
  3786. #define MB_FIX_SW       0x0 //Fix south west corner when sizing
  3787.  
  3788. #define MB_QCHILD_SIZE_MAX     WM_USER+205
  3789.            //Sent from frame to child to queryw
  3790.            //max size of the child area.  (h&w in MR)
  3791.            //Used when sizing to determin if scroll bars are ness.
  3792.  
  3793. #define MB_QCHILD_GRID     WM_USER+206
  3794.            //Sent from frame to child before tracking
  3795.            //Child supposed to return x&y granularity in MR
  3796.  
  3797. #define MB_CREATE          WM_USER+207  //Internally shipped command.
  3798.  
  3799. typedef struct _FRM_DTA { /* Fram data */
  3800.     PFNWP    oldProc;
  3801.     SHORT    nTrkCnr,nYSclHor,nXSclVer,nTitle;
  3802.     SHORT    xMax,yMax;    //Max size of Client in PIX
  3803.     SHORT    ScrMaxX,ScrMaxY;
  3804.     POINTL   ptlBdr;
  3805.     HWND     hVert,hHori;
  3806.     SHORT    xCur,yCur;    //Current size of Client in PIX
  3807.     SHORT    nCorner;      //Which corner is to be stable
  3808. } FRM_DTA;
  3809. typedef FRM_DTA FAR * PFRM_DTA;
  3810.  
  3811. --- CUT --- CUT --- .C file --- CUT --- CUT --- 
  3812.  
  3813. HWND    APIENTRY WinCreateMBWindow(HWND hParent, ULONG flStyle,
  3814.                                    PULONG pflCreate, PSZ pszClientClass,
  3815.                                    PSZ pszTitle, ULONG styleClient,
  3816.                                    HMODULE hmod,
  3817.                                    USHORT idResources, PHWND phClient)
  3818. {
  3819.   HWND         hFrame;
  3820.   PFRM_DTA     pFrm;
  3821.  
  3822.   hFrame = WinCreateStdWindow(hParent,flStyle,pflCreate,pszClientClass,
  3823.                               pszTitle,styleClient,hmod,idResources,phClient);
  3824.  
  3825.   //Allocate some storage for local parameters, and initialize it
  3826.   pFrm=malloc(sizeof( FRM_DTA));
  3827.   memset(pFrm,0,sizeof( FRM_DTA));
  3828.  
  3829.   WinSetWindowPtr(hFrame,QWL_USER,(PVOID) pFrm);
  3830.  
  3831.   pFrm->oldProc= WinSubclassWindow(hFrame,newFrameProc);
  3832.  
  3833.   //Now window is setup:
  3834.  
  3835.   WinSendMsg(hFrame,MB_CREATE,MP0,MP0);    //My own WM_CREATE
  3836.  
  3837.   WinShowWindow(hFrame,TRUE);
  3838.  
  3839.   WinUpdateWindow(hFrame);
  3840.   return hFrame;
  3841. }
  3842.  
  3843. VOID GetChildMax(HWND hFrame, PFRM_DTA    pFrm)
  3844. { MRESULT mr;
  3845.   mr = WinSendMsg(WinWindowFromID(hFrame,FID_CLIENT),
  3846.                   MB_QCHILD_SIZE_MAX,MP0,MP0);
  3847.   pFrm->xMax=SHORT1FROMMR(mr);
  3848.   pFrm->yMax=SHORT2FROMMR(mr);
  3849. }
  3850.  
  3851. #define CLIENT_PROVIDED  FALSE
  3852. #define FRAME_PROVIDED     TRUE
  3853.  
  3854. BOOL WinCalcFrameSWP(HWND hwnd, PSWP pSWP, BOOL bFrame)
  3855. { //    TRUE       Frame rectangle provided
  3856.   //    FALSE      Client-area rectangle provided.
  3857.   RECTL rcl;
  3858.   BOOL bSuccess;
  3859.  
  3860.   rcl.xLeft   = pSWP->x;
  3861.   rcl.yBottom = pSWP->y;
  3862.   rcl.xRight  = pSWP->x+pSWP->cx;
  3863.   rcl.yTop    = pSWP->y+pSWP->cy;
  3864.  
  3865.   bSuccess = WinCalcFrameRect(hwnd, &rcl, bFrame );
  3866.  
  3867.   pSWP->x  =(SHORT) rcl.xLeft;
  3868.   pSWP->y  =(SHORT) rcl.yBottom;
  3869.   pSWP->cx =(SHORT) (rcl.xRight-rcl.xLeft);
  3870.   pSWP->cy =(SHORT) (rcl.yTop  -rcl.yBottom);
  3871.  
  3872.   return(bSuccess);
  3873. }
  3874.  
  3875.  
  3876. VOID SclBarEnable(HWND hwnd, PSWP pSWP, PFRM_DTA  pFrm)
  3877. {
  3878.  
  3879.   .....
  3880.  
  3881.  Your routines to determine and en/disable scroll bars 
  3882.  
  3883.   .....
  3884. /*    Part of my code */
  3885.   swpClient = *(pSWP);
  3886.   WinCalcFrameSWP(hwnd, &swpClient, FRAME_PROVIDED);
  3887.   if (swpClient.cx >= pFrm->xMax-1)
  3888.   { //Turn off horisontal scroll bar
  3889.     WinSetParent(pFrm->hHori,HWND_OBJECT ,FALSE);
  3890.     nUpdt = FCF_HORZSCROLL;
  3891.   }  /* code for enabling left out..... */
  3892.  
  3893.   if (nUpdt != 0)
  3894.   {
  3895.     WinSendMsg (hwnd, WM_UPDATEFRAME, MPFROMSHORT(nUpdt), MP0);
  3896.   }
  3897. */
  3898. }
  3899.  
  3900. /***************** Start of frame subclass procedure *****************/
  3901.  
  3902. MRESULT  EXPENTRY newFrameProc( HWND hwnd, USHORT msg,
  3903. MPARAM mp1, MPARAM mp2 )
  3904.  
  3905. { PSWP        pSWP;
  3906.   PFNWP     oldProc;
  3907.   PFRM_DTA  pFrm;
  3908.  
  3909.   pFrm=(PFRM_DTA)WinQueryWindowPtr(hwnd,QWL_USER);
  3910.   oldProc=pFrm->oldProc;
  3911.  
  3912.   switch(msg)
  3913.   {
  3914.     case MB_CREATE:
  3915.       //Start hiding scroll bars
  3916.       pFrm->hVert  = WinWindowFromID(hwnd,FID_VERTSCROLL);
  3917.       WinSetParent(pFrm->hVert,HWND_OBJECT ,FALSE);
  3918.       pFrm->nYSclHor = 0;
  3919.     break;
  3920.  
  3921.     case WM_MINMAXFRAME:
  3922.     { SWP swpClient;
  3923.       pSWP=(PSWP) PVOIDFROMMP(mp1);
  3924.       pSWP->fs |= SWP_SIZE;
  3925.  
  3926.       GetChildMax(hwnd, pFrm);
  3927.  
  3928.       if (pSWP->fs & SWP_MAXIMIZE) //MaxiMizeing Operation
  3929.       {
  3930.         //tprintf("WM_MINMAXFRAME SWP_MAXIMIZE FS: %X┬á",pSWP->fs);
  3931.         if ((0!=pFrm->xMax) && (0!=pFrm->yMax))
  3932.         { //I have no data for all of screen, so act as Windowed OS/2
  3933.  
  3934.           memset(&swpClient,0,sizeof(swpClient));
  3935.           swpClient.cx=pFrm->xMax;
  3936.           swpClient.cy=pFrm->yMax;
  3937.           WinCalcFrameSWP(hwnd, &swpClient,CLIENT_PROVIDED);
  3938.  
  3939.           pSWP->cx = swpClient.cx;
  3940.           pSWP->cy = swpClient.cy;
  3941.  
  3942.           pSWP->y  = pFrm->ScrMaxY - swpClient.cy + (SHORT)pFrm->ptlBdr.y;
  3943.  
  3944.  
  3945.           SclBarEnable(hwnd, pSWP, pFrm);
  3946.  
  3947.           return MRFROMSHORT(FALSE);
  3948.         }
  3949.       }
  3950.  
  3951.       if (pSWP->fs & SWP_RESTORE) //MiniMizeing Operation
  3952.  
  3953. ??? (restore i guess) 
  3954.  
  3955.       {
  3956.         //tprintf("WM_MINMAXFRAME SWP_RESTORE FS: %X┬á",pSWP->fs);
  3957.         if ((0!=pFrm->xMax) && (0!=pFrm->yMax))  //Why do I need this?
  3958.         {
  3959.           return MRFROMSHORT(FALSE);
  3960.         }
  3961.       }
  3962.     }
  3963.     return (MRESULT)(*oldProc)(hwnd, msg, mp1, mp2);
  3964.  
  3965.  
  3966.     case WM_QUERYTRACKINFO:
  3967.     {
  3968.       PTRACKINFO pTI;
  3969.       LONG i;
  3970.  
  3971.       if (TF_MOVE <= SHORT1FROMMP(mp1))
  3972.       {
  3973.         pFrm->nTrkCnr= 0;
  3974.         return (MRESULT)(*oldProc)(hwnd, msg, mp1, mp2);
  3975.       }
  3976.  
  3977.       pTI = (PTRACKINFO) PVOIDFROMMP (mp2);  //Get structure pointer;
  3978.       //tprintf("@+WM_QUERYTRACKINFO FS: %X┬á",pTI->fs);
  3979.       if ((*oldProc)(hwnd, msg, mp1, mp2)==0) return MRFROMSHORT(FALSE);
  3980.  
  3981.       GetChildMax(hwnd, pFrm);
  3982.       if ((0!=pFrm->xMax) && (0!=pFrm->yMax))
  3983.       { //Setup track info structure
  3984.         pTI->ptlMaxTrackSize.x = (LONG) pFrm->xMax;
  3985.         pTI->ptlMaxTrackSize.y = (LONG) pFrm->yMax;
  3986.  
  3987.         WinCalcFrameRect(hwnd, &(pTI->rclTrack), FRAME_PROVIDED );
  3988.  
  3989.         { MRESULT mr;
  3990.           mr = WinSendMsg(WinWindowFromID(hwnd,FID_CLIENT),
  3991.                           MB_QCHILD_GRID,MP0,MP0);
  3992.           if (NULL!=mr)
  3993.           {
  3994.             pTI->cxGrid  = SHORT1FROMMR(mr);
  3995.             pTI->cyGrid  = SHORT2FROMMR(mr);
  3996.  
  3997.             //Setting height of client to integral cyGrid
  3998.             i = (pTI->rclTrack.yTop - pTI->rclTrack.yBottom)/pTI->cyGrid;
  3999.             pTI->rclTrack.yTop = i * pTI->cyGrid + pTI->rclTrack.yBottom;
  4000.  
  4001.             pTI->fs    |= TF_GRID;
  4002.             pFrm->nTrkCnr= WM_QUERYTRACKINFO;
  4003.             //Used in WM_ADJUSTWINODWPOS
  4004.           }
  4005.         }
  4006.       }
  4007.       return MRFROMSHORT(TRUE);
  4008.     }
  4009.     break;
  4010.  
  4011.     case WM_ADJUSTWINDOWPOS:
  4012.     { RECTL rcl;
  4013.       pSWP=(PSWP) PVOIDFROMMP(mp1);
  4014.  
  4015.       if (pSWP->fs & (SWP_SIZE | SWP_MOVE | SWP_MAXIMIZE))
  4016.       {
  4017.         GetChildMax(hwnd, pFrm);
  4018.         if (WM_QUERYTRACKINFO==pFrm->nTrkCnr)
  4019.           //As a result of tracking
  4020.         {
  4021.           //Go from client to frame values
  4022.           WinCalcFrameSWP(hwnd, pSWP, CLIENT_PROVIDED);
  4023.         }
  4024.  
  4025.         pFrm->nTrkCnr     = 0;
  4026.  
  4027.         SclBarEnable(hwnd, pSWP, pFrm);
  4028.       }
  4029.       return (MRESULT)(*oldProc)(hwnd, msg, mp1, mp2);
  4030.     }
  4031.     break;
  4032.  
  4033.     case MB_CHILD_SIZE:      //xCur,yCur
  4034.     { SWP swp;
  4035.  
  4036. ............. do your actions as responce to client resize request (Change of 
  4037. fontsize for instance) 
  4038.  
  4039.  
  4040.       return (MRESULT)TRUE;
  4041.     }
  4042.     break;
  4043.  
  4044.     default:
  4045.     break;
  4046.   }
  4047.   return (MRESULT)(*oldProc)(hwnd, msg, mp1, mp2);
  4048. }
  4049.  
  4050. A lot is deleted (Som is very application specific), but i hope you get the 
  4051. general picture. 
  4052.  
  4053. Credit:  Henrik Wahlberg 
  4054.  
  4055.  
  4056. ΓòÉΓòÉΓòÉ 8.29. How do I use the 16-bit EPM toolkit? ΓòÉΓòÉΓòÉ
  4057.  
  4058. Since there were a few requests, here are the changes I made to get the ESIMPLE 
  4059. example from the EPM Toolkit to work with the C-Set++ compiler. The ETK DLLs 
  4060. are 16-bit and need to be thunked to be called from a 32-bit app. Since I was 
  4061. playing around, some of the changes were not necessary to get the program to 
  4062. run.  Changes are in DIFF format. 
  4063.  
  4064. **** Changes to EDLL.H ****
  4065. 254a255
  4066. > #pragma pack(2)
  4067. 259,263c260,264
  4068. <    PSWP   pswp;         // positioning of edit window
  4069. <    PSZ    filename;     // file to be edited (with wildcard)
  4070. <    PVOID  hEditPtr;     // handle to editor pointer icon.
  4071. <    PVOID  hMarkPtr;     // handle to mark pointer icon.
  4072. <    PVOID  hEditorIcon;  // editor ICON.
  4073. >    PSWP _Seg16   pswp;         // positioning of edit window
  4074. >    PSZ _Seg16    filename;     // file to be edited (with wildcard)
  4075. >    HPOINTER  hEditPtr;  // handle to editor pointer icon.
  4076. >    HPOINTER  hMarkPtr;  // handle to mark pointer icon.
  4077. >    PVOID _Seg16  hEditorIcon;  // editor ICON.
  4078. 267,269c268,270
  4079. <    PSZ    exfile;       // pre-compiled macro code file (EPM.EX)
  4080. <    PSZ    topmkr;       // top and bottom of file marker
  4081. <    PSZ    botmkr;       //
  4082. ---
  4083. >    PSZ _Seg16    exfile;       // pre-compiled macro code file (EPM.EX)
  4084. >    PSZ _Seg16    topmkr;       // top and bottom of file marker
  4085. >    PSZ _Seg16    botmkr;       //
  4086. 271,272c272,273
  4087. <    PSZ    exsearchpath; // a set of paths to search for ex's files
  4088. <    PSZ    exe_path;     // path where the application started
  4089. ---
  4090. >    PSZ _Seg16    exsearchpath; // a set of paths to search for ex's files
  4091. >    PSZ _Seg16    exe_path;     // path where the application started
  4092. 275c276,277
  4093. < typedef EDITORINFO far *PEDITORINFO;
  4094. ---
  4095. > typedef EDITORINFO * PEDITORINFO;
  4096. > #pragma pack()
  4097. 280c282
  4098. < #define ETKENTRY _loadds
  4099. ---
  4100. > #define ETKENTRY CDECL16
  4101. 285,286c287,288
  4102. < PSZ     ETKENTRY EtkRegister( HAB hab, ULONG class_style );
  4103. < USHORT ETKENTRY EtkCreate( PEDITORINFO epm_p, PHWND hEwnd_p);
  4104. ---
  4105. > PSZ _Seg16    ETKENTRY EtkRegister( HAB hab, ULONG class_style );
  4106. > USHORT ETKENTRY EtkCreate( PEDITORINFO _Seg16 epm_p, PHWND _Seg16 hEwnd_p);
  4107. 304c306,307
  4108. < SHORT  ETKENTRY EtkSetSelection( HWND  hwndClient, LINE_INDEX_G  firstline,
  4109. ---
  4110. > SHORT  ETKENTRY EtkSetSelection( HWND  hwndClient, LINE_INDEX_G  firstline,
  4111. >    FIDType fileid);
  4112.  
  4113. **** Changes to ESIMPLE.C ****
  4114. 28a29,30
  4115. >
  4116. > #include "thunk.h"
  4117. 47a50
  4118. >    HWND hwndEditFrame;
  4119. 52c55
  4120. <
  4121. ---
  4122. >    swp.fl = SWP_MOVE | SWP_SIZE;
  4123. 58c61
  4124. <    epm.filename    = (PSZ)Fname;      // file to be edited (with wildca
  4125. ---
  4126. >    epm.filename    = Fname;           // file to be
  4127. > edited (with wildca
  4128. 64,65c67,70
  4129. <    epm.editorstyle = EDIT_STYLE_ACTIVATEFOCUS | EDIT_STYLE_DISABLEOWNERAFFECT
  4130. <                      EDIT_STYLE_CURSORON;
  4131. ---
  4132. >    epm.editorstyle = EDIT_STYLE_ACTIVATEFOCUS |
  4133. >                      EDIT_STYLE_CURSORON |
  4134. >                      EDIT_STYLE_STATUSLINE |
  4135. >                      EDIT_STYLE_MESSAGELINE;
  4136. 67,68c72,73
  4137. <    epm.pmstyle     = FCF_TITLEBAR | FCF_SIZEBORDER | FCF_VERTSCROLL;
  4138. <
  4139. ---
  4140. >    epm.pmstyle     = FCF_TITLEBAR | FCF_SIZEBORDER |
  4141. > FCF_VERTSCROLL | FCF_MIN
  4142. >    epm.font = TRUE;  // large font
  4143. 70,71c75,76
  4144. <    epm.topmkr      =                        // top and bottom file indicator
  4145. <    epm.botmkr      = (PSZ)" ╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧";
  4146. ---
  4147. >    epm.topmkr      = (PSZ)"<Top>";
  4148. > // top and bottom fi
  4149. >    epm.botmkr      = (PSZ)"<Bottom>";
  4150. 75c80
  4151. <
  4152. ---
  4153. >    epm.hini = NULLHANDLE;
  4154. 77,79c82,86
  4155. <    EtkCreate( (EDITORINFO far *)&epm, (PHWND)&hwndEdit );
  4156. <
  4157. <    return( (HWND)hwndEdit );
  4158. ---
  4159. >    EtkCreate( &epm, &hwndEdit );
  4160. >       hwndEditFrame = WinQueryWindow(hwndEdit, QW_PARENT);
  4161. >       WinSetWindowPos(hwndEditFrame, NULLHANDLE, swp.x, swp.y,
  4162. >           swp.cx, swp.cy, SWP_MOVE | SWP_SIZE);
  4163. >    return( hwndEdit );
  4164. 95c102
  4165. < MRESULT FAR PASCAL TestWndProc( HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2
  4166. ---
  4167. > MRESULT EXPENTRY TestWndProc( HWND hwnd, USHORT msg,
  4168. > MPARAM mp1, MPARAM mp2 )
  4169. 144,146c151,155
  4170. <   case EPM_EDIT_ACTIVEHWND:
  4171. <      WinSetActiveWindow(HWND_DESKTOP,(HWND)mp1 );
  4172. <      break;
  4173. ---
  4174. > case EPM_EDIT_ACTIVEHWND:
  4175. >   {
  4176. >      WinSetActiveWindow(HWND_DESKTOP,(HWND)mp1 );
  4177. >   }
  4178. >   break;
  4179. 160c169
  4180. <                     (PSZ)mp1,
  4181. ---
  4182. >                     (PSZ)_DosSelToFlat(mp1),
  4183. 162c171
  4184. <                     NULL,
  4185. ---
  4186. >                     NULLHANDLE,
  4187. 235c244
  4188. <     hab = WinInitialize(NULL);              // Initialize app as a PM app
  4189. ---
  4190. >     hab = WinInitialize(NULLHANDLE);        // Initialize app as a PM app
  4191. 247c256
  4192. <
  4193.  
  4194. Credit:  Mat Kramer 
  4195.  
  4196.  
  4197. ΓòÉΓòÉΓòÉ 8.30. How do I get error info after using WinGetLastError()? ΓòÉΓòÉΓòÉ
  4198.  
  4199. One should only use WinGetLastError() after a bad return value, ERRORID is not 
  4200. always zeroed after a successful call to PM API. 
  4201.  
  4202. ShowError Function: 
  4203.  
  4204. /*
  4205.  * ShowError -- for debugging: outputs (via printf) the last error;
  4206.  *    to use this, redirect the output of this program to a file and
  4207.  *    check the results in that file.
  4208.  *    Updated to display the error text in a MESSAGE BOX; ID_MSGBOX must be
  4209.  *    defined.
  4210.  */
  4211.  void ShowError(void)
  4212.  {
  4213.     PERRINFO p;
  4214.     char *cp;
  4215.     extern HAB hab;   /* kinda kludgy, should be a parameter */
  4216.  
  4217.     printf("ShowError: ");
  4218.     if((p = WinGetErrorInfo(hab)) == NULL)
  4219.        printf("NO ERROR\n");
  4220.     else
  4221.     {
  4222.        printf("idError = %#X\n", p->idError);
  4223.        cp = (char *)((ULONG)p + *(ULONG *)((ULONG)p + p->offaoffszMsg));
  4224.        printf("\"%s\"\n", cp);
  4225.        WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, (PSZ)cp, (PSZ)"Show Error",
  4226.                      ID_MSGBOX, MB_OK | MB_ICONEXCLAMATION);
  4227.        WinFreeErrorInfo(p);
  4228.     }
  4229.  }
  4230.  
  4231. Credit:  Justin V Frank 
  4232.  
  4233.  
  4234. ΓòÉΓòÉΓòÉ 8.31. Do you have code to save/restore the clipboard? ΓòÉΓòÉΓòÉ
  4235.  
  4236.  typedef struct _CLPBRDDATA // INFORMATION ABOUT A CLIPBOARD FORMAT
  4237.  {
  4238.     ULONG ulFormat; // The format type
  4239.     PVOID pvData;   // Pointer to the data for this format
  4240.  } CLPBRDDATA, *PCLPBRDDATA;
  4241.  
  4242.  //***************
  4243.  // Save formats
  4244.  //***************
  4245.  INT SaveClipboardData( HAB hab, PCLPBRDDATA *ppcd )
  4246.  {
  4247.     INT iFmtCount = 0;
  4248.  
  4249.     if( WinOpenClipbrd( hab ) )
  4250.     {
  4251.        ULONG ulNextFmt, ulPrevFmt = 0;
  4252.  
  4253.        ulNextFmt = WinEnumClipbrdFmts( hab, ulPrevFmt );
  4254.        while( ulNextFmt )
  4255.        {
  4256.           iFmtCount++;
  4257.           ulPrevFmt = ulNextFmt;
  4258.           ulNextFmt = WinEnumClipbrdFmts( hab, ulPrevFmt );
  4259.        }
  4260.  
  4261.        if( iFmtCount )
  4262.        {
  4263.           *ppcd = (PCLPBRDDATA) malloc( sizeof( CLPBRDDATA ) * iFmtCount );
  4264.           if( *ppcd )
  4265.           {
  4266.              memset( *ppcd, 0, sizeof( CLPBRDDATA ) * iFmtCount );
  4267.               if( !GetClipboardFmts( hab, *ppcd ) )
  4268.                  iFmtCount = 0;
  4269.           }
  4270.           else
  4271.           {
  4272.              iFmtCount = 0;
  4273.              Msg( "Out of memory in SaveClipboardData" );
  4274.           }
  4275.        }
  4276.        WinCloseClipbrd( hab );
  4277.     }
  4278.     else
  4279.        Msg( "SaveClipboardData could not open the clipboard" );
  4280.  
  4281.     return iFmtCount;
  4282.  }
  4283.  
  4284.  BOOL GetClipboardFmts( HAB hab, PCLPBRDDATA pcd )
  4285.  {
  4286.     BOOL  fSuccess = TRUE;
  4287.     ULONG ulNextFmt, ulPrevFmt = 0;
  4288.  
  4289.     ulNextFmt = WinEnumClipbrdFmts( hab, ulPrevFmt );
  4290.     while( ulNextFmt )
  4291.     {
  4292.        pcd->ulFormat = ulNextFmt;
  4293.        switch( ulNextFmt )
  4294.        {
  4295.           case CF_TEXT:
  4296.              StoreClipboardText( hab, pcd );
  4297.              break;
  4298.           case CF_BITMAP:
  4299.              StoreClipboardBmp( hab, pcd );
  4300.              break;
  4301.           case CF_METAFILE:
  4302.              StoreClipboardMeta( hab, pcd );
  4303.              break;
  4304.           default:
  4305.              break;
  4306.        }
  4307.  
  4308.        pcd++;
  4309.        ulPrevFmt = ulNextFmt;
  4310.        ulNextFmt = WinEnumClipbrdFmts( hab, ulPrevFmt );
  4311.     }
  4312.     return fSuccess;
  4313.  }
  4314.  
  4315.  VOID StoreClipboardText( HAB hab, PCLPBRDDATA pcd )
  4316.  {
  4317.     PSZ szClipText = (PSZ) WinQueryClipbrdData( hab, CF_TEXT );
  4318.     if( szClipText )
  4319.     {
  4320.        pcd->pvData = malloc( strlen( szClipText ) + 1 );
  4321.        if( pcd->pvData )
  4322.           strcpy( pcd->pvData, szClipText );
  4323.        else
  4324.           Msg( "Out of memory in StoreClipboardText" );
  4325.     }
  4326.     else
  4327.        Msg( "StoreClipboardText found no TEXT in the clipboard" );
  4328.  }
  4329.  
  4330.  VOID StoreClipboardBmp( HAB hab, PCLPBRDDATA pcd )
  4331.  {
  4332.     HBITMAP hbmClip = WinQueryClipbrdData( hab, CF_BITMAP );
  4333.     if( hbmClip )
  4334.        pcd->pvData = (PVOID) CopyBitmap( hab, hbmClip );
  4335.     else
  4336.        Msg( "StoreClipboardBmp found no BITMAP in the clipboard" );
  4337.  }
  4338.  
  4339.  VOID StoreClipboardMeta( HAB hab, PCLPBRDDATA pcd )
  4340.  {
  4341.     HMF hmfClip = WinQueryClipbrdData( hab, CF_METAFILE );
  4342.     if( hmfClip )
  4343.     {
  4344.        HMF hmfNew = GpiCopyMetaFile( hmfClip );
  4345.        if( hmfNew == GPI_ERROR )
  4346.           Msg( "StoreClipboardMeta GpiCopyMetaFile RC = %x",
  4347.           (USHORT) WinGetLastError( hab ) );
  4348.        else
  4349.           pcd->pvData = (PVOID) hmfNew;
  4350.     }
  4351.     else
  4352.        Msg( "StoreClipboardMeta found no METAFILE in the clipboard" );
  4353.  }
  4354.  
  4355.  //******************
  4356.  // Restore formats
  4357.  //******************
  4358.  VOID RestClipboardData( HAB hab, INT iFmtCount, PCLPBRDDATA pcd )
  4359.  {
  4360.     PCLPBRDDATA pcdSave = pcd;
  4361.     INT  i;
  4362.     BOOL fFormatsExist = FALSE;
  4363.  
  4364.     for( i = 0; i < iFmtCount; i++, pcd++ )
  4365.     {
  4366.        if( pcd->ulFormat && pcd->pvData )
  4367.        {
  4368.           fFormatsExist = TRUE;
  4369.           break;
  4370.        }
  4371.     }
  4372.  
  4373.     pcd = pcdSave;
  4374.     if( fFormatsExist )
  4375.        if( WinOpenClipbrd( hab ) )
  4376.        {
  4377.           WinEmptyClipbrd( hab );
  4378.           for( i = 0; i < iFmtCount; i++, pcd++ )
  4379.           {
  4380.              switch( pcd->ulFormat )
  4381.              {
  4382.                 case 0:
  4383.                    break;
  4384.                 case CF_TEXT:
  4385.                    if( pcd->pvData )
  4386.                    {
  4387.                       RestClipboardText( hab, pcd->pvData );
  4388.                       free( pcd->pvData );
  4389.                    }
  4390.                    break;
  4391.                 case CF_BITMAP:
  4392.                    if( pcd->pvData )
  4393.                    RestClipboardBmp( hab, (HBITMAP) pcd->pvData );
  4394.                    break;
  4395.                 case CF_METAFILE:
  4396.                    if( pcd->pvData )
  4397.                       RestClipboardMeta( hab, (HMF) pcd->pvData );
  4398.                    break;
  4399.                 default:
  4400.                    break;
  4401.              }
  4402.           }
  4403.           WinCloseClipbrd( hab );
  4404.        }
  4405.        else
  4406.           Msg( "RestClipboardData could not open the clipboard" );
  4407.     free( pcdSave );
  4408.  }
  4409.  
  4410.  VOID RestClipboardText( HAB hab, PSZ szTextIn )
  4411.  {
  4412.     PSZ szTextOut = NULL;
  4413.     ULONG ulRC =
  4414.     DosAllocSharedMem( (PVOID) &szTextOut, NULL,
  4415.                        strlen( szTextIn ) + 1,
  4416.                        PAG_WRITE | PAG_COMMIT | OBJ_GIVEABLE );
  4417.     if( !ulRC )
  4418.     {
  4419.        strcpy( szTextOut, szTextIn );
  4420.        if( !WinSetClipbrdData( hab, (ULONG) szTextOut, CF_TEXT,
  4421.                                CFI_POINTER ) )
  4422.           Msg( "RestClipboardText WinSetClipbrdData failed" );
  4423.     }
  4424.     else
  4425.        Msg( "RestClipboardText DosAllocSharedMem RC: %u", ulRC );
  4426.  }
  4427.  
  4428.  VOID RestClipboardBmp( HAB hab, HBITMAP hbm )
  4429.  {
  4430.   if( !WinSetClipbrdData( hab, (ULONG) hbm, CF_BITMAP, CFI_HANDLE ) )
  4431.      Msg( "RestClipboardBmp WinSetClipbrdData failed" );
  4432.  }
  4433.  
  4434.  VOID RestClipboardMeta( HAB hab, HMF hmf )
  4435.  {
  4436.   if( !WinSetClipbrdData( hab, (ULONG) hmf, CF_METAFILE, CFI_HANDLE ) )
  4437.      Msg( "RestClipboardMeta WinSetClipbrdData failed" );
  4438.  }
  4439.  
  4440.  HBITMAP CopyBitmap( HAB hab, HBITMAP hbmIn )
  4441.  {
  4442.     BITMAPINFOHEADER2 bmih;
  4443.     HBITMAP           hbmOut = NULLHANDLE;
  4444.     HDC               hdcIn = NULLHANDLE, hdcOut = NULLHANDLE;
  4445.     HPS               hpsIn = NULLHANDLE, hpsOut = NULLHANDLE;
  4446.     POINTL            aptl[ 3 ];
  4447.     SIZEL             sizel = {0,0};
  4448.  
  4449.     hdcIn = DevOpenDC( hab, OD_MEMORY, "*", 0, NULL, NULLHANDLE );
  4450.     if( !hdcIn )
  4451.     {
  4452.        Msg( "CopyBitmap DevOpenDC for hdcIn RC = %x",
  4453.             (USHORT) WinGetLastError( hab ) );
  4454.        goto BYEBYE;
  4455.     }
  4456.  
  4457.     hdcOut = DevOpenDC( hab, OD_MEMORY, "*", 0, NULL, NULLHANDLE );
  4458.     if( !hdcOut )
  4459.     {
  4460.        Msg( "CopyBitmap DevOpenDC for hdcOut RC = %x",
  4461.             (USHORT) WinGetLastError( hab ) );
  4462.        goto BYEBYE;
  4463.     }
  4464.  
  4465.     hpsIn  = GpiCreatePS( hab, hdcIn, &sizel,PU_PELS |
  4466.                           GPIF_DEFAULT | GPIT_MICRO | GPIA_ASSOC );
  4467.     if( !hpsIn )
  4468.     {
  4469.        Msg( "CopyBitmap GpiCreatePS for hpsIn RC = %x",
  4470.             (USHORT) WinGetLastError( hab ) );
  4471.        goto BYEBYE;
  4472.     }
  4473.  
  4474.     hpsOut = GpiCreatePS( hab, hdcOut, &sizel,PU_PELS |
  4475.                           GPIF_DEFAULT | GPIT_MICRO | GPIA_ASSOC );
  4476.     if( !hpsOut )
  4477.     {
  4478.        Msg( "CopyBitmap GpiCreatePS for hpsOut RC = %x",
  4479.             (USHORT) WinGetLastError( hab ) );
  4480.        goto BYEBYE;
  4481.     }
  4482.  
  4483.     bmih.cbFix = sizeof( BITMAPINFOHEADER2 );
  4484.     if( !GpiQueryBitmapInfoHeader( hbmIn, &bmih ) )
  4485.     {
  4486.        Msg( "CopyBitmap GpiQueryBitmapInfoHeader for hbmIn RC = %x",
  4487.             (USHORT) WinGetLastError( hab ) );
  4488.        goto BYEBYE;
  4489.     }
  4490.  
  4491.     hbmOut = GpiCreateBitmap( hpsOut, &bmih, 0, NULL, NULL );
  4492.     if( hbmOut )
  4493.     {
  4494.        if( HBM_ERROR == GpiSetBitmap( hpsIn, hbmIn ) )
  4495.        {
  4496.           Msg( "CopyBitmap GpiSetBitmap for hpsIn RC = %x",
  4497.                (USHORT) WinGetLastError( hab ) );
  4498.           hbmOut = NULLHANDLE;
  4499.           goto BYEBYE;
  4500.        }
  4501.  
  4502.        if( HBM_ERROR == GpiSetBitmap( hpsOut, hbmOut ) )
  4503.        {
  4504.           Msg( "CopyBitmap GpiSetBitmap for hpsOut RC = %x",
  4505.                (USHORT) WinGetLastError( hab ) );
  4506.           hbmOut = NULLHANDLE;
  4507.           goto BYEBYE;
  4508.        }
  4509.  
  4510.        aptl[ 0 ].x = 0;
  4511.        aptl[ 0 ].y = 0;
  4512.        aptl[ 1 ].x = bmih.cx;
  4513.        aptl[ 1 ].y = bmih.cy;
  4514.        aptl[ 2 ].x = 0;
  4515.        aptl[ 2 ].y = 0;
  4516.  
  4517.        if( GPI_ERROR == GpiBitBlt( hpsOut, hpsIn, 3, aptl, ROP_SRCCOPY,
  4518.                                    BBO_IGNORE ) )
  4519.        {
  4520.           Msg( "CopyBitmap GpiBitBlt for hpsOut RC = %x",
  4521.                (USHORT) WinGetLastError( hab ) );
  4522.           hbmOut = NULLHANDLE;
  4523.        }
  4524.     }
  4525.     else
  4526.        Msg( "CopyBitmap GpiCreateBitmap for hbmOut RC = %x",
  4527.             (USHORT) WinGetLastError( hab ) );
  4528.  
  4529.  BYEBYE:
  4530.  
  4531.     if( hpsIn )
  4532.        GpiDestroyPS( hpsIn );
  4533.     if( hpsOut )
  4534.        GpiDestroyPS( hpsOut );
  4535.     if( hdcIn )
  4536.        DevCloseDC( hdcIn );
  4537.     if( hdcOut )
  4538.        DevCloseDC( hdcOut );
  4539.     return hbmOut;
  4540.  }
  4541.  
  4542. Credit:  Rick Fishman 
  4543.  
  4544.  
  4545. ΓòÉΓòÉΓòÉ 8.32. How do I know what item was selected in a Combo box? ΓòÉΓòÉΓòÉ
  4546.  
  4547. Catch the LN_SELECT message from the combo box, then send an LM_QUERYSELECTION 
  4548. to get the index of the selection, then a LM_QUERYITEMTEXT to get the selected 
  4549. text. 
  4550.  
  4551. Credit:  Pete Norloff 
  4552.  
  4553.  
  4554. ΓòÉΓòÉΓòÉ 8.33. How do I get a bitmap into a dialog in a DLL? ΓòÉΓòÉΓòÉ
  4555.  
  4556. You've hit on a known problem with bitmaps in dialogs in dlls. This also used 
  4557. to be a problem for icons but that appears to be working now. 
  4558.  
  4559. First, define your bitmap in your dialog like this (notice no mention of 
  4560. SS_BITMAP). It is strictly text at this point. PM can handle this when loading 
  4561. the dialog: 
  4562.  
  4563. Below are all the files necessary to create dllbitmp.exe and dlgdll.dll. Dlgdll 
  4564. has the dialog box and bitmap. Dllbitmp.exe calls DllDialog() in dlgdll.dll to 
  4565. bring up the dialog box from the dll's resource file... 
  4566.  
  4567. DLLBITMP.C: 
  4568.  
  4569.  #define  INCL_GPI
  4570.  #define  INCL_WIN
  4571.  #include <os2.h>
  4572.  #include "dllbitmp.h"
  4573.  
  4574.  #define FRAME_FLAGS  (FCF_TASKLIST | FCF_TITLEBAR   |
  4575.                        FCF_MENU     | FCF_SYSMENU    |
  4576.                        FCF_MINMAX   | FCF_SIZEBORDER |
  4577.                        FCF_SHELLPOSITION)
  4578.  #define CLIENT_CLASS "DllBitmp"
  4579.  
  4580.  
  4581.  INT main( VOID );
  4582.  VOID EXPENTRY DllDialog( HWND );
  4583.  FNWP wpClient;
  4584.  
  4585.  
  4586.  INT main( VOID )
  4587.  {
  4588.     HAB   hab;
  4589.     HMQ   hmq;
  4590.     QMSG  qmsg;
  4591.     HWND  hwndFrame, hwndClient;
  4592.     ULONG flFrame = FRAME_FLAGS;
  4593.  
  4594.     hab = WinInitialize( 0 );
  4595.     hmq = WinCreateMsgQueue( hab, 0 );
  4596.     WinRegisterClass( hab, CLIENT_CLASS, wpClient, 0, 0 );
  4597.     hwndFrame = WinCreateStdWindow( HWND_DESKTOP, WS_VISIBLE,
  4598.                                     &flFrame,CLIENT_CLASS, NULL,
  4599.                                     0,NULLHANDLE, ID_RESOURCES,
  4600.                                     &hwndClient );
  4601.     while( WinGetMsg( hab, &qmsg, NULLHANDLE, 0, 0 ) )
  4602.        WinDispatchMsg( hab, &qmsg );
  4603.  
  4604.     WinDestroyWindow( hwndFrame );
  4605.     WinDestroyMsgQueue( hmq );
  4606.     WinTerminate( hab );
  4607.     return 0;
  4608.  }
  4609.  
  4610.  
  4611.  MRESULT EXPENTRY wpClient( HWND hwnd, ULONG msg,
  4612.                             MPARAM mp1, MPARAM mp2 )
  4613.  {
  4614.     switch( msg )
  4615.     {
  4616.        case WM_ERASEBACKGROUND:
  4617.           return (MRESULT) TRUE;
  4618.        case WM_COMMAND:
  4619.        switch( SHORT1FROMMP( mp1 ) )
  4620.        {
  4621.           case IDM_DOIT:
  4622.           {
  4623.              DllDialog( hwnd );
  4624.              return 0;
  4625.           }
  4626.        }
  4627.  
  4628.        break;
  4629.     }
  4630.     return WinDefWindowProc( hwnd, msg, mp1, mp2 );
  4631.  }
  4632.  
  4633. DLLBITMP.H: 
  4634.  
  4635.  #define ID_RESOURCES    1
  4636.  #define IDD_DOIT    100
  4637.  #define IDM_DOIT    110
  4638.  #define ID_BITMAP    1100
  4639.  #define ID_BITMAPID    1200
  4640.  
  4641. DLLBITMP.DEF: 
  4642.  
  4643.  NAME        DLLBITMP      WINDOWAPI
  4644.  PROTMODE
  4645.  HEAPSIZE    16384
  4646.  STACKSIZE    16384
  4647.  
  4648. DLLBITMP.RC: 
  4649.  
  4650.  #include <os2.h>
  4651.  #include "dllbitmp.h"
  4652.  
  4653.  
  4654.  MENU ID_RESOURCES
  4655.  {
  4656.      MENUITEM "!~DoIt", IDM_DOIT
  4657.  }
  4658.  
  4659. DLGDLL.C: 
  4660.  
  4661.  #define  INCL_DOS
  4662.  #define  INCL_GPI
  4663.  #define  INCL_WIN
  4664.  #include <os2.h>
  4665.  #include "dllbitmp.h"
  4666.  
  4667.  
  4668.  FNWP wpDlg;
  4669.  
  4670.  
  4671.  VOID EXPENTRY DllDialog( HWND hwnd )
  4672.  {
  4673.     HMODULE hmod;
  4674.  
  4675.     DosQueryModuleHandle( "DLGDLL", &hmod );
  4676.     WinDlgBox( HWND_DESKTOP, hwnd, wpDlg, hmod, IDD_DOIT, NULL );
  4677.  }
  4678.  
  4679.  
  4680.  MRESULT EXPENTRY wpDlg( HWND hwndDlg, ULONG msg, MPARAM mp1, MPARAM mp2 )
  4681.  {
  4682.     switch (msg)
  4683.     {
  4684.        case WM_INITDLG:
  4685.        {
  4686.           HWND    hwndBmp = WinWindowFromID( hwndDlg, ID_BITMAPID );
  4687.           HPS     hps = WinGetPS( hwndDlg );
  4688.           HBITMAP hbm;
  4689.           HMODULE hmod;
  4690.  
  4691.           DosQuieryModuleHandle( "DLGDLL", &hmod );
  4692.           hbm = GpiLoadBitmap( hps, hmod, ID_BITMAP, 0, 0 );
  4693.           WinSetWindowBits(hwndBmp,QWL_STYLE,SS_BITMAP,SS_BITMAP | 0x7f);
  4694.           WinSendMsg( hwndBmp, SM_SETHANDLE, MPFROMP( hbm ), NULL );
  4695.           WinSetWindowULong( hwndDlg, QWL_USER, (ULONG) hbm );
  4696.           WinReleasePS( hps );
  4697.           break;
  4698.        }
  4699.        case WM_DESTROY:
  4700.        {
  4701.           HBITMAP hbm = (HBITMAP) WinQueryWindowULong(hwndDlg,QWL_USER );
  4702.           GpiDeleteBitmap( hbm );
  4703.           break;
  4704.        }
  4705.     }
  4706.     return WinDefDlgProc( hwndDlg, msg, mp1, mp2 );
  4707.  }
  4708.  
  4709. DLGDLL.DLG: 
  4710.  
  4711.  DLGTEMPLATE IDD_DOIT LOADONCALL MOVEABLE DISCARDABLE
  4712.  BEGIN
  4713.    DIALOG "", IDD_DOIT, 0, 0, 210, 154, FS_NOBYTEALIGN | FS_DLGBORDER |
  4714.               WS_VISIBLE | WS_CLIPSIBLINGS | WS_SAVEBITS, FCF_TITLEBAR
  4715.    BEGIN
  4716.        CONTROL "foo", ID_BITMAPID, 98, 56, 32, 32, WC_STATIC,
  4717.                SS_TEXT | DT_LEFT | DT_TOP | WS_VISIBLE
  4718.    END
  4719.  END
  4720.  
  4721. DLGDLL.DEF: 
  4722.  
  4723.  LIBRARY    DLGDLL        INITINSTANCE    TERMINSTANCE
  4724.  PROTMODE
  4725.  CODE        LOADONCALL
  4726.  DATA        LOADONCALL    MULTIPLE    NONSHARED
  4727.  EXPORTS    DllDialog
  4728.  
  4729. DLGDLL.RC: 
  4730.  
  4731.  #include <os2.h>
  4732.  #include "dllbitmp.h"
  4733.  
  4734.  
  4735.  BITMAP  ID_BITMAP "dlgdll.bmp"
  4736.  
  4737.  
  4738.  rcinclude dlgdll.dlg
  4739.  
  4740. MAKEFILE: 
  4741.  
  4742.  all: dlgdll.dll dllbitmp.exe
  4743.  
  4744.  dlgdll.dll: $*.obj $*.res
  4745.      link386 /NOI /NOE /MAP /DE /NOL $*, $*.dll,, os2386, $*
  4746.      rc $*.res $*.dll
  4747.      implib $*.lib $*.def
  4748.  
  4749.  dllbitmp.exe: $*.obj $*.def $*.res
  4750.      link386  /NOI /NOE /MAP /DE /NOL $*,,, os2386 dlgdll, $*
  4751.      rc $*.res $*.exe
  4752.  
  4753.  dllbitmp.obj: $*.c
  4754.      icc /Q+ /Ss /W3 /Kbcepr /Gm- /Gd- /Ge+ /Ti+ /O- /C $*.c
  4755.  
  4756.  dllbitmp.res: $*.rc
  4757.      rc -r $*
  4758.  
  4759.  dlgdll.obj: $*.c
  4760.      icc /Q+ /Ss /W3 /Kbcepr /Gm- /Gd- /Ge- /Ti+ /O- /C $*.c
  4761.  
  4762.  dlgdll.res: $*.rc $*.dlg
  4763.      rc -r $*
  4764.  
  4765. Credit:  Rick Fishman 
  4766.  
  4767.  
  4768. ΓòÉΓòÉΓòÉ 8.34. How does programming PM compare to programming X? ΓòÉΓòÉΓòÉ
  4769.  
  4770. Many people have said "PM is much cleaner."  Until I hear from someone I trust 
  4771. with extensive experience with both (I only know X), however, this FAQ will 
  4772. take no position. 
  4773.  
  4774. There was an unsubstantiated rumor that someone was porting an X library to 
  4775. OS/2 (X-Windows, not X-Mode or any other X), I dunno whether this has been 
  4776. substantiated or not. 
  4777.  
  4778. IBM and a few other manufacturers have built their own X servers for OS/2. 
  4779. [details?] 
  4780.  
  4781. [Colin Jensen...] 
  4782.  
  4783. I have some limited experience with X and PM.  Raw Xlib is harder to program 
  4784. than PM.  However most, if not all, of the X11 Toolkits are *easier* to use 
  4785. than PM.  I have experience comparing XView to PM. A friend of mine has 
  4786. experience with Windows versus Xt, and has the same opinion (Windows isn't that 
  4787. far off conceptually from PM). 
  4788.  
  4789.  
  4790. ΓòÉΓòÉΓòÉ 8.35. How do I put bitmaps on buttons? ΓòÉΓòÉΓòÉ
  4791.  
  4792. Stefan Gruendal (Stefan_Gruendel@wue.maus.de) writes: 
  4793.  
  4794. But to my question:  How do I build my own "smart icons", i.e. bitmaps on 
  4795. pushbuttons, that optically "move into the screen"? I didn't find any way to 
  4796. achieve this with the Toolkit's Dialog Editor.  But as mentioned above, I know 
  4797. there's a way. 
  4798.  
  4799. Starting with OS/2 2.x, a new button style was added - BS_ICON - which allows 
  4800. you to do what you are trying to accomplish.  It works, as far as I know, only 
  4801. for pushbuttons, and the icon or bitmap is taken from the resource file, whose 
  4802. resource id is specified in the pushbutton text. 
  4803.  
  4804. For example: 
  4805.  
  4806. In FOO.H: 
  4807.  
  4808. #define IDBM_BUTTON 256
  4809. #define IDPB_BUTTON 257
  4810.  
  4811. In FOO.RC: 
  4812.  
  4813. BITMAP IDBM_BUTTON BUTTON.BMP
  4814.  
  4815. In FOO.C: 
  4816.  
  4817. sprintf(achText,"#%d",IDBM_BUTTON);
  4818.  
  4819. hwndButton=WinCreateWindow(hwndClient,WC_BUTTON,achText,
  4820.                            WS_VISIBLE|BS_PUSHBUTTON|BS_ICON,
  4821.                            10,10,32,32,hwndClient,HWND_TOP,
  4822.                            IDPB_BUTTON,NULL,NULL);
  4823.  
  4824. The bitmap is stretched or compressed to fill the button. 
  4825.  
  4826. (Quoted almost directly from EDMI/2 Edition 1) 
  4827.  
  4828.  
  4829. ΓòÉΓòÉΓòÉ 8.36. Can a PM program tell if there's a previous instance of itself running? ΓòÉΓòÉΓòÉ
  4830.  
  4831. Raja Thiagarajan (sthiagar@bronze.ucs.indiana.edu) writes: 
  4832.  
  4833. Can a PM program tell if there's a previous instance of itself running?  In 
  4834. Win3.x (but apparently NOT Win32), there's a hPrevInst handle; is there an OS/2 
  4835. 2.x equivalent?  Basically, I'm thinking in terms of a program that would try 
  4836. to borrow resources from a previous instance if a previous instance is running. 
  4837. (Specifically, if my palette animation program gets started twice, the second 
  4838. instance oughta share palettes with the first instance!) 
  4839.  
  4840. What you're really asking is two questions: 
  4841.  
  4842.  1. How can I determine if a previous instance of my application is already 
  4843.     running? 
  4844.  2. How can I share resources between multiple instances of my application? 
  4845.  
  4846. There are some ways to achieve this; You can use semaphores or/and shared 
  4847. memory or the other method described below. Try to open your named semaphore, 
  4848. if it's there, your application is already running, else create a semaphore... 
  4849. To share data, use shared memory. There are some excellent examples in Schildt 
  4850. & Goosey "OS/2 Programming". 
  4851.  
  4852. To answer your first question, you need to enumerate all of the main windows 
  4853. present on the desktop, and figure out if any of them are yours. This is 
  4854. achieved using the following code: 
  4855.  
  4856. HWND queryAppInstance(PCHAR pchClassWanted)
  4857. {
  4858.    HENUM heEnum;
  4859.    HWND hwndTop;
  4860.    HWND hwndClient;
  4861.    CHAR achClass[256];
  4862.  
  4863.    heEnum=WinBeginEnumWindows(HWND_DESKTOP);
  4864.  
  4865.    hwndTop=WinGetNextWindow(heEnum);
  4866.    while (hwndTop!=NULLHANDLE) {
  4867.       hwndClient=WinWindowFromID(hwndTop,FID_CLIENT);
  4868.       if (hwndClient!=NULLHANDLE) {
  4869.          WinQueryClassName(hwndClient,sizeof(achClass),achClass);
  4870.          if (strcmp(achClass,pchClassWanted)==0) {
  4871.             WinEndEnumWindows(heEnum);
  4872.             return hwndClient;
  4873.          } /* endif */
  4874.       } /* endif */
  4875.  
  4876.       hwndTop=WinGetNextWindow(heEnum);
  4877.    } /* endwhile */
  4878.  
  4879.    WinEndEnumWindows(heEnum);
  4880.    return NULLHANDLE;
  4881. }
  4882.  
  4883. To answer your second question, the only way that I know of to share resources 
  4884. is to place them in a DLL.  The procedure to do this is as follows: 
  4885.  
  4886. o Create a dummy source file with an empty procedure in it. 
  4887. o Compile the source file and link as a DLL. 
  4888. o Add your resources to the DLL in the same manner as you would to an 
  4889.   executable. 
  4890.  
  4891. Then, when your application starts, you simply call WinLoadLibrary  (the 
  4892. preferred way) or DosLoadModule to load the DLL.  These functions return a 
  4893. handle to the DLL which must then be used in any function which loads resources 
  4894. (e.g. GpiLoadBitmap, WinLoadPointer, etc.). 
  4895.  
  4896. Note that this procedure does not require knowing the window handle of any 
  4897. previous instance of your application because OS/2 implements DLLs in a shared 
  4898. fashion (which I suspect is one of the reasons they were created in the first 
  4899. place).  All you need to know is the name of the DLL.  This technique can also 
  4900. be used to share resources between different applications. 
  4901.  
  4902. (Quoted almost directly from EDMI/2 Edition 1) 
  4903.  
  4904.  
  4905. ΓòÉΓòÉΓòÉ 8.37. How to avoid crash when using Drag and Drop? ΓòÉΓòÉΓòÉ
  4906.  
  4907. You can avoid this by doing; 
  4908.  
  4909. 1) Call any DRG*() function in your application
  4910. 2) Call DosLoadModule() to load the PMDRAG.DLL file
  4911. Credit: Q 
  4912.  
  4913.  
  4914. ΓòÉΓòÉΓòÉ 9. Miscellaneous Programming ΓòÉΓòÉΓòÉ
  4915.  
  4916. This section covers non-Presentation Manager programming. 
  4917.  
  4918.  
  4919. ΓòÉΓòÉΓòÉ 9.1. Explain the SYS_DLL keywords. ΓòÉΓòÉΓòÉ
  4920.  
  4921. Actually there are three key names that exist for the app name SYS_DLL. 
  4922.  
  4923. They are: 
  4924.  
  4925. LOAD 
  4926.           DLL loaded and ordinal 1 entry point called for every msg queue 
  4927.           created in the system 
  4928.  
  4929. LOADPERPROCESS 
  4930.           DLL loaded and ordinal 1 entry point called for only the first 
  4931.           message queue created on a process 
  4932.  
  4933. LOADONETIME 
  4934.           DLL loaded and ordinal 1 entry point called for only the shell's 
  4935.           message queue (the first PM queue in the system) 
  4936.  
  4937. You would use one over another depending on the type of initialization that you 
  4938. require.  Most DLL's only need to be initialized once for the system and are 
  4939. thus LOADONETIME, some DLLs like PMCTLS have per process initialization and 
  4940. thus are LOADPERPROCESS, and then there is the very rare case of DLLs that need 
  4941. to perform some function every time a message queue is created and these are 
  4942. specified as LOAD.  Note: that anything other than LOADONETIME is a significant 
  4943. performance hit on the system.  Note: also that in addition to your 
  4944. INITIALIZATION/TERMINATION function specified in the DEF file for your DLL 
  4945. (which is a new feature in 2.0), your ORDINAL 1 entry point in your DLL is also 
  4946. called.  Be careful with this as I have seen some pretty strange results if you 
  4947. have an ordinal 1 entry point that has nothing to do with initialization.  In 
  4948. addition, remember to never ever create a message queue inside of your 
  4949. initialization routine.  Always call WinQueryAnchorBlock if you need a HAB for 
  4950. some API. 
  4951.  
  4952. As for shared resources, if you need resources on multiple processes then they 
  4953. need to be created on multiple processes as they won't be valid on any process 
  4954. other than the one you loaded.  I believe that this is the reason PMCTLS is 
  4955. LOADPERPROCESS.  You have a few options here, 1) you can store your resources 
  4956. in shared memory, and 2) for icons you can call WinSetPoinerOwner to make your 
  4957. icons shared across the entire system. 
  4958.  
  4959.  
  4960. ΓòÉΓòÉΓòÉ 9.2. How do I start another session? ΓòÉΓòÉΓòÉ
  4961.  
  4962. This small program will start any program synchronously using 
  4963. DosStartSession(). The important thing is the queue. When you specify 
  4964. SSF_RELATED_CHILD and a TermQ name, OS/2 will write the return code to the 
  4965. specified queue when the session terminates. I use this in an event scheduler 
  4966. by creating a separate thread that does reads from the queue but you can just 
  4967. as easily block on the main thread to catch the return code. That will, in 
  4968. effect, provide for synchronous execution. Note that one problem with 
  4969. SSF_RELATED_CHILD is that if the program that started the child dies, so does 
  4970. the child. 
  4971.  
  4972.  #define  INCL_DOSERRORS
  4973.  #define  INCL_DOSPROCESS
  4974.  #define  INCL_DOSQUEUES
  4975.  #define  INCL_DOSSESMGR
  4976.  #include <os2.h>
  4977.  #include <stdio.h>
  4978.  #include <stdlib.h>
  4979.  #include <string.h>
  4980.  
  4981.  #define QUEUE_NAME    "\\QUEUES\\STRTSYNC.QUE"
  4982.  
  4983.  int main( int argc, char *argv[] );
  4984.  
  4985.  int main( int argc, char *argv[] )
  4986.  {
  4987.      APIRET rc;
  4988.      HQUEUE hque;
  4989.  
  4990.      if( argc < 2 )
  4991.          return 1;
  4992.  
  4993.      rc = DosCreateQueue( &hque, QUE_FIFO | QUE_CONVERT_ADDRESS, QUEUE_NAME );
  4994.      if( !rc )
  4995.      {
  4996.          STARTDATA   stdata;
  4997.          PID         pidSession;
  4998.          CHAR        szObjFail[ 50 ];
  4999.          ULONG       ulLength, idSession;
  5000.          REQUESTDATA rd;
  5001.          PUSHORT     pusInfo = NULL;
  5002.          BYTE        bPriority;
  5003.  
  5004.          (void) memset( &stdata, 0, sizeof( stdata ) );
  5005.  
  5006.          stdata.Length       = sizeof( STARTDATA );
  5007.          stdata.FgBg         = SSF_FGBG_FORE;
  5008.          stdata.TraceOpt     = SSF_TRACEOPT_NONE;
  5009.          stdata.PgmTitle     = "Rick's Program";
  5010.          stdata.InheritOpt   = SSF_INHERTOPT_SHELL;
  5011.          stdata.SessionType  = SSF_TYPE_DEFAULT;
  5012.          stdata.PgmControl   = SSF_CONTROL_VISIBLE;
  5013.          stdata.ObjectBuffer = szObjFail;
  5014.          stdata.ObjectBuffLen= sizeof( szObjFail );
  5015.          stdata.Related      = SSF_RELATED_CHILD;
  5016.          stdata.TermQ        = QUEUE_NAME;
  5017.          stdata.PgmName      = argv[ 1 ];
  5018.  
  5019.          rc = DosStartSession( &stdata, &idSession, &pidSession );
  5020.  
  5021.          if( rc && rc != ERROR_SMG_START_IN_BACKGROUND )
  5022.          {
  5023.              printf( "DosStartSession RC(%u)\n", rc );
  5024.              return (INT) rc;
  5025.          }
  5026.  
  5027.          rc = DosReadQueue( hque, &rd, &ulLength, (PPVOID) &pusInfo, 0,
  5028.                             DCWW_WAIT, &bPriority, 0 );
  5029.  
  5030.          if( rc && rc != ERROR_QUE_EMPTY )
  5031.          {
  5032.              printf( "DosReadQueue RC(%u)\n", rc );
  5033.              return (INT) rc;
  5034.          }
  5035.  
  5036.          printf( "RetCode from Session %u: %u\n",
  5037.                   pusInfo[ 0 ], pusInfo[ 1 ]);
  5038.  
  5039.          DosCloseQueue( hque );
  5040.      }
  5041.      else
  5042.      {
  5043.          printf( "DosCreateQueue RC(%u)\n", rc );
  5044.          return (INT) rc;
  5045.      }
  5046.  
  5047.      return 0;
  5048.  }
  5049.  
  5050. Credit:  Rick Fishman 
  5051.  
  5052.  
  5053. ΓòÉΓòÉΓòÉ 9.3. How do I check if a filename is valid? ΓòÉΓòÉΓòÉ
  5054.  
  5055. Here's some code that should help.  I found that you have to look at each 
  5056. return code to see if it's really an error.  This routine does do syntax 
  5057. checking, it's just a little more complicated than before :^) 
  5058.  
  5059. #define INCL_DOSFILEMGR
  5060. #define INCL_DOSERRORS
  5061. #include <os2.h>
  5062. #include <stdio.h>
  5063.  
  5064. int main( int argc, char **argv )
  5065. {
  5066.         int         rc;
  5067.         FILESTATUS3 piBuffer;
  5068.  
  5069.         if ( argc !=2 )
  5070.         {
  5071.                 printf( "Must pass filename on command line!\n");
  5072.                 return( -1 );
  5073.         }
  5074.         else
  5075.         {
  5076.                 printf( "Checking on %s, ", argv[ 1 ] );
  5077.                 rc = DosQueryPathInfo( (PSZ)argv[1], FIL_STANDARD, &piBuffer,
  5078.                                        sizeof(FILESTATUS3));
  5079.  
  5080.                 if ( rc == 0 )
  5081.                         printf( "syntax valid and file exists\n" );
  5082.                 else
  5083.                 if ( rc == ERROR_FILE_NOT_FOUND )
  5084.                         printf( "syntax valid and file doesn't exist.\n");
  5085.                 else
  5086.                 if ( rc == ERROR_PATH_NOT_FOUND )
  5087.                         printf( "syntax valid, somthing in path was not found\n");
  5088.                 else
  5089.                 {
  5090.                         printf( "bad, rc=%d, ",rc );
  5091.                         switch( rc )
  5092.                         {
  5093.                                 case ERROR_INVALID_DRIVE:
  5094.                                         printf( "drive name does not exist\n");
  5095.                                         break;
  5096.  
  5097.                                 case ERROR_INVALID_NAME:
  5098.                                         printf( "invalid syntax for drive name\n");
  5099.                                         break;
  5100.  
  5101.                                 case ERROR_FILENAME_EXCED_RANGE:
  5102.                                         printf( "dir name and/or filename too long\n");
  5103.                                         break;
  5104.  
  5105.                                 case ERROR_SHARING_VIOLATION:
  5106.                                         printf( "sharing violation\n");
  5107.                                         break;
  5108.  
  5109.                                 case ERROR_BUFFER_OVERFLOW:
  5110.                                         printf( "buffer overflow\n");
  5111.                                         break;
  5112.  
  5113.                                 case ERROR_INVALID_LEVEL:
  5114.                                         printf( "invalid level requested\n");
  5115.                                         break;
  5116.  
  5117.                                 case ERROR_INVALID_EA_NAME:
  5118.                                         printf( "invalid EA name\n");
  5119.                                         break;
  5120.  
  5121.                                 case ERROR_EA_LIST_INCONSISTENT:
  5122.                                         printf( "EA list inconsistent\n");
  5123.                                         break;
  5124.  
  5125.                                 default:
  5126.                                         printf("Undocumented return value.\n");
  5127.                         }
  5128.                         return( -1 );
  5129.             }
  5130.             return( 0 );
  5131.         }
  5132. }
  5133.  
  5134. Credit:  Mike Brown 
  5135.  
  5136.  
  5137. ΓòÉΓòÉΓòÉ 9.4. Why should I use _beginthread instead of DosCreateThread? ΓòÉΓòÉΓòÉ
  5138.  
  5139. You must if you want to use the C runtime library. 
  5140.  
  5141.  
  5142. ΓòÉΓòÉΓòÉ 9.5. How do I open a file that is already in use? ΓòÉΓòÉΓòÉ
  5143.  
  5144. Use DosOpen with OPEN_SHARE_DENYNONE. 
  5145.  
  5146. /* this will copy an open program */
  5147.  
  5148. #define INCL_NOPM
  5149. #define INCL_DOS
  5150. #include <os2.h>
  5151. #include <stdio.h>
  5152. #include <string.h>
  5153.  
  5154. void usage(void)
  5155. {
  5156.     printf("USAGE: CopyOpen <source file> <dest file>\n\n");
  5157.     printf("       This program,  unlike the normal copy and xcopy commands,\n");
  5158.     printf("       will copy an open file.\n");
  5159.     printf("NOTE:  Wildcards are not supported\n");
  5160. }
  5161.  
  5162. int cdecl main(int argc, char **argv)
  5163. {
  5164.     HFILE hf, hfOut;
  5165.     USHORT usAction, rc, bytesRead, bytesWriten ;
  5166.     static BYTE buf[4096];
  5167.     long total=0l;
  5168.     int error = FALSE;
  5169.  
  5170.     if(argc!=3){
  5171.         usage();
  5172.         return 1;
  5173.     }
  5174.     rc = DosOpen(strupr(argv[1]),
  5175.         &hf,
  5176.         &usAction,
  5177.         0L,
  5178.         FILE_NORMAL,
  5179.         FILE_OPEN,
  5180.         OPEN_ACCESS_READONLY | OPEN_SHARE_DENYNONE,
  5181.         0L);
  5182.     if(rc){
  5183.         printf("SYS%04u: Could not open %s for read.\n", rc, argv[1]);
  5184.         return 3;
  5185.     }
  5186.     rc = DosOpen(strupr(argv[2]),
  5187.         &hfOut,
  5188.         &usAction,
  5189.         0L,
  5190.         FILE_NORMAL,
  5191.         FILE_CREATE | FILE_TRUNCATE,
  5192.         OPEN_ACCESS_WRITEONLY | OPEN_SHARE_DENYREADWRITE,
  5193.         0L);
  5194.     if(rc){
  5195.         printf("SYS%04u: Could not open %s for write.\n", rc, argv[2]);
  5196.         return 3;
  5197.     }
  5198.     else{
  5199.         do{
  5200.             rc = DosRead(hf, buf, sizeof(buf), &bytesRead);
  5201.             if(!rc){
  5202.                rc = DosWrite(hfOut, buf, bytesRead, &bytesWriten);
  5203.                if(!rc) total += bytesWriten;
  5204.             }
  5205.         }while(!rc &&
  5206.                sizeof(buf) == bytesRead &&
  5207.                bytesRead == bytesWriten);
  5208.         if(rc){
  5209.             printf("SYS%04u: while copying.\n", rc);
  5210.             error = TRUE;
  5211.         }
  5212.         if(bytesRead != bytesWriten){
  5213.             printf("Disk full?\n");
  5214.             error = TRUE;
  5215.         }
  5216.         DosClose(hf);
  5217.         if(!error)
  5218.             printf("%lu bytes copied.\n", total);
  5219.     }
  5220.     return( error? 3 : 0);
  5221. }
  5222.  
  5223. Credit:  Peter Fitzsimmons 
  5224.  
  5225.  
  5226. ΓòÉΓòÉΓòÉ 9.6. Can we use Vio in v2.0? Where are the docs for it? ΓòÉΓòÉΓòÉ
  5227.  
  5228. Yes; check cdrom.com for PRCP.ZIP. 
  5229.  
  5230.  
  5231. ΓòÉΓòÉΓòÉ 9.7. Can I redirect stdin and stdout in a child process? ΓòÉΓòÉΓòÉ
  5232.  
  5233. This is what I use to redirect stderr, stdout to a file from a program I start 
  5234. using DosStartSession. You could do the same type of thing using a pipe. 
  5235.  
  5236.     ULONG  ulAction;
  5237.     ULONG  ulNew;
  5238.     HFILE  hfFile, hfNewStdOut = -1, hfNewStdErr = -1,
  5239.            hfStdOut = 1, hfStdErr = 2;
  5240.  
  5241.     // Open output file
  5242.     DosOpen( szOutputFile, &hfFile, &ulAction, 1, 0,
  5243.              FILE_OPEN | FILE_CREATE,
  5244.              OPEN_ACCESS_READWRITE | OPEN_SHARE_DENYNONE, 0L );
  5245.     // Duplicate handles
  5246.     DosDupHandle( hfStdOut, phfNewStdOut );
  5247.     DosDupHandle( hfStdErr, phfNewStdErr );
  5248.     // Close existing handles for current process
  5249.     DosClose( hfStdOut );
  5250.     DosClose( hfStdErr );
  5251.     // Redirect existing handles to new file
  5252.     DosDupHandle( hfFile, &hfStdOut );
  5253.     DosDupHandle( hfFile, &hfStdErr );
  5254.     // Let started program inherit handles from parent
  5255.     stdata.InheritOpt = SSF_INHERITOPT_PARENT;
  5256.     // Start new session
  5257.     DosStartSession( &stdata, &ulSessionID, &pidSession );
  5258.     // Get back original handles
  5259.     DosDupHandle( hfNewStdOut, &hfStdOut );
  5260.     DosDupHandle( hfNewStdErr, &hfStdErr );
  5261.     // Close the duplicated handles - no longer needed
  5262.     DosClose( hfNewStdOut );
  5263.     DosClose( hfNewStdErr );
  5264.  
  5265. Credit:  Rick Fishman 
  5266.  
  5267.  
  5268. ΓòÉΓòÉΓòÉ 9.8. How do I use DosMon*() to stuff the kbd buf? ΓòÉΓòÉΓòÉ
  5269.  
  5270. Here's a mini app (all error handling, comments, etc. removed.) 
  5271.  
  5272. (also all this stuff to avoid compile warnings !!!!!). 
  5273.  
  5274. compile with: icc -Sm -Kabgioprx+ -Ss+ -W3 -Gs+ -Gf+ -O+ KEY.C
  5275. start with: detach key
  5276. stop with: F11 or CTRL-F10
  5277. test envir: OS/2 2.0GA+SP, C-Set++ CSD 22.
  5278. no other functionality.
  5279.  
  5280. orginal src part of my glorious DOS/OS2 1.x/OS2 2.0 keyboard roboter which 
  5281. inserts keys into the keyboard monitor queue controlled by an source file (mini 
  5282. language). 
  5283.  
  5284.    (C) Mario Semo 1777,1832,1967-92. 
  5285.  
  5286. ========= TOP OF FILE KEY.C ================ 
  5287.  
  5288. #define INCL_DOS
  5289. #define INCL_KBD
  5290. #define INCL_NOPM
  5291.  
  5292. #include<os2.h>
  5293. #include<stdio.h>
  5294. #include<conio.h>
  5295. #include<process.h>
  5296. #include<stdlib.h>
  5297. #include<string.h>
  5298.  
  5299. #define DosMonOpen  DOS16MONOPEN
  5300. #define DosMonClose DOS16MONCLOSE
  5301. #define DosMonReg   DOS16MONREG
  5302. #define DosMonRead  DOS16MONREAD
  5303. #define DosMonWrite DOS16MONWRITE
  5304.  
  5305. #define MONITOR_DEFAULT 0x0000
  5306. #define MONITOR_BEGIN   0x0001
  5307. #define MONITOR_END     0x0002
  5308.  
  5309. typedef SHANDLE HMONITOR;       /* hmon */
  5310. typedef HMONITOR *PHMONITOR;
  5311.  
  5312. #pragma pack(2)
  5313. typedef struct _MONIN {         /* mnin */
  5314.         USHORT cb;
  5315.         BYTE abReserved[18];
  5316.         BYTE abBuffer[108];
  5317. } MONIN;
  5318. typedef MONIN *PMONIN;
  5319.  
  5320. #pragma pack(2)
  5321. typedef struct _MONOUT {        /* mnout */
  5322.         USHORT cb;
  5323.         UCHAR buffer[18];
  5324.         BYTE abBuf[108];
  5325. } MONOUT;
  5326. typedef MONOUT *PMONOUT;
  5327.  
  5328. APIRET16 APIENTRY16 DosMonOpen(PSZ pszDevName, PHMONITOR phmon);
  5329. APIRET16 APIENTRY16 DosMonClose(HMONITOR hmon);
  5330. APIRET16 APIENTRY16 DosMonReg(HMONITOR hmon, PBYTE pbInBuf,
  5331.              PBYTE pbOutBuf, USHORT fPosition, USHORT usIndex);
  5332. APIRET16 APIENTRY16 DosMonRead(PBYTE pbInBuf, USHORT fWait,
  5333.                                PBYTE pbDataBuf,
  5334.                                PUSHORT pcbData);
  5335. APIRET16 APIENTRY16 DosMonWrite(PBYTE pbOutBuf, PBYTE pbDataBuf,
  5336.                                 USHORT cbData);
  5337.  
  5338. #define DosGetInfoSeg    DOS16GETINFOSEG
  5339. APIRET16 APIENTRY16 DosGetInfoSeg(PSEL pselGlobal, PSEL pselLocal);
  5340.  
  5341. #pragma pack(2)
  5342. typedef struct _GINFOSEG { /* gis */
  5343.         ULONG   time; ULONG   msecs; UCHAR   hour;
  5344.         UCHAR   minutes; UCHAR   seconds; UCHAR   hundredths;
  5345.         USHORT  timezone; USHORT cusecTimerInterval; UCHAR   day;
  5346.         UCHAR   month; USHORT  year; UCHAR   weekday;
  5347.         UCHAR   uchMajorVersion; UCHAR uchMinorVersion;
  5348.         UCHAR   chRevisionLetter; UCHAR   sgCurrent;
  5349.         UCHAR   sgMax; UCHAR   cHugeShift;
  5350.         UCHAR   fProtectModeOnly; USHORT pidForeground;
  5351.         UCHAR   fDynamicSched; UCHAR   csecMaxWait;
  5352.         USHORT  cmsecMinSlice; USHORT  cmsecMaxSlice;
  5353.         USHORT  bootdrive; UCHAR   amecRAS[32];
  5354.         UCHAR   csgWindowableVioMax; UCHAR   csgPMMax;
  5355. } GINFOSEG;
  5356. typedef GINFOSEG *PGINFOSEG;
  5357.  
  5358. static PGINFOSEG gdt;
  5359.  
  5360. #define MAKEPGINFOSEG(sel)  ((PGINFOSEG)MAKEP(sel, 0))
  5361. #define MAKEPLINFOSEG(sel)  ((PLINFOSEG)MAKEP(sel, 0))
  5362.  
  5363. #pragma pack(2)
  5364. typedef struct _keypacket
  5365.   {
  5366.    USHORT     mnflags;
  5367.    KBDKEYINFO cp;
  5368.    USHORT     ddflags;
  5369.   } KEYPACKET;
  5370.  
  5371.  
  5372. #define RELEASE     0x40
  5373. #define CTL_F10_KEY 103
  5374. #define F11_KEY     133
  5375.  
  5376. #pragma stack16(8192)
  5377. #pragma seg16(HKBD)
  5378. #pragma seg16(MONIN)
  5379. #pragma seg16(MONOUT)
  5380. #pragma seg16(KEYPACKET)
  5381.  
  5382. static HKBD KBDHandle = (HKBD)0;
  5383. static PGINFOSEG _Seg16 gdt;
  5384. static MONIN monInbuf = {0};
  5385. static MONOUT monOutbuf = {0};
  5386. static HEV hevThreadDone = (HEV)0;
  5387.  
  5388. static void _System keyboard_monitor(ULONG Dummy);
  5389.  
  5390. int main(int argc, char *argv[], char *envp[])
  5391. {
  5392.  SEL gdt_descriptor, ldt_descriptor;
  5393.  PID pidKeybrd;
  5394.  
  5395.  monInbuf.cb  = sizeof(MONIN);
  5396.  monOutbuf.cb = sizeof(MONOUT);
  5397.  
  5398.  DosGetInfoSeg(&gdt_descriptor, &ldt_descriptor);
  5399.  
  5400.  gdt = MAKEPGINFOSEG(gdt_descriptor);
  5401.  
  5402.  DosMonOpen ( "KBD$", &KBDHandle );
  5403.  
  5404.  DosCreateEventSem(NULL, &hevThreadDone,0,FALSE);
  5405.  
  5406.  if (DosCreateThread(&pidKeybrd, &keyboard_monitor, 0L, 2L, 12000L))
  5407.          DosExit(EXIT_PROCESS,0);
  5408.  
  5409.  DosWaitEventSem(hevThreadDone, (ULONG)SEM_INDEFINITE_WAIT);
  5410.  DosMonClose(KBDHandle);
  5411.  
  5412.  DosBeep(100,100);
  5413.  
  5414.  DosExit(EXIT_PROCESS,0);
  5415.  return(0);
  5416. }
  5417.  
  5418.  
  5419. static void _System keyboard_monitor(ULONG Dummy)
  5420. {
  5421.  KEYPACKET keybuff;
  5422.  USHORT count;
  5423.  
  5424.  DosSetPrty(PRTYS_THREAD, PRTYC_TIMECRITICAL,0, 0);
  5425.  
  5426.  DosMonReg( KBDHandle, (PBYTE)&monInbuf, (PBYTE)&monOutbuf,
  5427.             MONITOR_BEGIN, gdt->sgCurrent);
  5428.  
  5429.  DosSetPrty(PRTYS_THREAD, PRTYC_REGULAR,0, 0);
  5430.  
  5431.  for(keybuff.cp.chChar = 0; ; )
  5432.    {
  5433.     count = sizeof(keybuff);
  5434.     DosMonRead( (PBYTE)&monInbuf, IO_WAIT, (PBYTE)&keybuff, &count);
  5435.     if (!(keybuff.ddflags & RELEASE))
  5436.        {
  5437.         if(keybuff.cp.chChar == 0)
  5438.           {
  5439.            switch (keybuff.cp.chScan)
  5440.              {
  5441.               case CTL_F10_KEY   :
  5442.               case F11_KEY       :
  5443.                  DosPostEventSem(hevThreadDone);
  5444.                  DosExit(EXIT_THREAD,0);
  5445.                  break;
  5446.              }
  5447.           }
  5448.        }
  5449.     DosMonWrite((PBYTE)&monOutbuf,(PBYTE)&keybuff,count);
  5450.    }
  5451. }
  5452.  
  5453. Credit:  Mario Semo 
  5454.  
  5455.  
  5456. ΓòÉΓòÉΓòÉ 9.9. How do I determine what file system a drive uses? ΓòÉΓòÉΓòÉ
  5457.  
  5458. 16 bit:  DosQFsInfo().
  5459. 32 but:  DosQueryFSInfo()
  5460.  
  5461. The folling little 16 bit program produces the following output on my computer: 
  5462.  
  5463.  LOCAL  C:  FAT
  5464.  LOCAL  D:  HPFS
  5465.  LOCAL  E:  HPFS
  5466.  LOCAL  F:  FAT
  5467.  REMOTE P:  LAN   \\SERV1\C$
  5468.  REMOTE Q:  LAN   \\SERV1\D$
  5469.  REMOTE R:  LAN   \\SERV1\E$
  5470.  
  5471. Code.... 
  5472.  
  5473.  /* qdisk.c */
  5474.  #define INCL_NOPM
  5475.  #define INCL_DOS
  5476.  #include <os2.h>
  5477.  #include <stdio.h>
  5478.  #include <stdlib.h>
  5479.  
  5480.  
  5481.  void errorRC(USHORT rc)
  5482.  {
  5483.      char msg[256];
  5484.      USHORT bc;
  5485.      if(0 != (rc=DosGetMessage(NULL, 0, msg, sizeof(msg), rc,
  5486.                                "OSO001.MSG", &bc))) {
  5487.          printf("SYS%04u: Unable to access OSO001.MSG\n", rc);
  5488.      }
  5489.      else DosWrite(2, msg, bc, &bc);
  5490.  }
  5491.  
  5492.  void qdisk(char drv)
  5493.  {
  5494.      USHORT rc, len;
  5495.      char dev[3];
  5496.      void *buf;
  5497.      char *p;
  5498.  
  5499.      if(drv < 'C')
  5500.          return;
  5501.      sprintf(dev, "%c:", drv);
  5502.      buf = malloc(2048);
  5503.      len = 2048;
  5504.      rc = DosQFSAttach(dev, 0, FSAIL_QUERYNAME, buf, &len, 0L);
  5505.      if(rc){
  5506.          errorRC(rc);
  5507.          return;
  5508.      }
  5509.      switch((*(PUSHORT)buf)){
  5510.          case FSAT_CHARDEV  : printf("CHAR   "); break;
  5511.          case FSAT_PSEUDODEV: printf("DEV    "); break;
  5512.          case FSAT_LOCALDRV : printf("LOCAL  "); break;
  5513.          case FSAT_REMOTEDRV: printf("REMOTE "); break;
  5514.          default: printf("Unknown "); break;
  5515.      }
  5516.      p = buf;
  5517.      p += sizeof(USHORT);    /* itype */
  5518.      printf("%-3s ", p+sizeof(USHORT));
  5519.      p += (sizeof(USHORT) + (*(USHORT *)p) + 1);    /* cbName */
  5520.      printf("%-8s ", p+sizeof(USHORT));
  5521.      p += (sizeof(USHORT) + (*(USHORT *)p) + 1);    /* cbFSDName */
  5522.      if((*(USHORT *)p))                             /* cbFSAData */
  5523.          printf("%s", p+sizeof(USHORT));
  5524.      printf("\n");
  5525.      free(buf);
  5526.  }
  5527.  
  5528.  void cdecl main(void)
  5529.  {
  5530.      char drv;
  5531.      USHORT usDisk;
  5532.      ULONG ulDrives;
  5533.      DosQCurDisk(&usDisk, &ulDrives); /* gets current drive */
  5534.      for (drv = 'A'; drv <= 'Z'; drv++) {
  5535.          if (ulDrives & 1)              /* if the drive bit is set, */
  5536.              qdisk(drv);
  5537.          ulDrives >>= 1;
  5538.      }
  5539.  }
  5540.  
  5541. ps: DosQSysInfo() will return the max path length that your version of OS/2 
  5542. supports.  But since this API is specific to OS/2,  and not to a particular 
  5543. drive,  it does not answer your original question. 
  5544.  
  5545. Credit: Peter Fitzsimmons 
  5546.  
  5547.  
  5548. ΓòÉΓòÉΓòÉ 9.10. How do I get the error message from a DOS API call? ΓòÉΓòÉΓòÉ
  5549.  
  5550. For DOSAPI calls, you can issue a DosGetMessage as follows: 
  5551.  
  5552.    RC = DosXXXX(...);
  5553.    DosGetMessage(NULL,0,Msg,sizeof(Msg),RC,"OSO001.MSG",&Msg_Length);
  5554.  
  5555. Credit:  Ken Kahn 
  5556.  
  5557.  
  5558. ΓòÉΓòÉΓòÉ 9.11. How do I set an exception handler? ΓòÉΓòÉΓòÉ
  5559.  
  5560. /*
  5561.  * Simple example of an exception handler
  5562.  */
  5563.  
  5564. #define INCL_DOS
  5565. #include <os2.h>
  5566. #include <setjmp.h>
  5567. #include <stdio.h>
  5568. #include <string.h>
  5569.  
  5570. extern int main(void);
  5571.  
  5572.  /*
  5573.  * Exception registration record.  Stored on stack, with first
  5574.  * pointer to next registeration record, second pointer to
  5575.  * exception handler, and the rest defined by the author of
  5576.  * the exception handler.
  5577.  */
  5578.  
  5579. typedef struct {
  5580.   struct _EXCEPTIONREGISTRATIONRECORD * volatile prev_structure;
  5581.    _ERR * volatile ExceptionHandler;
  5582.    jmp_buf env;
  5583. } MYEXCEPTIONREGISTRATIONRECORD, *PMYEXCEPTIONREGISTRATIONRECORD;
  5584.  
  5585. /*
  5586.  * Exception handler that returns traps via longjmp().
  5587.  */
  5588.  
  5589. extern ULONG APIENTRY MyExceptionHandler
  5590.     (PEXCEPTIONREPORTRECORD pReportRecord,
  5591.     PEXCEPTIONREGISTRATIONRECORD pRegRecord,
  5592.     PCONTEXTRECORD pContextRecord, PVOID pReserved)
  5593. {
  5594.   ULONG rc = XCPT_CONTINUE_SEARCH;
  5595.  
  5596.   if (pReportRecord->ExceptionNum == XCPT_ACCESS_VIOLATION)
  5597.     longjmp(((PMYEXCEPTIONREGISTRATIONRECORD) pRegRecord)->env, -1);
  5598.  
  5599.   /*
  5600.    * If we return to here then we could not handle the exception.
  5601.    */
  5602.  
  5603.   return rc;
  5604. }
  5605.  
  5606. extern BOOL Trapper(PSZ psz)
  5607. {
  5608.   MYEXCEPTIONREGISTRATIONRECORD myExceptionRegRecord;
  5609.  
  5610.   /*
  5611.    * Insert my exception handler into the chain.
  5612.    */
  5613.  
  5614.   myExceptionRegRecord.prev_structure = NULL;
  5615.   myExceptionRegRecord.ExceptionHandler = MyExceptionHandler;
  5616.   DosSetExceptionHandler((PEXCEPTIONREGISTRATIONRECORD) &myExceptionRegRecord);
  5617.  
  5618.   if (setjmp(myExceptionRegRecord.env))
  5619.     goto OnException;
  5620.  
  5621.   /*
  5622.    * Now go about my business in safety.
  5623.    */
  5624.  
  5625.   if (strlen(psz))
  5626.     printf("Trapper says okay to '%s'\n", psz);
  5627.   else
  5628.     printf("Trapper says it is empty\n");
  5629.  
  5630.   /*
  5631.    * I'm done, so unchain my exception handler.
  5632.    */
  5633.  
  5634.   DosUnsetExceptionHandler((PEXCEPTIONREGISTRATIONRECORD)&myExceptionRegRecord)
  5635.  
  5636.   return TRUE;
  5637.  
  5638.   /*
  5639.    * The code below is only executed if a trap occurs.
  5640.    */
  5641.  
  5642. OnException:
  5643.   printf("Trapper says 'ouch!'\n");
  5644.  
  5645.   DosUnsetExceptionHandler((PEXCEPTIONREGISTRATIONRECORD)&myExceptionRegRecord)
  5646.  
  5647.   return FALSE;
  5648. }
  5649.  
  5650. extern int main()
  5651. {
  5652.   Trapper("Hello");
  5653.   Trapper(NULL);
  5654.   Trapper("");
  5655.   Trapper((PSZ) 42);
  5656.   Trapper("Goodbye");
  5657.  
  5658.   return 0;
  5659. }
  5660.  
  5661. Credit:  Dan Kehn 
  5662.  
  5663.  
  5664. ΓòÉΓòÉΓòÉ 9.12. How can I determine a diskette format and if a disk is in a drive? ΓòÉΓòÉΓòÉ
  5665.  
  5666. Let's have a snippet from one of my functions: 
  5667.  
  5668. The 'ifdef M_I386's mean CSet/2 
  5669.  
  5670. --- snip --- 
  5671.  
  5672. EXPORT int GetFileSysAttach ( char cDrv, PVOID pInfo, UnsInt cbInfo )
  5673. {
  5674. CHAR szFileSys [4];
  5675.  
  5676.   szFileSys [0] = (CHAR) toupper ( cDrv );
  5677.   szFileSys [1] = ':';
  5678.   szFileSys [2] = '\0';
  5679.  
  5680.   DosError ( EXCEPTION_DISABLE );
  5681.  
  5682. #ifdef M_I386
  5683.   Errno = DosQueryFSAttach ( szFileSys, 0, FSAIL_QUERYNAME, pInfo, &cbInfo );
  5684. #else
  5685.   Errno = DosQFSAttach ( szFileSys, 0, FSAIL_QUERYNAME, pInfo, &cbInfo, 0L );
  5686. #endif
  5687.  
  5688.   DosError ( EXCEPTION_ENABLE );
  5689.   return Errno ? -1 : 0;
  5690. }
  5691.  
  5692.  
  5693. EXPORT    int    GetFileSysInfo ( PSZ pszFileSys, PFSysInfo pfsi )
  5694. {
  5695. USHORT    idDrv;
  5696. FSALLOCATE fsal;
  5697. FSINFO    fsinfo;
  5698. #ifdef M_I386
  5699. PFSQBUFFER2 fsq = NULL;
  5700. #else
  5701. PFSQBUFFER  fsq = NULL;
  5702. PUSHORT     pus;
  5703. #endif
  5704. CHAR    hbuf [L_FILENAME];
  5705. PCHAR   pch;
  5706. #ifndef _MT
  5707. BOOL    fProt = ProtectedMode ();
  5708. #else
  5709. #define fProt TRUE
  5710. #endif
  5711.  
  5712.   idDrv = tolower ( *pszFileSys ) - ('a' - 1);
  5713.  
  5714.   DosError ( EXCEPTION_DISABLE );
  5715.  
  5716.   if ( ! (Errno = DosQFSInfo ( idDrv, 1, (PBYTE) &fsal, sizeof ( fsal ) )) )
  5717.     Errno = DosQFSInfo ( idDrv, 2, (PBYTE) &fsinfo, sizeof ( fsinfo ) );
  5718.  
  5719.   DosError ( EXCEPTION_ENABLE );
  5720.  
  5721.   if ( Errno )
  5722.   {
  5723.     if ( Errno == ERROR_NO_VOLUME_LABEL )
  5724.       memset ( &fsinfo, 0, sizeof (fsinfo) );
  5725.     else
  5726.       return -1; // No disk inserted
  5727.   }
  5728.  
  5729.   if ( fProt )
  5730.   {
  5731.     if ( GetFileSysAttach ( (CHAR) (idDrv + 'a' - 1), hbuf, L_FILENAME ) )
  5732.       return -1;
  5733.  
  5734. #ifdef M_I386
  5735.     fsq = (PFSQBUFFER2) hbuf;
  5736. #else
  5737.     fsq = (PFSQBUFFER) hbuf;
  5738. #endif
  5739.   }
  5740.  
  5741.   DosError ( EXCEPTION_ENABLE );
  5742.  
  5743.   ...
  5744.  
  5745. --- snap --- 
  5746.  
  5747. I think it's more than you want, the fsal-struct contains the size information, 
  5748. but I think if you want to retrieve ALL information about a logical drive 
  5749. that's what you need. 
  5750.  
  5751. Credit:  Rainer Prem 
  5752.  
  5753.  
  5754. ΓòÉΓòÉΓòÉ 9.13. What do all those keywords mean when making a DLL? ΓòÉΓòÉΓòÉ
  5755.  
  5756. Okay, with the help of some of my peers, I've solved the mystery surrounding 
  5757. the seemingly redundant SINGLE/MULTIPLE and SHARED/NONSHARED attributes. 
  5758.  
  5759. First, some prep up work... 
  5760.  
  5761. Every DLL needs and gets a data segment ("automatic data segment"). It is the 
  5762. place where the DLL stores all its STATIC data--basically the data declared in 
  5763. the DLL module but declared outside any function AND (I venture) variables 
  5764. declared STATIC within a DLL function as well. The STACK is NOT!! part of a 
  5765. DLL's automatic data segment (thoug it seems to be for an EXE). The stack that 
  5766. is used when 'running' a DLL function is that of the calling thread. 
  5767.  
  5768. Now here's the clincher... 
  5769.  
  5770. DLLs CAN ALSO HAVE ADDITIONAL DATA SEGMENTS!! (as can EXEs, I imagine) 
  5771.  
  5772. Bingo! Now we understand why there are two different sets of 
  5773. attributes--specifically, NONE/SINGLE/MULTIPLE and SHARED/NONSHARED. Though 
  5774. they basically do the same thing, they APPLY to different things. 
  5775.  
  5776. NONE/SINGLE/MULTIPLE 
  5777.           applies to the one and only default data segment. This is the data 
  5778.           segment that is "automatically" created for your DLL (or EXE). I 
  5779.           imagine that for 90% of the DLLs written, this is the only type of 
  5780.           data segment that exists. Whether or not this data segment is shared 
  5781.           or whether a private copy is created for each linking application is 
  5782.           A DIRECT FUNCTION OF THIS ATTRIBUTE--'SINGLE'=it's shared, 
  5783.           'MULTIPLE'=everyone get's his own copy. 
  5784.  
  5785. SHARED/NONSHARED 
  5786.           This SETS THE DEFAULT!! FOR ALL DATA SEGMENTS other than the 
  5787.           "automatic" data segment. DEFAULT is the key word, because you can 
  5788.           specify, through the SEGMENTS statement, the characteristics of these 
  5789.           additional segments on an individual basis (which in all certainty, 
  5790.           override this value.) 
  5791.  
  5792. So...to answer my own question 
  5793.  
  5794. >could {someone} explain what the following statements would
  5795. >produce:
  5796. >
  5797. >        DATA MULTIPLE SHARED
  5798.  
  5799. Every application which links to the DLL will have it's own private copy of the 
  5800. automatic data segment. If the DLL has no additional data segments, the SHARED 
  5801. keyword is meaningless and can be omitted. If there are additional data 
  5802. segments, only one copy of each will exist and they will be shared by all 
  5803. applications (unless a SEGMENTS statement follows which overrides this default 
  5804. for a specific segment) 
  5805.  
  5806. >        or
  5807. >        DATA SINGLE NONSHARED
  5808.  
  5809. Every application which links to the DLL will share a single automatic data 
  5810. segment (hence, each app that affects the DLL STATIC data will affect it for 
  5811. all apps). If there are no additional data segments, the NONSHARED keyword is 
  5812. meaningless and can be omitted. If there are, a private copy will be created 
  5813. for each app (unless overriden by a SEGMENTS statement). 
  5814.  
  5815. Note that in the absence of BOTH a SINGLE/MUTLIPLE and SHARED/NONSHARED 
  5816. keyword, the default is for ALL data segments (automatic and additional ones) 
  5817. to be shared (i.e., only one copy). In the absence of one OR the other, but not 
  5818. both, the property of ALL data segments are mandated by the single keyword. In 
  5819. other words, 
  5820.  
  5821. DATA SINGLE
  5822.  and
  5823. DATA SHARED
  5824.  
  5825. do the same exact thing. 
  5826.  
  5827. Credit:  John Cortell 
  5828.  
  5829.  
  5830. ΓòÉΓòÉΓòÉ 9.14. Where can I find serial port sample code? ΓòÉΓòÉΓòÉ
  5831.  
  5832. Q)  Does anyone have any C sample code showing how to use the serial port under 
  5833. OS/2 using DosOpen() and DosDevIoCtl()? 
  5834.  
  5835. A) As a matter of fact, yes.  :-) 
  5836.  
  5837. -=-= extracted from a silly & specialized program =-=-=-=-==-=-=
  5838.  
  5839. /* dtp.c -- D-dial Terminal Program: the first hack */
  5840.  
  5841. //-- an annoying detail
  5842.  
  5843. #define INCL_BASE
  5844. #define INCL_DOSDEVIOCTL  /* docs lie, this is NOT included by BASE */
  5845. #include <os2.h>
  5846.  
  5847. //-- initialization (in main() as written)
  5848.  
  5849.     HFILE portFd;
  5850.     ULONG action;
  5851.  
  5852.     if (DosOpen("COM1", &portFd, &action, 0, FILE_NORMAL, FILE_OPEN,
  5853.       OPEN_ACCESS_READWRITE | OPEN_SHARE_DENYREADWRITE, 0) != 0) {
  5854.         fprintf(stderr, "Open of COM1 failed\n");
  5855.         goto error0;
  5856.     }
  5857.  
  5858.     {    DCBINFO di;
  5859.         ULONG dummy;
  5860.  
  5861.         dummy = sizeof(di);
  5862.         if (DosDevIOCtl(portFd, IOCTL_ASYNC, ASYNC_GETDCBINFO, 0, 0, 0,
  5863.                         &di, sizeof(di), &dummy) != 0)
  5864.             fprintf(stderr, "DosDevIOCtl failed\n");
  5865.         else {
  5866.             fprintf(stderr, "Timeouts: read = %u, write = %u\n",
  5867.                     di.usWriteTimeout, di.usReadTimeout);
  5868.             fprintf(stderr, "Flag bytes: %02x, %02x, %02x\n",
  5869.                     di.fbCtlHndShake, di.fbFlowReplace, di.fbTimeout);
  5870.         }
  5871.         di.fbTimeout = (di.fbTimeout & ~(3 << 1)) | (2 << 1);
  5872.                                           /* rcv = wait-for-something */
  5873.         di.usReadTimeout = 250;
  5874.         dummy = sizeof(di);
  5875.         if (DosDevIOCtl(portFd, IOCTL_ASYNC, ASYNC_SETDCBINFO,
  5876.                         &di, sizeof(di), &dummy, 0, 0, 0) != 0)
  5877.             fprintf(stderr, "DosDevIOCtl failed to set parameters!\a\n");
  5878.     }
  5879.  
  5880.     if (initSerialOutput(portFd) != 0)
  5881.         goto error1;
  5882.  
  5883. //-- the "running" variable is sort of a relic, I think
  5884.  
  5885.     running = 1;
  5886.     if (_beginthread(serialInputThread, 0, 8192, (void *)portFd) < 0) {
  5887.         fprintf(stderr, "can't start serial input thread\n");
  5888.         goto error2;
  5889.     }
  5890.  
  5891.     if (_beginthread(serialOutputThread, 0, 8192, (void *)portFd) < 0) {
  5892.         fprintf(stderr, "can't start serial output thread\n");
  5893.         goto error2;
  5894.     }
  5895.  
  5896. //-- wrapup code
  5897.  
  5898.     shutdownSerialOutput();
  5899.     DosClose(portFd);
  5900.  
  5901. //-- the rest of this lives outside of main()...
  5902.  
  5903. //-- input side: gory details omitted
  5904.  
  5905. //-- the port has been setup in "wait for something" mode, so we can request
  5906. //-- more than one character at a time without blocking until the buffer is
  5907. //-- full.  At least, I *think* that's working now: this is used with 300 baud
  5908. //-- systems, so it's hard to tell <g>.  At least it isn't blocking until the
  5909. //-- buffer is filled...
  5910.  
  5911. /*  serialInputThread -- reads port, writes to text window
  5912. *
  5913. *   arg is the port's handle for reading
  5914. */
  5915. void serialInputThread(void *arg)
  5916. {
  5917.     HFILE inFd = (long)arg;
  5918.     FILE *logFile;
  5919.     UCHAR buf[10];
  5920.  
  5921.     ParserState ps = {0};
  5922.  
  5923.     logFile = fopen("dtp.log", "ab");
  5924.  
  5925.     for ( ; ; )
  5926.     {
  5927.         ULONG n;
  5928.         if (DosRead(inFd, buf, 10, &n) == 0)
  5929.         {
  5930.             ULONG i;
  5931.             for (i = 0; i <n; ++i)
  5932.             {
  5933.                 if (logFile != 0)
  5934.                     putc(buf[i], logFile);
  5935.                 if (runParser(&ps, buf[i]) != 0)
  5936.                     postChar(buf[i]);
  5937.             }
  5938.         }
  5939.     }
  5940. }
  5941.  
  5942. /* output side: I rather like this arrangement using queues
  5943.    except that I'd prefer an anonymous queue.
  5944.    For this, having the queue named in the
  5945.    filesystem's name space is at best a minor annoyance. */
  5946.  
  5947. /* * * *    SerialOutput subsystem
  5948. */
  5949.  
  5950. #define MAX_CHUNK_SIZE 50
  5951.  
  5952. typedef struct
  5953. {
  5954.     USHORT nUsed;
  5955.     UCHAR buf[MAX_CHUNK_SIZE];
  5956. } SO_CHUNK;
  5957.  
  5958. #define NUM_SO_CHUNKS 6
  5959.  
  5960.  
  5961. HQUEUE soQueue, freeQueue;
  5962.  
  5963.  
  5964. int initSerialOutput (HFILE outFd)
  5965. {
  5966.     (void) outFd;     /* reserved for more general version */
  5967.  
  5968.     if (DosCreateQueue
  5969.        (&soQueue, QUE_FIFO, "\\queues\\dtp\\soQueue") != 0)
  5970.     {
  5971.         fprintf(stderr, "Failed to create serial output queue\n");
  5972.         goto error0;
  5973.     }
  5974.     if (DosCreateQueue
  5975.        (&freeQueue, QUE_FIFO, "\\queues\\dtp\\freeQueue") != 0)
  5976.     {
  5977.         fprintf(stderr, "Failed to create serial free queue\n");
  5978.         goto error1;
  5979.     }
  5980.     {   SO_CHUNK *p = malloc(sizeof(SO_CHUNK) * NUM_SO_CHUNKS);
  5981.         int i;
  5982.         if (p == 0)
  5983.         {
  5984.             fprintf(stderr,
  5985.             "Failed to allocate memory for serial chunks\n");
  5986.             goto error1;
  5987.         }
  5988.         for (i = NUM_SO_CHUNKS; 0 < i; --i)
  5989.             if (DosWriteQueue(freeQueue, 0, sizeof(SO_CHUNK), p++, 0)
  5990.             != 0)
  5991.             {
  5992.                 fprintf(stderr, "Failed to initialize free queue\n");
  5993.                 goto error1;
  5994.             }
  5995.     }
  5996.  
  5997.     return 0;
  5998.  
  5999. error1:
  6000.     DosCloseQueue(soQueue);
  6001. error0:
  6002.     return -1;
  6003. }
  6004.  
  6005.  
  6006. void shutdownSerialOutput(void)
  6007. {
  6008.     DosCloseQueue(freeQueue);
  6009.     DosCloseQueue(soQueue);
  6010. }
  6011.  
  6012.  
  6013. void writeSerial(UCHAR const *buf, USHORT n)
  6014. {
  6015.  
  6016.     while (0 < n)
  6017.     {
  6018.         REQUESTDATA rd;
  6019.         ULONG dataLength;
  6020.         PVOID data;
  6021.         BYTE priority;
  6022.  
  6023.         if (DosReadQueue(freeQueue, &rd, &dataLength, &data,
  6024.                          0, DCWW_WAIT, &priority, 0) == 0)
  6025.         {
  6026.             SO_CHUNK *sc = data;
  6027.             USHORT m = MAX_CHUNK_SIZE;
  6028.             if (n < m)
  6029.                 m = n;
  6030.             memcpy(sc->buf, buf, m);
  6031.             sc->nUsed = m;
  6032.             DosWriteQueue(soQueue, 0, sizeof(SO_CHUNK), sc, 0);
  6033.             buf += m;
  6034.             n -= m;
  6035.         }
  6036.     }
  6037. }
  6038.  
  6039.  
  6040. void writeSerialString(UCHAR const *buf)
  6041. {
  6042.     writeSerial(buf, strlen(buf));
  6043. }
  6044.  
  6045.  
  6046. void serialOutputThread(void *arg)
  6047. {
  6048.     HFILE outFd = (long)arg;
  6049.     REQUESTDATA rd;
  6050.     ULONG dataLength;
  6051.     PVOID data;
  6052.     BYTE priority;
  6053.  
  6054.     for ( ; ; )
  6055.     {
  6056.         if (DosReadQueue(soQueue, &rd, &dataLength, &data,
  6057.                          0, DCWW_WAIT, &priority, 0) == 0)
  6058.         {
  6059.             if (rd.ulData == 0) {     /* simple data block */
  6060.                 ULONG dummy;
  6061.                 SO_CHUNK *sc = data;
  6062.                 DosWrite(outFd, sc->buf, sc->nUsed, &dummy);
  6063.                 DosWriteQueue(freeQueue, 0, sizeof(SO_CHUNK), sc, 0);
  6064.             }
  6065.             else
  6066.                 ;  /* anything else is a test, ignore it */
  6067.         }
  6068.     }
  6069. }
  6070.  
  6071. The intention was that control messages could be posted to the queue using null 
  6072. data packets (passing the actual message in the REQUESTDATA.ulData field); 
  6073. these would allow for controlling the port's baud rate and other settings. 
  6074. This seems to work under 2.0, and even appears to be intended to work (Deitel & 
  6075. Kogan's description), but I haven't done anything with it yet, as you can see. 
  6076. Haven't needed the facility yet... 
  6077.  
  6078. Credit:  Martin Maney 
  6079.  
  6080.  
  6081. ΓòÉΓòÉΓòÉ 9.15. How do I disable <Ctrl><Alt><Del>? ΓòÉΓòÉΓòÉ
  6082.  
  6083. You need to do a DosDevIOCtl with Category 4, Function 56. Use a 0xFFFF for the 
  6084. Hot Key ID.  Set the other values to 0. This will toggle <Ctrl><Alt><Del> and 
  6085. <Ctrl><Esc> and <Alt><Esc> on then off on the next call. Note that this does a 
  6086. little more than what you want since it also disables <Ctrl><Esc> and 
  6087. <Alt><Esc> so you may run into problems getting around your different sessions 
  6088. when you've got it disabled. Other than this there is NO WAY to disable 
  6089. <Ctrl><Alt><Del> under OS/2 and believe me, people have tried! 
  6090.  
  6091. Credit:  Mike Brown 
  6092.  
  6093.  
  6094. ΓòÉΓòÉΓòÉ 9.16. Why doesn't printf() produce output when I expect it to? ΓòÉΓòÉΓòÉ
  6095.  
  6096. For historical reasons, most Unix C libraries' stdio default to using line 
  6097. buffered streams, whereas most DOS and OS/2 C libraries' stdio default to using 
  6098. fully buffered streams.  ANSI C species that standard output should be line 
  6099. buffered when connected to an interactive device, but not all libraries are 
  6100. ANSI compliant.  You can control the buffering algorithm used for a particular 
  6101. stream with the setvbuf() function. 
  6102.  
  6103. If you didn't understand that paragraph, read on. 
  6104.  
  6105. printf() is part of the Standard I/O (stdio) library, which uses buffered 
  6106. streams for file IO.  ANSI C specifies three algorithms for deciding when to 
  6107. flush the buffer (i.e. when to print buffered data to the file): 
  6108.  
  6109. o not buffered.  Data is flushed to the file as soon as possible, usually 
  6110.   immediately after being received. 
  6111. o line buffered.  Data is flushed to the file when a newline is received (and 
  6112.   the newline is also flushed). 
  6113. o fully buffered.  Data is flushed to the file when the buffer is full. 
  6114.  
  6115. Buffered data is always flushed when the stream is closed or when fflush() is 
  6116. called.  Since standard output is flushed when main() exits, all data printed 
  6117. with printf() will appear at that time, if it has not already.  However, ANSI C 
  6118. does not require that a stream be flushed when scanf() is called on it. 
  6119. Therefore, if you print to a fully buffered stream and then request input on 
  6120. it, it is likely that the input will be read before the printed data appears. 
  6121.  
  6122. You can control the buffering algorithm used for a particular stream with the 
  6123. setvbuf() function.  For example, the statement setvbuf(stdout, NULL, _IOLBF, 
  6124. BUFSIZ) sets standard output to be line-buffered, which is what most Unix 
  6125. programmers expect.  Any decent C reference will cover all of this material. 
  6126.  
  6127. [Colin Jensen...] 
  6128.  
  6129. After reading one too many bug reports about this phenomena, the gcc/2 
  6130. maintainer changed its stdout to not-buffered whenever stdout is interactive. 
  6131. When stdout is sent to a pipe or file, stdout is still fully-buffered. 
  6132.  
  6133.  
  6134. ΓòÉΓòÉΓòÉ 9.17. How do I write an OS/2 device driver? ΓòÉΓòÉΓòÉ
  6135.  
  6136. The preferred method is to buy the OS/2 device driver kit (DDK) from IBM.  It 
  6137. contains samples for display, printer, SCSI, and other drivers. You can develop 
  6138. kernel and PM drivers.    NOTE:  The kernel debugger comes with the IBM Toolkit, 
  6139. sold separately. 
  6140.  
  6141. There's a book called Writing OS/2 2.0 Device Drivers in C from 
  6142. Van Nostrand-Reinhold and also IBM's flood of printed material. 
  6143.  
  6144.  
  6145. Related Information:
  6146.  
  6147. What are good reference books for programming in OS/2 and PM?
  6148.  
  6149.  
  6150. ΓòÉΓòÉΓòÉ 9.18. How do I change the master environment? ΓòÉΓòÉΓòÉ
  6151.  
  6152. Quick and simple answer: you don't. 
  6153.  
  6154. In OS/2 it is literally impossible for you to change the master environment 
  6155. from one of your programs.    To be able to do so would fatally disrupt the 
  6156. programming paradigm that has existed for ages:  Your program does not alter 
  6157. the master environment. Your program is the slave, not the master.  Therefore, 
  6158. no capability was built into OS/2 to facilitate this. 
  6159.  
  6160. There is, however, a kludge. 
  6161.  
  6162. As you know, a .CMD file can alter the master environment.  This is the nature 
  6163. of batch files (ok, so I'm a MS-DOG dinosaur and still call them batch files 
  6164. instead of command files or scripts).  Therefore, you can place a sequence of 
  6165. commands in the batch file that will take your program's output and alter the 
  6166. environment of your current shell. 
  6167.  
  6168. That's as close as you are gonna get to the master environment.  You can always 
  6169. create your own sort of environment variables, in the form of shared memory or 
  6170. named pipes. 
  6171.  
  6172.  
  6173. ΓòÉΓòÉΓòÉ 9.19. What is the best way to communicate between processes? ΓòÉΓòÉΓòÉ
  6174.  
  6175. There is more than one way - and you get to decide which is right for you! 
  6176.  
  6177. Shared Memory 
  6178.  
  6179. Shared memory is pretty self-explanatory.  It is a memory segment that is 
  6180. allocated by one program, and then made available to other programs. When all 
  6181. the programs are done with it, then it is disposed of.  You can name shared 
  6182. memory.  So if you want two programs to communicate, then let them look for 
  6183. memory with the same name and communicate that way. 
  6184.  
  6185. Named Pipes 
  6186.  
  6187. Named pipes are a lot like shared memory, but think of a named pipe as a file 
  6188. instead of a single block of memory.  Each process can create, read, write, and 
  6189. destroy a named pipe, much like you can a file. 
  6190.  
  6191. The difference between named pipes and shared memory is that a named pipe link 
  6192. is hot; With shared memory, data can be left in (as a sleeper, if you will), 
  6193. process 1 exits, process 2 accesses the data in memory, then deallocates the 
  6194. memory.  With shared memory, a process doesn't even have to exist to leave a 
  6195. message for another process. 
  6196.  
  6197. Queues 
  6198.  
  6199. An OS/2 queue is either a standard First-In First-Out (FIFO) queue 
  6200. data/operation structure, a LIFO structure, or a user-based-priority structure. 
  6201. However, OS/2 makes it unique because more than one process (or thread) can 
  6202. write to this queue. 
  6203.  
  6204.  
  6205. Related Information:
  6206.  
  6207. What is the best way to communicate between threads?
  6208.  
  6209.  
  6210. ΓòÉΓòÉΓòÉ 9.20. What is the best way to communicate between threads? ΓòÉΓòÉΓòÉ
  6211.  
  6212. The best way to communicate between threads is sometimes also the best way to 
  6213. communicate between processes.  However, when communicating between threads you 
  6214. can utilize two (very important) techniques: 
  6215.  
  6216. Semaphores 
  6217.  
  6218. In order to share application resources, and not write to the same space at the 
  6219. same time, you have to have some kind of flags that tell the thread when it 
  6220. should stop, when it should keep on going, and so on. Semaphores provide this 
  6221. capability.  Semaphores are not for passing data.  They merely exist as simple 
  6222. flags between threads and you should treat them as such. 
  6223.  
  6224. Global Variables 
  6225.  
  6226. "Hey Jeff - I thought this was supposed to be about nifty OS/2-specific 
  6227. tricks!"  It is!  You can now use those old nasty things, global variables, in 
  6228. new ways.  In conjunction with semaphores, you can pass data very easily 
  6229. between threads with global variables.  Here's a simple example: 
  6230.  
  6231.  1. Create a global variable called PassData. 
  6232.  2. Create a semaphore called OkToPassData. 
  6233.  3. Create a semaphore called DataPassed. 
  6234.  4. Have two threads work at the same time: 
  6235.  
  6236.     a. If the semaphore DataPassed is true: 
  6237.  
  6238.        1. Set the semaphore OkToPassData to false. 
  6239.        2. Read the data in the global. 
  6240.        3. Set the semaphore DataPassed to false. 
  6241.        4. Set the semaphore OkToPassData to true. 
  6242.  
  6243.     b. When a thread wants to pass data, wait for the semaphore to be clear. 
  6244.     c. Set the semaphore OkToPassData to false. 
  6245.     d. Put the data in the global. 
  6246.     e. Set the semaphore DataPassed to true. 
  6247.     f. Set the semaphore OkToPassData to true. 
  6248.  
  6249. Of course, there are issues of deadlock and other such nonsense that corporate 
  6250. chaps get paid to consider, but that's beyond the scope of this document. 
  6251.  
  6252.  
  6253. Related Information:
  6254.  
  6255. What is the best way to communicate between processes?
  6256.  
  6257.  
  6258. ΓòÉΓòÉΓòÉ 9.21. How to I write an IFS? ΓòÉΓòÉΓòÉ
  6259.  
  6260. Starting with Issue #3, EDM/2 started carrying a series about writing an IFS. 
  6261.  
  6262.  
  6263. ΓòÉΓòÉΓòÉ 9.22. How do I interface with OS/2's SCSI support? ΓòÉΓòÉΓòÉ
  6264.  
  6265. A complete description and sample code can be found at ftp archive; 
  6266.  
  6267. reseq.regent.e-technik.tu-muenchen.de 
  6268.  
  6269. in /pub/comp/os/os2/drivers/source/scsipg.zip. 
  6270.  
  6271.  
  6272. ΓòÉΓòÉΓòÉ 9.23. How do I program full-screen graphics? ΓòÉΓòÉΓòÉ
  6273.  
  6274. Several compilers come with their own VGA graphics libraries.  A 3rd party 
  6275. developer has even developed an SVGA library (with drivers) for emx/gcc. 
  6276.  
  6277. Full-screen graphics programming is nearly identical to full-screen DOS 
  6278. graphics programming, with the notable exception that you must lock and unlock 
  6279. the screen under OS/2 before you can use it. 
  6280.  
  6281.  
  6282. ΓòÉΓòÉΓòÉ 9.24. How do I program MMPM/2 programs? ΓòÉΓòÉΓòÉ
  6283.  
  6284. IBM has created the MMPM/2 toolkit just for that.  However, if that is too much 
  6285. trouble for you, there is a simple REXX interface to MMPM/2 available in OS/2 
  6286. 2.1. 
  6287.  
  6288. IBM's Ultimedia Builder/2, Ultimedia Perfect Image/2, and Ultimedia Workplace/2 
  6289. are all in beta and scheduled to be released soon. 
  6290.  
  6291. For the Emx/GCC enviroment there is the mm4emx package by Marc Van Woerkom. 
  6292. mm4emx is freeware. All header and lib files included. 
  6293.  
  6294.  
  6295. ΓòÉΓòÉΓòÉ 9.25. How do I peripheral memory or an I/O port? ΓòÉΓòÉΓòÉ
  6296.  
  6297. The basic thing to do is either mark it as IOPL or surround it in a 16-bit 
  6298. module.    emx/gcc and other compilers include some macros and functions to assist 
  6299. you in doing this. 
  6300.  
  6301. Check the file IOPL32.ZIP at ftp.cdrom.com:/pub/os2/os2_x/programs 
  6302.  
  6303.  
  6304. ΓòÉΓòÉΓòÉ 10. Porting ΓòÉΓòÉΓòÉ
  6305.  
  6306. This section covers all aspects of porting programs. 
  6307.  
  6308.  
  6309. ΓòÉΓòÉΓòÉ 10.1. How do I port my DOS keyboard TSR to OS/2? ΓòÉΓòÉΓòÉ
  6310.  
  6311. Use keyboard monitors (for fullscreen sessions) or hooks for the PM session. 
  6312.  
  6313.  
  6314. ΓòÉΓòÉΓòÉ 10.2. How can I simulate (Unix feature) under OS/2? ΓòÉΓòÉΓòÉ
  6315.  
  6316.  1. fork 
  6317.  2. fork/exec 
  6318.  3. select 
  6319.  4. job control 
  6320.  
  6321. A working version of select() is included with the emx/gcc libraries. See the 
  6322. emx/gcc documentation for more information on its usage. 
  6323.  
  6324. A working version of fork() comes with the emx/gcc libraries.  The author 
  6325. cautions that this is not the way to multitask, though, because it eats up a 
  6326. lot of resources (since it literally duplicates the current process, leaving 
  6327. everything but the PID unchanged).  _beginthread() is the suggested solution if 
  6328. at all possible. 
  6329.  
  6330.  
  6331. ΓòÉΓòÉΓòÉ 10.3. How can I recompile public domain/shareware source code for OS/2? ΓòÉΓòÉΓòÉ
  6332.  
  6333. Most publicly available OS/2 programs come with binaries (since there is 
  6334. currently only one OS/2 architecture).  If you are porting source code from 
  6335. another system (for example, Unix), you will first need to acquire a compiler. 
  6336. See section 1 for information on compilers; in particular, note that the GNU C 
  6337. compiler is available. 
  6338.  
  6339. You should realize that many publicly available programs have already been 
  6340. ported to OS/2.  Check the many FTP sites carrying OS/2 programs before you 
  6341. reinvent any wheels (the OS/2 User's FAQ contains information on FTP site). 
  6342.  
  6343. Most Unix applications (through the use of emx/gcc) port with extreme ease; DOS 
  6344. and Windows applications are a tougher problem, and require many changes before 
  6345. they can be recompiled as a native OS/2 program. 
  6346.  
  6347. (It is interesting to note that MicroSoft C v6.0 will compile bound OS/2 
  6348. programs, which will run under DOS and OS/2 without modification.) 
  6349.  
  6350.  
  6351. Related Information:
  6352.  
  6353. How can I port my DOS program to OS/2?
  6354. How can I port my Windows program to OS/2?
  6355.  
  6356.  
  6357. ΓòÉΓòÉΓòÉ 10.4. How can I port my DOS program to OS/2? ΓòÉΓòÉΓòÉ
  6358.  
  6359. To the first approximation, you don't have to --- OS/2 2.x's DOS support is 
  6360. excellent, and your DOS program will probably just work; similarly, OS/2 2.x 
  6361. supports Windows 3.0 (and soon 3.1) programs.  See the OS/2 User's FAQ for 
  6362. details. 
  6363.  
  6364. [That was Barry Jaspan's opinion.  I believe that you should make every effort 
  6365. to recompile your existing DOS programs for OS/2 2.x.  They will run faster in 
  6366. many cases, and both (a) use less memory and (b) be able to use more memory 
  6367. than their DOS counterparts. - Jeff] 
  6368.  
  6369. If you truly want to port your DOS program over to OS/2, then study the 
  6370. libraries available to you.  The core code (if you wrote it correctly) will 
  6371. probably not change much.  You will just have to change the user interface 
  6372. stuff. 
  6373.  
  6374. If your program is a real simple one that uses standard input and output, then 
  6375. you will probably not make very many changes to your program when converting it 
  6376. to OS/2. 
  6377.  
  6378. You should also realize that neato and nifty DOS tricks (like grabbing an 
  6379. interrupt whenever you feel like it, or writing directly to almost anywhere) 
  6380. are completely out of the question. 
  6381.  
  6382.  
  6383. Related Information:
  6384.  
  6385. How can I port my Windows program to OS/2?
  6386.  
  6387.  
  6388. ΓòÉΓòÉΓòÉ 10.5. How can I port my Windows program to OS/2? ΓòÉΓòÉΓòÉ
  6389.  
  6390. A tool called Mirrors is available from Micrographx.  It does not currently 
  6391. support Windows 3.1-specific programs and calls.  (although you *can* call the 
  6392. functions in the new 3.1 DLLs) 
  6393.  
  6394. o Rough ports can be done in under 1 day, but a detailed port still costs you a 
  6395.   lot of effort. 
  6396. o The ported application is heavily dependent on the underlying OS/2 system. 
  6397.  
  6398. There are also several toolkits available that allow you to make calls to a 
  6399. common API library, and your source will work across the two platforms without 
  6400. any changes at all. 
  6401.  
  6402. However, if you want to bite the bullet and port it, then be prepared to make a 
  6403. lot of changes.  Just like porting regular DOS programs, you will have to scrap 
  6404. most, if not all, of your user interface.  Your core code, if modular and 
  6405. abstract enough, should come through the port relatively unscathed. 
  6406.  
  6407. SMART - by One-up Corp is also available on Developers Connection CD. 
  6408.  
  6409.  
  6410. Related Information:
  6411.  
  6412. How can I port my DOS program to OS/2?
  6413.  
  6414.  
  6415. ΓòÉΓòÉΓòÉ 11. Miscellaneous ΓòÉΓòÉΓòÉ
  6416.  
  6417. This section covers questions not covered in previous sections. 
  6418.  
  6419.  
  6420. ΓòÉΓòÉΓòÉ 11.1. Is OS/2 suitable for real time programs? ΓòÉΓòÉΓòÉ
  6421.  
  6422. Yes!  There is a special priority you can assign your programs 
  6423. (ForegroundServer Mode) via DosSetPriority() which will give your process 
  6424. (note, not thread, but process) the maximum allowable CPU time. 
  6425.  
  6426. Another route is to use DosEnterCritSec()/DosExitCritSec().  Calling the former 
  6427. will disable thread switching (hopefully for a short period of time), and 
  6428. calling the latter will enable thread switching again. 
  6429.  
  6430.  
  6431. ΓòÉΓòÉΓòÉ 11.2. What is available for multimedia programming under OS/2? ΓòÉΓòÉΓòÉ
  6432.  
  6433. The OS/2 2.x Multimedia package is now available.  Call the IBM Multimedia 
  6434. office at (800) 426-9402 ext. 150. 
  6435.  
  6436.  
  6437. ΓòÉΓòÉΓòÉ 11.3. What is available for AI/neural net programming under OS/2? ΓòÉΓòÉΓòÉ
  6438.  
  6439. LISP and XScheme are available from cdrom.com.  There are also some AI/neural 
  6440. net tools listed in tinf31.zip. 
  6441.  
  6442.  
  6443. Related Information:
  6444.  
  6445. Programming language availability
  6446.  
  6447.  
  6448. ΓòÉΓòÉΓòÉ 11.4. Special software offers ΓòÉΓòÉΓòÉ
  6449.  
  6450. Here are some of the OS/2 software products that represent particularly good 
  6451. values.  Most prices do not include shipping and handling. 
  6452.  
  6453. o Borland C++ for OS/2.  Available from Below Zero in Calgary (phone 
  6454.   800-461-2777, 403-547-0669, or FAX 403-547-1018) for about $136 U.S., 
  6455.   including shipping.  Add GST in Canada.  Below Zero will export outside North 
  6456.   America. 
  6457.  
  6458. o IBM PL/I.  Not everyone is a PL/I programmer, but IBM is offering free copies 
  6459.   of Workframe/2 with every purchase and free product videos. Phone 
  6460.   800-426-3346 ext. STL10 for more information on the two packages available. 
  6461.  
  6462. (Quoted almost directly from OS/2 General FAQ) 
  6463.  
  6464.  
  6465. ΓòÉΓòÉΓòÉ 11.5. Technical Support ΓòÉΓòÉΓòÉ
  6466.  
  6467. How can I get answers to my OS/2 questions? 
  6468.  
  6469. If your question is not answered in this List, post a note to the appropriate 
  6470. Usenet conference: 
  6471.  
  6472. Newsgroup                           Description 
  6473. comp.os.os2.advocacy                deals with opinions and speculation 
  6474. comp.os.os2.announce                carries important OS/2 announcements 
  6475. comp.os.os2.apps                    carries discussions related to finding or 
  6476.                                     using any application running under OS/2 
  6477. comp.os.os2.beta                    explores beta releases of OS/2 
  6478. comp.os.os2.bugs                    discusses possible bugs found in released 
  6479.                                     versions of the operating system 
  6480. comp.os.os2.games                   covers all question about OS/2 games 
  6481. comp.os.os2.misc                    is for any other OS/2-related discussion 
  6482. comp.os.os2.multimedia              fosters conversation about OS/2 multimedia 
  6483.                                     (including MMPM/2), 
  6484. comp.os.os2.networking              looks at general networking issues 
  6485. comp.os.os2.networking.misc         miscellaneous discussions about networking 
  6486. comp.os.os2.networking.tcp-ip       covers TCP/IP issues 
  6487. comp.os.os2.programmer.misc         addresses anything else related to OS/2 
  6488.                                     programming 
  6489. comp.os.os2.programmer.oop          covers object-oriented programming 
  6490.                                     discussions 
  6491. comp.os.os2.programmer.porting      helps programmers move applications over to 
  6492.                                     OS/2 from other operating systems and 
  6493.                                     environments 
  6494. comp.os.os2.programmer.tools        covers tools for OS/2 application 
  6495.                                     developing 
  6496. comp.os.os2.setup                   offers a place to talk about setup and 
  6497.                                     installation issues 
  6498. comp.os.os2.ver1x                   HAS BEEN REMOVED 
  6499. comp.lang.rexx                      discusses REXX programming 
  6500.  
  6501. These groups are also watched closely by OS/2 experts from IBM. 
  6502.  
  6503. A LISTSERVer distributes its own OS/2 conference by mail; send a single line 
  6504. message with the word HELP to listserv@cc1.kuleuven.ac.be for full 
  6505. instructions; or send the same message to listserv@frors12.circe.fr for 
  6506. information on an unedited mailing list.  To subscribe to the Multimedia 
  6507. Presentation Manager/2, send a single line message with the phrase SUBSCRIBE 
  6508. MMOS2-L (Your Name) to mail-server@knex.via.mind.org. 
  6509.  
  6510. Your local FidoNet BBS may carry OS/2 echo conferences and/or OS2NET. If not, 
  6511. ask your system operator to join them.  CompuServe (FIND OS/2) and Prodigy are 
  6512. also excellent resources. 
  6513.  
  6514. The IBM PC Co. BBS's (modem 404-835-6600) message areas, product database, and 
  6515. PS/2 Assistant file(s) are invaluable resources. Information on the new OS/2 
  6516. BBS is included in the OS/2 2.0 package. In the United States IBM has toll free 
  6517. technical support (phone 800-237-5511), an OS/2 Hotline (general information, 
  6518. orders, upgrades, phone 800-3-IBM-OS2; ask about OS/2 videotapes, T-shirts, and 
  6519. other accessories), the HelpWare Center (phone 800-PS2-2227), a software order 
  6520. line (phone 800-IBM-CALL), two FAX information services (phone 800-IBM-4FAX 
  6521. and/or 800-IBM-3395), and an educational inquiries line (phone 800-222-7257). 
  6522. In Canada phone IBM Personal Systems Software at 800-465-1234. 
  6523.  
  6524. Any of the regular DOS or Windows resources (e.g. books, magazines, 
  6525. shareware/freeware sources) will be useful since both environments come with 
  6526. OS/2 2.0. 
  6527.  
  6528. (taken from OS/2 General FAQ) 
  6529.  
  6530.  
  6531. Related Information:
  6532.  
  6533. Developer's Assistance Program
  6534.  
  6535.  
  6536. ΓòÉΓòÉΓòÉ 11.6. Developer's Assistance Program (DAP) ΓòÉΓòÉΓòÉ
  6537.  
  6538. OS/2 2.0 developers should contact the IBM Developer Assistance Program (phone 
  6539. 407-982-6408); membership is free.  (You may also join on CompuServe with GO 
  6540. OS2DAP.)  The OS/2 Professional Developer's Kit CD-ROM, containing a wide 
  6541. selection of development tools and code, and the OS/2 2.1 Beta CD-ROM are both 
  6542. available from IBM (phone 800-3-IBM-OS2 to order in the United States for 
  6543. between $15 and $20 each, shipping included; in Canada, phone 800-465-1234; in 
  6544. Australia, phone Rohaini Cain or Mike Voris at 13-2426 ext. 7684; elsewhere, 
  6545. contact the International OS/2 User Group by phoning 285-641175 in the U.K.) 
  6546. The OS/2 Device Driver Development Kit CD-ROM is also now available from IBM. 
  6547. To order phone 407-982-4239 (FAX 407-982-4218) in North America, 61-2-354-7684 
  6548. (FAX 61-2-354-7766) in most of the Far East and Pacific Rim, 81-3-5563-5897 
  6549. (FAX 81-3-5563-4957) in Japan, 81-2-528-1548 (FAX 82-2-528-1414) in Korea, 
  6550. 011-52-627-1846 (FAX 011-52-395-7812) in Latin America, or +49-69-6645-3318 in 
  6551. Germany. 
  6552.  
  6553. (taken from the OS/2 general FAQ) 
  6554.  
  6555.  
  6556. ΓòÉΓòÉΓòÉ 12. OS/2 Software Sources ΓòÉΓòÉΓòÉ
  6557.  
  6558. The following BBSes hold large OS/2 libraries: 
  6559.  
  6560.  
  6561.  Name                      Number
  6562.  
  6563.  Fernwood                  (203) 483-0348
  6564.  
  6565.  OS/2 Shareware            (703) 385-4325
  6566.  
  6567.  Bay Area OS/2             (510) 657-7948
  6568.  
  6569.  Gateway/2                 (314) 554-9313
  6570.  
  6571.  Greater Chicago Online    (708) 895-4042
  6572.  
  6573.  OS/2 Connection (San      (619) 549-4215
  6574.  Diego)
  6575.  
  6576.  OS/2 Las Vegas            (702) 433-5535
  6577.  
  6578.  IBM Germany               049-711-785-777
  6579.  
  6580.  IBM Germany (Another)     +49-69-6645-325
  6581.  
  6582.  IBM Denmark               45-42-88-72-22
  6583.  
  6584.  OS/2 UK                   0454-633197
  6585.  
  6586.  IBM UK                    0256-336655
  6587.  
  6588.  IBM Norway                47-66-99-94-50
  6589.  
  6590.  OS/2 Norway               47-22-38-09-49
  6591.  
  6592.  OS/2 Australia            61-2-241-2466
  6593.  
  6594. Check OS/2 FAQ for a more extensive list of ftp sites. 
  6595.  
  6596. (The monthly Worldwide OS/2 BBS Listing, available from these BBSes, lists 
  6597. others.)  The IBM PC Company BBS (modem 404-835-6600) has some 
  6598. shareware/freeware as well, along with CSDs and the PS/2 Assistant (an 
  6599. invaluable resource for locating almost any sort of information on OS/2). For 
  6600. information on IBM's new OS/2 BBS phone 800-547-1283.  IBM Canada maintains 
  6601. several support BBSes: 
  6602.  
  6603.    (416) 946-4255 
  6604.    (514) 938-3022 
  6605.    (604) 664-6464 
  6606.    (416) 946-4244 
  6607.  
  6608. The Usenet conference comp.binaries.os2 carries OS/2 software.  And several 
  6609. sites are available via anonymous ftp.  (No ftp?  Send a single line message 
  6610. with the word HELP to bitftp@pucc.bitnet or ftpmail@decwrl.dec.com to learn 
  6611. about ftp mail servers.)  Some are (with Internet node numbers and 
  6612. subdirectories): 
  6613.  
  6614.  
  6615.  Site                           IP Address      Home OS/2 Directory
  6616.  
  6617.  ftp.cdrom.com                  192.153.46.2    /pub/os2
  6618.  
  6619.  ftp-os2.nmsu.edu               128.123.35.151  pub/os2
  6620.  
  6621.  software.watson.ibm.com        129.34.139.5    pub/os2
  6622.  
  6623.  mtsg.ubc.ca                    137.82.27.1     os2
  6624.  
  6625.  access.usask.ca                128.233.3.1     pub/archives/os2
  6626.  
  6627.  luga.latrobe.edu.au            131.172.2.2     pub/os2
  6628.  
  6629.  funic.funet.fi                 128.214.6.100   pub/os2
  6630.  
  6631.  pdsoft.lancs.ac.uk             148.88.64.2     micros/ibmpc/os2
  6632.  
  6633.  ftp.uni-stuttgart.de           129.69.1.12     soft/os2
  6634.  
  6635.  src.doc.ic.ac.uk               146.169.2.1     computing/systems/os2
  6636.  
  6637.  zaphod.cs.uwindsor.ca          137.207.224.3   pub/local/os2
  6638.  
  6639.  ftp.luth.se                    130.240.18.2    pub/pc/os2
  6640.  
  6641.  src.doc.ic.ac.uk               146.169.2.1     computing/systems/os2
  6642.  mirrors ftp-os2.nmsu.edu/ftp.c
  6643.  
  6644.  pdsoft.lancs.edu.uk            148.88.64.2     micros/ibmpc/os2
  6645.  
  6646.  ftp.informatik.tu-muenchen.de  131.159.0.198   /pub/comp/os2
  6647.  
  6648. The cdrom.com library is available on CD-ROM from Walnut Creek (phone 
  6649. 510-947-5996).  EMS (phone 301-924-3594) offers an OS/2 shareware/freeware 
  6650. library on diskette. 
  6651.  
  6652. Other sources include CompuServe (FIND OS/2) and archive servers (send a single 
  6653. line message with the word HELP to listserv@cc1.kuleuven.ac.be or 
  6654. mail-server@rus.uni-stuttgart.de for more information, or use ftp). TRICKLE 
  6655. servers are also available outside the United States.  For more information on 
  6656. TRICKLE services, including automatic file subscription procedures, send a 
  6657. single line message with the word HELP to any one of the following sites 
  6658. nearest you: 
  6659.  
  6660. Country      Address 
  6661. Austria      TRICKLE@AWIWUW11.BITNET 
  6662. Belgium      TRICKLE@BANUFS11.BITNET 
  6663. Colombia     TRICKLE@UNALCOL.BITNET 
  6664. France       TRICKLE@FRMOP11.BITNET 
  6665. Germany      TRICKLE@DEARN.BITNET 
  6666. Israel       TRICKLE@TAUNIVM.BITNET 
  6667. Italy        TRICKLE@IMIPOLI.BITNET 
  6668. Netherlands  TRICKLE@HEARN.BITNET 
  6669. Sweden       TRICKLE@SEARN.BITNET 
  6670. Turkey       TRICKLE@TREARN.BITNET 
  6671.              TRICKLE@TRMETU.BITNET 
  6672.  
  6673. IBM has been releasing freely distributable employee written software (e.g. 
  6674. Visual REXX) and OS/2 patches to these sites. 
  6675.  
  6676. (The previous was taken almost verbatim from the OS/2 General FAQ) 
  6677.  
  6678.  
  6679. ΓòÉΓòÉΓòÉ 13. Bugs / Obtaining this FAQ / Contacting the Author ΓòÉΓòÉΓòÉ
  6680.  
  6681. Reporting Bugs and Errors in the FAQ 
  6682.  
  6683. With the advent of all this nifty hypertext IPF stuff, there are bound to be 
  6684. bugs and errors in this FAQ, simply by Murphy's Law.  (Anything that can go 
  6685. wrong, will go wrong)  If you find an error, however, insignificant, please 
  6686. send me a note (through one of the ways listed below) telling me what's wrong 
  6687. with the FAQ. 
  6688.  
  6689. Obtaining this FAQ 
  6690.  
  6691. This FAQ is distributed on a regular basis to: 
  6692.  
  6693.  1. cdrom.com, in /pub/os2/all/info/faq, on the Internet 
  6694.  
  6695. All other sites should receive this FAQ on a trickle-down basis from these 
  6696. sites. 
  6697.  
  6698. This FAQ is distributed in two versions, ASCII and INF.  The INF version is 
  6699. binary and viewable only by the VIEW.EXE program that comes with OS/2.  The 
  6700. ASCII version is text and is viewable by any program that can view text (which 
  6701. includes most word processors).  The filename is PFAQnn.ZIP, where 'nn' is the 
  6702. FAQ version. 
  6703.  
  6704. Contacting the Author 
  6705.  
  6706. I can be contacted in a multitude of ways: 
  6707.  
  6708. o Internet.  This is the preferred method.  E-mail me at 
  6709.   andreas@traci.almroth.pp.se. 
  6710.  
  6711. o Snail Mail 
  6712.  
  6713.    Andreas Almroth 
  6714.    Fanrik Stals Gata 153 
  6715.    S-754 39 UPPSALA 
  6716.    SWEDEN 
  6717.  
  6718.  
  6719. ΓòÉΓòÉΓòÉ 14. Credits ΓòÉΓòÉΓòÉ
  6720.  
  6721. The following people have contributed in numerous and not-so-numerous ways to 
  6722. this document to make it what it is today, and what it will be tomorrow.  Give 
  6723. a big round of applause for... 
  6724.  
  6725. o Barry Jaspan <bjaspan@athena.mit.edu> 
  6726. o Jeff Garzik <jgarzik@pantera.atl.ga.us> 
  6727. o Byers R E James <zoorejb@nusunix2.nus.sg> 
  6728. o Stefan Gruendal <Stefan_Gruendel@wue.maus.de> 
  6729. o Raja Thiagarajan <sthiagar@bronze.ucs.indiana.edu> 
  6730. o Larry Saloman <os2man@panix.com> 
  6731. o Timothy Sipples <sip1@kimbark.uchicago.edu> 
  6732. o Bob Smith <OECN_SMITH@MEC.OHIO.GOV> 
  6733. o Tim Francis <francis@vnet.IBM.COM> 
  6734. o Colin Jensen <cjensen@netcom.com> 
  6735. o Bill Henning <bhenning@wimsey.com> 
  6736. o Axel Uhl <auhl@fzi.de> 
  6737. o R. Mahoney <rmahoney@bix.com> 
  6738. o Frank Fuchs <ffu@softpro.de> 
  6739. o James J. Song <jjs@acd4.acd.com> 
  6740. o Morio Taneda <Morio_Taneda@ka.maus.de> 
  6741. o Timur Tabi <timur@seas.gwu.edu> 
  6742. o Paul Prescod <papresco@undergrad.math.uwaterloo.ca> 
  6743. o Rich Wales <richw@mks.com> 
  6744. o Craig Swanson <Craig_Swanson@f354.n202.z1.fidonet.org> 
  6745. o Ivar E. Hosteng <nit3ieh@odin.oslo.nit.no or nit3ieh@accsys.oslo.nit.no> 
  6746.  
  6747. Ok, so the list is a little short right now.  If you contributed to Barry's or 
  6748. Jeff's FAQ, and you are not listed here, then please send me your name and I'll 
  6749. be glad to include you in this list. 
  6750.  
  6751. I have obtained some information from sources other than people also. Besides 
  6752. being credited above, here is another list: 
  6753.  
  6754. o OS/2 Frequently Asked Questions List v2.1  (Available from cdrom.com in 
  6755.   os2/all/info/faq/faq21*.zip) 
  6756.  
  6757. o Electronic Developers' OS/2 Magazine  (Available from cdrom.com in 
  6758.   os2/all/info/edmi/*) 
  6759.