home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / S12317.ZIP / WNDPROC.C < prev   
C/C++ Source or Header  |  1989-02-06  |  4KB  |  151 lines

  1. #define INCL_WIN
  2. #define INCL_GPI
  3.  
  4.  
  5. #include <os2.h>
  6. #include "APP.h"
  7. #include <stddef.h>
  8. #include <string.h>
  9.  
  10. extern char szAppName[];
  11. extern char szEdit[];
  12. LONG   FontsAvail=30;
  13. extern HAB    hAB;
  14. HPS    hPS;
  15. FONTMETRICS fm[30];
  16. FATTRS     vfat;
  17. FONTMETRICS FontMetrics;
  18. OWNERITEM FAR * oi;
  19. int i=0;
  20. LONG lCurrentId;
  21. CHAR pszBuf[20];
  22. LONG     lLength;
  23. POINTL     pPoint;
  24. MRESULT FAR PASCAL APPWndProc( hWnd, message, mp1, mp2 )
  25. HWND    hWnd;
  26. USHORT  message;
  27. MPARAM  mp1;
  28. MPARAM  mp2;
  29. {
  30.  
  31.     switch( message )
  32.     {
  33.     case WM_CREATE:
  34.         hPS = WinGetPS (hWnd);
  35.     /*load courier font set */
  36.         GpiLoadFonts( hAB, (PSZ) "c:\\os2\\dll\\courier.fon");
  37.     /*query all available private fonts */
  38.         GpiQueryFonts (hPS, (ULONG)QF_PRIVATE,
  39.                NULL, &FontsAvail, (LONG) sizeof(FONTMETRICS), fm);
  40.  
  41.     /*find suitable fixed pitch font */
  42.         while((i<=FontsAvail))
  43.         {
  44.  
  45.            if((fm[i].fsDefn & 0x8000) && (fm[i].fsType & 0x0001))
  46.           break;
  47.            i++;
  48.         }
  49.  
  50.       /*prepare FATTRS stuct for later use in WM_DRAWITEM processing in
  51.     GpiCreateLogFont call                   */
  52.         vfat.usRecordLength  =  sizeof(FATTRS) ;
  53.         vfat.lMatch      =  fm[i].lMatch;
  54.         vfat.fsSelection     =  fm[i].fsSelection;
  55.         strcpy(vfat.szFacename, fm[i].szFacename) ;
  56.         vfat.idRegistry     =  fm[i].idRegistry ;
  57.         vfat.usCodePage     =  850;
  58.         vfat.lMaxBaselineExt =  fm[i].lMaxBaselineExt;
  59.         vfat.lAveCharWidth     =  fm[i].lAveCharWidth;
  60.         vfat.fsType      =  FATTR_TYPE_FIXED;
  61.         vfat.fsFontUse     =  0;
  62.  
  63.      /* Get metrics  */
  64.         GpiCreateLogFont( hPS, (PSTR8) szAppName,(LONG)i+1, &vfat );
  65.         GpiSetCharSet(hPS,(LONG)i+1);
  66.         GpiQueryFontMetrics (hPS, (long) sizeof FontMetrics, &FontMetrics);
  67.         GpiSetCharSet(hPS,0L);
  68.         WinReleasePS (hPS);
  69.             return (0);
  70.  
  71.  
  72.  
  73.     case WM_CLOSE:
  74.         WinPostMsg( hWnd, WM_QUIT, 0L, 0L );
  75.         break;
  76.  
  77.     case WM_COMMAND:
  78.         switch (LOUSHORT(mp1)) {
  79.  
  80.         case IDADDSTRINGS:
  81.         AddStrings( hWnd, message, mp1, mp2 );
  82.         break;
  83.  
  84.  
  85.             case IDABOUT:
  86.         WinDlgBox( HWND_DESKTOP, hWnd, (PFNWP)About, NULL, IDD_ABOUT,
  87.             NULL );
  88.                 break;
  89.  
  90.             default:
  91.                 break;
  92.             }
  93.             break;
  94.  
  95.  
  96.     case WM_PAINT:
  97.         APPPaint( hWnd, message, mp1, mp2 );
  98.         break;
  99.  
  100.     case WM_ERASEBACKGROUND:
  101.     return TRUE;
  102.     break;
  103.  
  104.     case WM_MEASUREITEM:
  105.      /*   Set the item height in the listbox */
  106.      /*   Note that the LOUSHORT of mp1 is the listbox ID */
  107.  
  108.     return(FontMetrics.lMaxBaselineExt);
  109.  
  110.  
  111.     case WM_DRAWITEM:
  112.        oi = mp2;
  113.     /* If desired char set not allready selected, create log font and set */
  114.     /* char set for Presentation Space of Listbox (oi->hps)*/
  115.  
  116.        if(!(GpiQueryCharSet(oi->hps) == i+1))
  117.        {
  118.     GpiCreateLogFont(oi->hps, (PSTR8) szAppName,(LONG)i+1, &vfat );
  119.     GpiSetCharSet(oi->hps,(LONG)i+1);
  120.        }
  121.        if (oi->fsState == oi->fsStateOld)
  122.        {
  123.     WinFillRect(oi->hps,&(oi->rclItem),CLR_WHITE);
  124.     GpiSetBackMix(oi->hps,BM_OVERPAINT);
  125.     GpiSetColor(oi->hps,CLR_BLUE);
  126.     lLength = WinSendMsg(oi->hwnd,LM_QUERYITEMTEXT,(MPARAM)MAKEULONG(oi->idItem,20),
  127.            (MPARAM)pszBuf);
  128.     pPoint.x = oi->rclItem.xLeft;
  129.     pPoint.y = oi->rclItem.yBottom + 1;
  130.     GpiCharStringAt(oi->hps,/*&(oi->rclItem.xLeft)*/ &pPoint,lLength +1,pszBuf);
  131.     return(TRUE);
  132.        }
  133.     /*return false to tell listbox proc to draw items  */
  134.        return(FALSE);
  135.  
  136.  
  137.  
  138.     default:
  139.         return WinDefWindowProc( hWnd, message, mp1, mp2 );
  140.         break;
  141.  
  142.     }
  143.  
  144.     return( 0L );
  145. }
  146. /*
  147. */
  148.  
  149. /*
  150. */
  151.