home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / maths / plplot / plplot_2 / sys / os2 / pmserv / pmserv.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-11  |  17.4 KB  |  605 lines

  1. /*
  2.     pmserv.c
  3.     Geoffrey Furnish
  4.     22 September 1991
  5.  
  6.     This program is the OS/2 PM server for PLPLOT.    This program
  7.     is run in a seperate process, before the plplot app is run.
  8.     The app then communicates its requests to this server, which 
  9.     renders the plot in a PM window.  Since the plplot app need not
  10.     be a PM application, it can use normal printf output, and
  11.     need not exhibit the message based architecture common in PM apps.
  12.  
  13. Theory of Operation:
  14.     This program has two threads of execution.  The main thread handles
  15.     the PM message queue, and basically just responds to messages to
  16.     keep the image window up to date.  However, just before starting up
  17.     the message queue, it spawns a second process which manages the
  18.     pipe through which commands are accepted.  This second thread 
  19.     accepts connection requests from one client at a time, and routes
  20.     the drawing commands back to the first thread for display.  
  21.  
  22.     Although admittedly somewhat complex, this is actually a very efficient
  23.     way to implement the desired functionality.  Threads with OS/2 are
  24.     really great!
  25.  
  26. Revision History:
  27.     1-24-92    Finally fixed the problem with the colors getting messed
  28.         up on a repaint.  Also cleaning up the code a bit.
  29.     2-1-92    Finally fixed the problem with the final command in the
  30.         history buffer beeing fouled up in some cases.    More
  31.         code cleaning.    Fixed numerous compiler warnings.
  32.     2-1-92    Finally fixed the colors so they look about the same as
  33.         with the X Windows driver.  However, I still haven't
  34.         messed with the RGB escape function yet.  Later.
  35.     2-1-92    Fixed all compiler warnings.
  36.     2-2-92    Took out the majic number 200, and parameterized most
  37.         pipe things with constants defined in pmdefs.h.  Also took
  38.         this opportunity to choose a more sensible name for the
  39.         pipe.  Some optimization of pipe performance.
  40.     2-27-92    Finished the autoadvance code.    Seems to work about as well
  41.         as could be hoped.  The only thing wrong is that pages with
  42.         rgb never get drawn correctly, since they advance before they
  43.         ever get refreshed with correct colors.  Sure would be nice
  44.         if I could get them to draw right in the first place...
  45.     3-13-92    Fixed the bug which prevented a page with RGB on it from ever
  46.         being plotted right if it was the last page in the file.
  47.             
  48.         Anyway, looks like this is good enough to be called 
  49.             Version 1.0!
  50. */
  51.  
  52. #include "plplot.h"
  53.  
  54. #define INCL_WIN
  55. #define INCL_DOS
  56. #define INCL_GPI
  57. #include <os2.h>
  58. #include <process.h>
  59. #include <stdlib.h>
  60.  
  61. #include <stdio.h>
  62. #include <string.h>
  63. #include <memory.h>
  64.  
  65. #include "pmdefs.h"
  66.  
  67. VOID CheckMenuItem( HWND hwnd, SHORT sMenuItem, BOOL fCheck );
  68.  
  69. VOID FAR PipeManagerThread( PMSTUFF *pmstuff );
  70. MRESULT EXPENTRY ClientWndProc( HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2 );
  71. void InitiatePipeManagement( void );
  72. long    pmcolor( long color );
  73.  
  74. static CHAR szClientClass[] = "PlDrawClass";
  75. static ULONG flFrameFlags =    FCF_TITLEBAR | FCF_SYSMENU |
  76.                 FCF_SIZEBORDER | FCF_MINMAX |
  77.                 FCF_SHELLPOSITION | FCF_TASKLIST |
  78.                 FCF_MENU ;
  79.  
  80. HAB hab;
  81. HMQ hmq;
  82. HWND hwndFrame, hwndClient;
  83. QMSG qmsg;
  84.  
  85. PLINT inbuflen, inbuffer[ PIPE_BUFFER_SIZE ];
  86. int inbuffree = 1;
  87.  
  88. // I'm not really too clear on just how big this number should be.  When I
  89. // had it set to only 16000, I found that examles 1, 12 and 13 all exhibited
  90. // the property of overflowing the history buffer.  The code handles this
  91. // correctly, in the sense that no error is generated, but clearly we want
  92. // this number big enough for most graphs to work without a hitch.
  93.  
  94. #define MAX_LIST_LEN    60000
  95. PLINT permbuflen, permbufferfull=0;
  96. PLINT _huge permbuffer[ MAX_LIST_LEN ];
  97.  
  98. #define WM_DRAW_MORE    (WM_USER + 0)
  99. #define WM_NEW_SESSION    (WM_USER + 1)
  100.  
  101. /*----------------------------------------------------------------------------*\
  102. * void main ( void )
  103. *
  104. * In this function we initialize the necessary data structures, spawn the 
  105. * thread which manages the incoming command pipe, and finally start up the 
  106. * PM message queue and process messages until all done.
  107. *
  108. * This is based on code from C. Petzold's book on OS/2 PM Programming.
  109. \*----------------------------------------------------------------------------*/
  110.  
  111. void main ( void )
  112. {
  113.     hab = WinInitialize(0);
  114.     hmq = WinCreateMsgQueue( hab, 0 );
  115.     
  116.     WinRegisterClass( hab, szClientClass, ClientWndProc, CS_SIZEREDRAW, 
  117.     0 );
  118.     
  119.     hwndFrame = WinCreateStdWindow( HWND_DESKTOP, WS_VISIBLE,
  120.         &flFrameFlags, szClientClass,
  121.         NULL,
  122.         0L, (HMODULE) 0, ID_RESOURCE, &hwndClient );
  123.  
  124.     WinSendMsg( hwndFrame, WM_SETICON,
  125.     WinQuerySysPointer( HWND_DESKTOP, SPTR_APPICON, FALSE ), NULL );
  126.  
  127.     InitiatePipeManagement();    // spawns a new thread for this purpose.
  128.     
  129.     while( WinGetMsg( hab, &qmsg, NULL, 0, 0 ) )
  130.     WinDispatchMsg( hab, &qmsg );
  131.  
  132.     WinDestroyWindow( hwndFrame );
  133.     WinDestroyMsgQueue( hmq );
  134.     WinTerminate( hab );
  135. }
  136.  
  137. /*----------------------------------------------------------------------------*\
  138. * MRESULT EXPENTRY ClientWndProc(HWND hwnd,USHORT msg,MPARAM mp1,MPARAM mp2)
  139. *
  140. * In this function we handle all the messages to the main window.
  141. \*----------------------------------------------------------------------------*/
  142.  
  143. MRESULT EXPENTRY ClientWndProc( HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2 )
  144. {
  145.     long i=0, j;
  146.     long startofset, atendofimage, commandlen, range, 
  147.             pmrgb, pmcolorindex;
  148.     HPS hps;
  149.     POINTL ptl;
  150.     static SHORT cx, cy;
  151.     static float scalex, scaley;
  152.     static int rgbused = 0;
  153.     static int WaitingToAdvance = 0;
  154.     static int justadvanced = 0;
  155.     static int autoadvance = 0;
  156.     SHORT  sMenuItem;
  157.     static long resumewith = 0;
  158.     static PLINT oldx, oldy, oldcolor = CLR_WHITE, firstcolor = CLR_WHITE;
  159.  
  160.     switch (msg) {
  161.     case WM_COMMAND:
  162.         switch ( COMMANDMSG(&msg)->cmd ) {
  163.         case IDM_ADVANCE:
  164.             WinAlarm( HWND_DESKTOP, WA_ERROR );
  165.             if (WaitingToAdvance) {
  166.             WaitingToAdvance = 0;
  167.             justadvanced = 1;
  168.             WinPostMsg( hwndFrame, WM_DRAW_MORE, NULL, NULL );
  169.             }
  170.             return 0;
  171.  
  172.         case IDM_AUTO_ADVANCE:
  173.             autoadvance = !autoadvance;
  174.             sMenuItem = COMMANDMSG(&msg)->cmd;
  175.             CheckMenuItem( hwnd, sMenuItem, autoadvance );
  176.             return 0;
  177.         }
  178.         break;
  179.     
  180.     case WM_SIZE:
  181.         cx = SHORT1FROMMP( mp2 );
  182.         cy = SHORT2FROMMP( mp2 );
  183.         scalex = cx / (float) PLMETA_X;
  184.         scaley = cy / (float) PLMETA_Y;
  185.         return 0;
  186.     
  187.     case WM_PAINT:
  188.         hps = WinBeginPaint( hwnd, NULL, NULL );
  189.  
  190.         ptl.x = oldx = 0; ptl.y = oldy = 0;
  191.         GpiMove( hps, &ptl );
  192.         ptl.x = cx; ptl.y = cy;
  193.  
  194. // Some ballogney to clear the window.    Gotta be a better way...
  195.  
  196.         GpiSetPattern( hps, PATSYM_SOLID );
  197.         GpiSetColor( hps, CLR_BLACK );
  198.         GpiBox( hps, DRO_FILL, &ptl, 0, 0 );
  199.  
  200. // Now reset the color to the color which was the current color at the time
  201. // of the last frame advance, i.e. the first color to use when drawing lines
  202. // in this window.  This is not necessarily the same as oldcolor, or the
  203. // first color in the color map.
  204. // Also, reset the command index i, and other flags.
  205.  
  206.         GpiSetColor( hps, pmcolor(firstcolor) );
  207.         i = 0; 
  208.         atendofimage = 0;
  209.  
  210.         while ( i < (int) permbuflen && !atendofimage )
  211.         switch ( permbuffer[i++] ) {
  212.             case INITIALIZE:
  213.             break;
  214.         
  215.             case SWITCH_TO_TEXT:
  216.             break;
  217.             
  218.             case SWITCH_TO_GRAPH:
  219.             break;
  220.             
  221.             case CLEAR:
  222.             atendofimage = 1;
  223.             break;
  224.             
  225.             case PAGE:
  226.             break;
  227.             
  228.             case NEW_COLOR:
  229.             oldcolor = permbuffer[i++];
  230.             GpiSetColor( hps, pmcolor(oldcolor) );
  231.             break;
  232.             
  233.             case NEW_WIDTH:
  234.             i++;
  235.             break;
  236.             
  237.             case LINETO:
  238.             oldx = ptl.x = (long) (permbuffer[i++] * scalex);
  239.             oldy = ptl.y = (long) (permbuffer[i++] * scaley);
  240.             GpiLine( hps, &ptl );
  241.             break;
  242.             
  243.             case LINE:
  244.             ptl.x = (long) (permbuffer[i++] * scalex);
  245.             ptl.y = (long) (permbuffer[i++] * scaley);
  246.             GpiMove( hps, &ptl );
  247.             oldx = ptl.x = (long) (permbuffer[i++] * scalex);
  248.             oldy = ptl.y = (long) (permbuffer[i++] * scaley);
  249.             GpiLine( hps, &ptl );
  250.             break;
  251.  
  252.             case CLOSE:
  253.             atendofimage = 1;
  254.             break;
  255.         
  256.             case ESCAPE:
  257.             switch(permbuffer[i++]) {
  258.                 case ESC_NOOP:
  259.                 break;
  260.  
  261.                 case ESC_RGB:
  262.                 pmrgb = permbuffer[i++];
  263.                 // Do something to update the color here.
  264.                 pmcolorindex = GpiQueryColorIndex( hps,
  265.                     LCOLOPT_REALIZED, pmrgb );
  266.                 if (pmcolorindex >= 0 && pmcolorindex <= 15) {
  267.                     GpiSetColor( hps, pmcolorindex );
  268.                     oldcolor = pmcolorindex;
  269.                 }
  270.                 break;
  271.             
  272.                 default:
  273.                 WinAlarm( HWND_DESKTOP, WA_ERROR );
  274.                 printf( "*** UNRECOGNIZED COMMAND ***\n" );
  275.                 exit(0);
  276.                 break;
  277.             
  278.             }
  279.             break;
  280.         
  281.             default:
  282.             WinAlarm( HWND_DESKTOP, WA_ERROR );
  283.             printf( "*** UNRECOGNIZED COMMAND ***\n" );
  284.             exit(0);  // if bad here, then its bad bad news !!!
  285.             break;
  286.         }
  287.         
  288.         WinEndPaint( hps );
  289.         return 0;
  290.  
  291.     case WM_DRAW_MORE:
  292.         inbuffree = 0;    // Mark the buffer "off-limits".
  293.  
  294. // Get a PS, and restore prior state.
  295.         
  296.         hps = WinGetPS( hwnd );
  297.         GpiSetColor( hps, pmcolor(oldcolor) );
  298.         GpiSetPattern( hps, PATSYM_SOLID );
  299.         ptl.x = oldx; ptl.y = oldy;
  300.         GpiMove( hps, &ptl );
  301.                       
  302.         if (justadvanced) {
  303.         i = resumewith;
  304.         resumewith = 0;
  305.         permbuflen = 0;
  306.         permbufferfull = 0;
  307.         ptl.x = oldx = 0; ptl.y = oldy = 0;
  308.         GpiMove( hps, &ptl );
  309.         ptl.x = cx; ptl.y = cy;
  310.  
  311. // Some ballogney to clear the window.    Gotta be a better way...
  312.  
  313.         GpiSetColor( hps, CLR_BLACK );
  314.         GpiBox( hps, DRO_FILL, &ptl, 0, 0 );
  315.         GpiSetColor( hps, pmcolor(oldcolor) );
  316.  
  317.         firstcolor = oldcolor;
  318.         rgbused = 0;
  319.         justadvanced = 0;
  320.         }
  321.  
  322. // Now process the new message stream.
  323.  
  324.         startofset = i;
  325.         range = 0;
  326.  
  327.         while ( i < (int) inbuflen && !WaitingToAdvance ) {
  328.         commandlen = 1;
  329.         switch ( inbuffer[i++] ) {
  330.             case INITIALIZE:
  331.             break;
  332.         
  333.             case SWITCH_TO_TEXT:
  334.             break;
  335.             
  336.             case SWITCH_TO_GRAPH:
  337.             break;
  338.             
  339.             case CLEAR:
  340.             resumewith = i;
  341.             WaitingToAdvance = 1;
  342.             if (rgbused)
  343.                 WinInvalidateRect( hwnd, NULL, FALSE );
  344.             break;
  345.             
  346.             case PAGE:
  347.             break;
  348.             
  349.             case NEW_COLOR:
  350.             oldcolor = inbuffer[i++];
  351.             GpiSetColor( hps, pmcolor(oldcolor) );
  352.             commandlen++;
  353.             break;
  354.             
  355.             case NEW_WIDTH:
  356.             i++;
  357.             commandlen++;
  358.             break;
  359.             
  360.             case LINETO:
  361.             oldx = ptl.x = (long) (inbuffer[i++] * scalex);
  362.             oldy = ptl.y = (long) (inbuffer[i++] * scaley);
  363.             GpiLine( hps, &ptl );
  364.             commandlen += 2;
  365.             break;
  366.             
  367.             case LINE:
  368.             ptl.x = (long) (inbuffer[i++] * scalex);
  369.             ptl.y = (long) (inbuffer[i++] * scaley);
  370.             GpiMove( hps, &ptl );
  371.             oldx = ptl.x = (long) (inbuffer[i++] * scalex);
  372.             oldy = ptl.y = (long) (inbuffer[i++] * scaley);
  373.             GpiLine( hps, &ptl );
  374.             commandlen += 4;
  375.             break;
  376.  
  377.             case CLOSE:
  378.             if (rgbused)
  379.                 WinInvalidateRect( hwnd, NULL, FALSE );
  380.             break;
  381.         
  382.             case ESCAPE:
  383.             commandlen++;
  384.             switch(inbuffer[i++]) {
  385.                 case ESC_NOOP:
  386.                 break;
  387.  
  388.                 case ESC_RGB:
  389.                 pmrgb = inbuffer[i++];
  390.                 commandlen++;
  391.                 // Do something to update the color here...
  392.                 // Unfortunately, this is very hard to do
  393.                 // here, since it keeps drawing in spurious
  394.                 // colors.  Only works right if done during
  395.                 // the WM_PAINT message handling.  So,
  396.                 // jury rig plots with RGB specified colors
  397.                 // to auto-repaint when done.
  398.                 rgbused = 1;
  399.                 break;
  400.             
  401.                 default:
  402.                 WinAlarm( HWND_DESKTOP, WA_ERROR );
  403.                 printf( "*** UNRECOGNIZED COMMAND ***\n" );
  404.                 exit(0);
  405.                 break;
  406.             
  407.             }
  408.             break;
  409.         
  410.             default:
  411.             WinAlarm( HWND_DESKTOP, WA_ERROR );
  412.             printf( "*** UNRECOGNIZED COMMAND ***\n" );
  413.             exit(0);
  414.             break;
  415.         }
  416.         if (!permbufferfull && permbuflen + range + commandlen 
  417.                 < MAX_LIST_LEN)
  418.             range += commandlen;
  419.         else
  420.             permbufferfull = 1;
  421.         }
  422.  
  423.         WinReleasePS( hps );
  424.  
  425. // Now add the commands processed this far to the permanent buffer list.
  426.         if ( range )
  427.         for( j=startofset; range; range-- )
  428.             permbuffer[ permbuflen++ ] = inbuffer[ j++ ];
  429.  
  430.         if (!WaitingToAdvance)
  431.         inbuffree = 1;
  432.  
  433. // Should this next block be here, or just above the one above???
  434.  
  435.         if (WaitingToAdvance && autoadvance) {
  436.         WaitingToAdvance = 0;
  437.         justadvanced = 1;
  438.         WinPostMsg( hwndFrame, WM_DRAW_MORE, NULL, NULL );
  439.         }
  440.  
  441.         return 0;
  442.  
  443.     case WM_NEW_SESSION:
  444.         WinAlarm( HWND_DESKTOP, WA_ERROR );
  445.         resumewith = 0;
  446.         justadvanced = 1;
  447.         return 0;
  448.     }
  449.  
  450.     return WinDefWindowProc( hwnd, msg, mp1, mp2 );
  451. }
  452.  
  453. /*----------------------------------------------------------------------------*\
  454. * long      pmcolor( long color )
  455. *
  456. * In this function we convert the PLPLOT requested color into a an actual
  457. * PM color index value.
  458. \*----------------------------------------------------------------------------*/
  459.  
  460. long    pmcolor( long color )
  461. {
  462.     static long pmcolors[] = {
  463.     CLR_WHITE, CLR_RED, CLR_YELLOW, CLR_GREEN,
  464.     CLR_CYAN, CLR_WHITE, CLR_WHITE, CLR_PALEGRAY,
  465.     CLR_WHITE, CLR_BLUE, CLR_GREEN, CLR_CYAN,
  466.     CLR_RED, CLR_PINK, CLR_YELLOW, CLR_WHITE
  467.     };
  468.  
  469.     if (color < 0 || color > 15)
  470.     color = 15;
  471.  
  472.     return pmcolors[color];
  473. }
  474.  
  475. /*----------------------------------------------------------------------------*\
  476. * void InitiatePipeManagement( void )
  477. *
  478. * In this function we start the thread which reads the pipe, and passes 
  479. * the graphics commands to the window procedure.
  480. \*----------------------------------------------------------------------------*/
  481.  
  482. void InitiatePipeManagement( void )
  483. {
  484.     static VOID *pThreadStack;
  485.     static TID    tidPipeManager;
  486.     static PMSTUFF pmstuff;
  487.     
  488.     pmstuff.a = 0;    // Not currently used for anything...
  489.     
  490.     if ( NULL == (pThreadStack = malloc( STACKSIZE )) ) {
  491.     printf( "Unable to allocate space for pipe manager thread.\n" );
  492.     exit(0);
  493.     }
  494.     if ( -1 == (tidPipeManager = _beginthread( PipeManagerThread,
  495.             pThreadStack, STACKSIZE, &pmstuff ))) {
  496.     printf( "Unable to spawn pipe manager thread.\n" );
  497.     exit(0);
  498.     }
  499. }
  500.  
  501. /*----------------------------------------------------------------------------*\
  502. * VOID FAR PipeManagerThread( PMSTUFF *pmstuff )
  503. *
  504. * In this function we read commands from the pipe, and pass them off to
  505. * the window procedure.
  506. \*----------------------------------------------------------------------------*/
  507.  
  508. VOID FAR PipeManagerThread( PMSTUFF *pmstuff )
  509. {
  510.     HPIPE hp;
  511.     USHORT bytes1, bytes2, bytes3, rv1, rv2, retries;
  512.     PLINT buflen, buffer[ PIPE_BUFFER_SIZE ];
  513.     char  *pbuffer = (char *) buffer;
  514.     
  515. // Now open up the pipe and start handling it.
  516.     
  517.     DosMakeNmPipe( /*"\\pipe\\bubba"*/ PIPE_NAME,    // pipe name.
  518.         &hp,            // pipe handle.
  519.         NP_ACCESS_INBOUND | NP_NOINHERIT | NP_NOWRITEBEHIND,
  520.         1 | NP_WAIT | NP_READMODE_BYTE | NP_TYPE_BYTE,
  521.         512,            // output-buffer size.
  522.         //512,            // input-buffer size.
  523.         2*PIPE_BUFFER_SIZE,    // input-buffer size.
  524.         500L );            // default timeout for DosWaitNmPipe.
  525.  
  526. // 2-1-92
  527. // Comments:  In vol 1 of the OS/2 Programmer's Reference, the output
  528. // and input buffer sizes are listed in the opposite order of what is
  529. // shown in vol 3.  I am taking 3 to be correct, since it is the complete
  530. // spec for the function.
  531. //
  532. // Secondly, in a prior life, I had to boost the output buffer (whic I thought
  533. // at the time was the input buffer) size from 512 to 2048.  I've now (2-1-92)
  534. // taken it back down to 512, and don't seem to have any problems with it.
  535.  
  536. // Really need to overhaul this next section.  Should replace all those
  537. // crazy diagnostics with some useful, effective actions.
  538.  
  539.     do {
  540.     if (DosConnectNmPipe( hp )) {
  541.         DosClose( hp );
  542.         exit(0);
  543.     }
  544.  
  545.     WinPostMsg( hwndFrame, WM_NEW_SESSION, NULL, NULL );
  546.  
  547.     do {
  548.         rv1 = DosRead( hp, &buflen, sizeof( PLINT ), &bytes1 );
  549.         if (bytes1 == 0) break;
  550. //        if (bytes1 != 4)
  551. //        printf( "Major screw up.  buflen not read correctly.\n" );
  552.  
  553.         bytes2 = 0;
  554.         retries = -1;
  555.         do {
  556.         retries++;
  557.         rv2 = DosRead( hp, &pbuffer[bytes2], 
  558.                 (USHORT) (buflen*sizeof(PLINT) - (PLINT) bytes2),
  559.                 &bytes3 );
  560.         bytes2 += bytes3;
  561. //        if (!bytes3) printf( "No bytes returned!\n" );
  562. //        if (rv2) printf( "Bogus pipe read.\n" );
  563.             
  564.         } while ( (PLINT) bytes2 < buflen*sizeof(PLINT) );
  565.     
  566. //        printf( "buflen=%d, Read %d bytes, %d expected.\n", 
  567. //        (int) buflen, (int) bytes2, (int) buflen*sizeof(PLINT) );
  568. //        if (retries) printf( "%d retries to get whole packet.\n", retries );
  569.         
  570. //        if (rv1 || rv2)
  571. //        printf( "rv1=%d, rv2=%d \n", rv1, rv2 );
  572.  
  573.         while (!inbuffree );
  574.         inbuflen = buflen;
  575.         memcpy( inbuffer, buffer, (int) buflen*sizeof(PLINT) );
  576.         inbuffree = 0;
  577.         WinPostMsg( hwndFrame, WM_DRAW_MORE, NULL, NULL );
  578.  
  579.     } while( bytes2 );
  580.  
  581.     DosDisConnectNmPipe( hp );
  582. //    printf( "Connection closed.\n\n" );
  583.     
  584.     } while(1);
  585.  
  586.     _endthread();
  587. }
  588.  
  589. /*----------------------------------------------------------------------------*\
  590. * VOID CheckMenuItem( HWND hwnd, SHORT sMenuItem, BOOL fCheck )
  591. *
  592. * This function, obtained from Petzold's book, manages the checking and
  593. * unchecking of a menu item.
  594. \*----------------------------------------------------------------------------*/
  595.  
  596. VOID CheckMenuItem( HWND hwnd, SHORT sMenuItem, BOOL fCheck )
  597. {
  598.     HWND hwndParent    = WinQueryWindow( hwnd, QW_PARENT, FALSE );
  599.     HWND hwndMenu    = WinWindowFromID( hwndParent, FID_MENU );
  600.  
  601.     WinSendMsg( hwndMenu, MM_SETITEMATTR,
  602.         MPFROM2SHORT( sMenuItem, TRUE ),
  603.         MPFROM2SHORT( MIA_CHECKED, fCheck ? MIA_CHECKED : 0 ) );
  604. }
  605.