home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR24 / PFAQ21IN.ZIP / PROGFAQ.INF (.txt)
OS/2 Help File  |  1993-06-17  |  197KB  |  6,257 lines

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