home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1993 #2 / Image.iso / os2 / pfaq22.zip / PROGFAQ.INF (.txt) next >
OS/2 Help File  |  1993-08-14  |  190KB  |  6,373 lines

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