home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Product / Product.zip / PRESNT.ZIP / PRESENT.C < prev    next >
C/C++ Source or Header  |  1992-04-09  |  16KB  |  678 lines

  1. /*
  2. ** Present.c        (NC)Not Copyrighted by The Frobozz Magic Software Company
  3. **
  4. **    Present a slide show 
  5. */
  6.  
  7. #define INCL_WIN
  8. #define INCL_DOS
  9. #define INCL_GPI
  10. #define INCL_BITMAPFILEFORMAT
  11. #define INCL_WINSTDFILE
  12.  
  13. #include <os2.h>
  14. #include "presfont.h"
  15.  
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <string.h>
  19. #include <malloc.h>
  20. #include "present.h"
  21.  
  22. CHAR  szApp[] = "Present!";
  23. HAB    hab;
  24. HWND    hwndFrame, hwndClient;
  25.  
  26. HPS    hps;
  27. HDC    hdcMem;
  28.  
  29. HPS    hpsBmp;
  30. HDC    hdcBmpmem;
  31.  
  32. BOOL    fPresSelected;
  33.  
  34. POINTL    ptlBmpsz;
  35.  
  36. struct _sheet;
  37.  
  38. typedef struct _sheet SHEET;
  39. typedef SHEET *PSHEET;
  40. typedef struct _line SLINE;
  41. typedef SLINE *PSLINE;
  42. typedef struct _pres PRES;
  43. typedef PRES *PPRES;
  44.  
  45. struct _line {
  46.     PSLINE        plNext;
  47.     PSHEET     pshSheet;
  48.     PSZ        pszText;
  49.     LONG        lColour;
  50.     HFONT        hf;
  51.     USHORT    usAlign;
  52.     POINTL    aptl[TXTBOX_COUNT];
  53.     USHORT    usShadow;
  54.     USHORT    usDepth;
  55. };
  56.  
  57. struct _sheet {
  58.     PSHEET    pshNext;
  59.     PSHEET    pshFollowing;
  60.     PSHEET    pshPrev;
  61.     PSLINE    plFirst;
  62.     PSZ        pszBitmap;
  63.     USHORT    usMode;
  64.     USHORT    usID;
  65.     USHORT    usNextID;
  66. };
  67.  
  68.  
  69. struct _pres {
  70.     PSZ        pszTitle;
  71.     POINTL    ptlSize;
  72.     PSHEET    pshFirst;
  73.     BOOL        fHasbmp;
  74. };
  75.  
  76. char foo[400];
  77.  
  78. PRES pres;
  79.  
  80.  
  81. typedef struct _nlin NLIN;
  82. typedef NLIN *PNLIN;
  83.  
  84. struct _nlin {
  85.     LONG        lColour;
  86.     PSZ        pszText;
  87.     CHAR        chFont[20];
  88.     USHORT    usAlign;
  89.     USHORT    usType;
  90.     USHORT    usPoint;
  91.     USHORT    usSub;
  92.     USHORT    usFx;
  93. };
  94.  
  95. #define    FX_SHADOW        1
  96. #define    FX_DEPTH            2
  97.  
  98.  
  99.  
  100. //------------- Keyword defines
  101.  
  102. #define K_INVALID        256
  103.  
  104. #define K_TITLE        0
  105. #define K_SIZE            1
  106. #define K_PAGE            2
  107. #define K_SHEET        3
  108. #define K_MODE            4
  109. #define K_NEXT            5
  110. #define K_SLINE            6
  111. #define K_ALIGN        7
  112. #define K_FONT            8
  113. #define K_TYPE            9
  114. #define K_POINT        10
  115. #define K_COLOUR        11
  116. #define K_SUB            12
  117. #define K_BITMAP        13
  118. #define K_FX            14
  119.  
  120. USHORT KeywordId(PSZ pszKey)
  121. {
  122.     static struct {
  123.         CHAR         szWord[10];
  124.         USHORT    usID;
  125.     } idLst[] = {
  126.         "title",    K_TITLE,
  127.         "size",    K_SIZE,
  128.         "page",    K_PAGE,
  129.         "sheet",    K_SHEET,
  130.         "mode",    K_MODE,
  131.         "next",    K_NEXT,
  132.         "line",    K_SLINE,
  133.         "align",    K_ALIGN,
  134.         "font",    K_FONT,
  135.         "type",    K_TYPE,
  136.         "point",    K_POINT,
  137.         "colour",K_COLOUR,
  138.         "sub",    K_SUB,
  139.         "bitmap",K_BITMAP,
  140.         "fx",        K_FX
  141.     };
  142.     register int i;
  143.     for (i = 0; i < sizeof(idLst)/sizeof(idLst[0]); i++) {
  144.         if (stricmp(pszKey, idLst[i].szWord) == 0) {
  145.             return idLst[i].usID;
  146.         }
  147.     }
  148.     return K_INVALID;
  149. }
  150.  
  151. VOID PresInit(VOID)
  152. {
  153.     pres.ptlSize.x = pres.ptlSize.y = 0L;
  154.     pres.fHasbmp = FALSE;
  155. }
  156.  
  157. VOID PresSetSize(PSZ pszLine)
  158. {
  159.     sscanf(pszLine, "%ld,%ld", &pres.ptlSize.x, &pres.ptlSize.y);
  160. }
  161.  
  162. #define BLOCK_FACT    64
  163.  
  164. VOID PresLoadBmp(HPS hpsBmp, PSZ pszFile)
  165. {
  166.     register int i;
  167.     PCHAR pchBuf;
  168.     BITMAPFILEHEADER bfh;
  169.     ULONG ulWidth;
  170.     PBITMAPINFO pbmi;
  171.     HBITMAP hbm;
  172.     FILE *f = fopen(pszFile, "rb");
  173.     if (f == NULL) {
  174.         CHAR szMsg[120];
  175.         sprintf(szMsg, "Cannot access bitmap file '%s'", pszFile);
  176.         WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szMsg, szApp, 0, MB_ICONEXCLAMATION | MB_ENTER);
  177.     }
  178.     fread(&bfh, 1, sizeof(bfh), f);
  179.     pbmi = malloc(bfh.offBits - sizeof(bfh) + sizeof(BITMAPINFOHEADER));
  180.     fseek(f, -sizeof(BITMAPINFOHEADER), SEEK_CUR);
  181.     fread(pbmi, 1, bfh.offBits - sizeof(bfh) + sizeof(BITMAPINFOHEADER), f);
  182.  
  183.     ulWidth = bfh.cbSize - bfh.offBits;
  184.     pchBuf = malloc(ulWidth);
  185.     fread(pchBuf, 1, ulWidth, f);
  186.     hbm = GpiCreateBitmap(hpsBmp, (PBITMAPINFOHEADER2)pbmi, CBM_INIT, pchBuf, (PBITMAPINFO2)pbmi);
  187.     GpiSetBitmap(hpsBmp, hbm);
  188.     pres.fHasbmp = TRUE;
  189.     ptlBmpsz.x = bfh.bmp.cx - 1;
  190.     ptlBmpsz.y = bfh.bmp.cy - 1;
  191.     free(pbmi);
  192.     free(pchBuf);
  193.     fclose(f);
  194. }
  195.  
  196. VOID PresAddSheet(PPRES ppr, PSHEET psh)
  197. {
  198.     if (psh->usID != 0) {            // new sheet added ??
  199.         PSHEET pshNew = malloc(sizeof(SHEET));
  200.         PSHEET *ppsh;
  201.         *pshNew = *psh;
  202.         pshNew->pshNext = pshNew->pshPrev = NULL;
  203.         for (ppsh = &(ppr->pshFirst); *ppsh != NULL; ppsh = &((*ppsh)->pshNext)) {
  204.             // EMPTY, find last sheet in list
  205.         }
  206.         *ppsh = pshNew;
  207.  
  208.         // reset edit sheet
  209.         psh->pshFollowing = NULL;
  210.         psh->plFirst = NULL;
  211.         psh->usID = psh->usNextID = 0;
  212.     }
  213. }
  214.  
  215. VOID PresLinkSheets(PPRES ppr)
  216. {
  217.     PSHEET psh1, psh2;
  218.     for (psh1 = ppr->pshFirst; psh1 != NULL; psh1 = psh1->pshNext) {
  219.         if (psh1->usNextID != 0) {
  220.             for (psh2 = ppr->pshFirst; psh2 != NULL; psh2 = psh2->pshNext) {
  221.                 if (psh2->usID == psh1->usNextID) {
  222.                     psh1->pshFollowing = psh2;
  223.                     psh2->pshPrev = psh1;
  224.                     break;
  225.                 }
  226.             }
  227.         }
  228.     }
  229. }
  230.  
  231. VOID SheetAddLine(PSHEET psh, PNLIN pnl)
  232. {
  233.     if (pnl->pszText != NULL) {
  234.         PSLINE pl = malloc(sizeof(SLINE));
  235.         PSLINE *ppl;
  236.         pl->lColour = pnl->lColour;
  237.         pl->pszText = pnl->pszText;
  238.         pl->usAlign = pnl->usAlign;
  239.         pl->usShadow = (pnl->usFx & FX_SHADOW) ? (pnl->usPoint / 10) : 0;
  240.         pl->usDepth = (pnl->usFx & FX_DEPTH) ? (pnl->usPoint / 20) : 0;
  241.         pl->pshSheet = NULL;
  242.         pl->plNext = NULL;
  243.         pl->hf = PresGetFont(hps, pnl->chFont, pnl->usPoint, pnl->usType);
  244.         PresSetFont(hps, pl->hf);
  245.         GpiQueryTextBox(hps, strlen(pl->pszText), pl->pszText, TXTBOX_COUNT, pl->aptl);
  246.         for (ppl = &(psh->plFirst); *ppl != NULL; ppl = &((*ppl)->plNext)) {
  247.             // EMPTY, find last slot
  248.         }
  249.         *ppl = pl;
  250.         pnl->pszText = NULL;
  251.     }
  252. }
  253.  
  254. USHORT LineParseType(PSZ psz)
  255. {
  256.     USHORT usType = 0;
  257.     for (;*psz != 0; psz++) {
  258.         switch (*psz) {
  259.         case 'B' :
  260.         case 'b' :        usType |= FATTR_SEL_BOLD;            break;
  261.         case 'I' :
  262.         case 'i' :        usType |= FATTR_SEL_ITALIC;        break;
  263.         case 'U' :
  264.         case 'u' :        usType |= FATTR_SEL_UNDERSCORE;    break;
  265.         case 'S' :
  266.         case 's' :        usType |= FATTR_SEL_STRIKEOUT;    break;
  267.         }
  268.     }
  269.     return usType;
  270. }
  271.  
  272. USHORT LineParseFx(PSZ psz)
  273. {
  274.     USHORT usFx = 0;
  275.     for (;*psz != 0; psz++) {
  276.         switch (*psz) {
  277.         case 'D' :
  278.         case 'd' :        usFx |= FX_DEPTH;            break;
  279.         case 'S' :
  280.         case 's' :        usFx |= FX_SHADOW;        break;
  281.         }
  282.     }
  283.     return usFx;
  284. }
  285.  
  286. struct {
  287.     PSZ pszCol;
  288.     LONG lValue;
  289. } sCol[] = {
  290.     "white",        CLR_WHITE,
  291.     "black",        CLR_BLACK,
  292.     "blue",        CLR_BLUE,
  293.     "red",        CLR_RED,
  294.     "pink",        CLR_PINK,
  295.     "green",        CLR_GREEN,
  296.     "cyan",        CLR_CYAN,
  297.     "yellow",    CLR_YELLOW,
  298.     "darkgray",    CLR_DARKGRAY,
  299.     "darkblue",    CLR_DARKBLUE,
  300.     "darkred",    CLR_DARKRED,
  301.     "darkpink",    CLR_DARKPINK,
  302.     "darkgreen",CLR_DARKGREEN,
  303.     "darkcyan",    CLR_DARKCYAN,
  304.     "brown",        CLR_BROWN,
  305.     "palegray",    CLR_PALEGRAY
  306. };
  307.  
  308.  
  309. LONG LineParseColour(PSZ psz)
  310. {
  311.     register int i;
  312.     for (i = 0; i < sizeof(sCol)/sizeof(sCol[0]); i++) {
  313.         if (stricmp(psz, sCol[i].pszCol) == 0) {
  314.             return sCol[i].lValue;
  315.         }
  316.     }
  317.     return CLR_BLACK;
  318. }
  319.  
  320. NLIN nlDefault = {CLR_BLACK, NULL, "Helv", 'C', 0, 12, 0, 0 };
  321.  
  322. BOOL LoadPresentation(PSZ pszFile)
  323. {
  324.     char szKeyword[10];
  325.     char szLine[80];
  326.     SHEET sheet;
  327.     NLIN line;
  328.     FILE *f = fopen(pszFile, "r");
  329.     if (f == NULL) {
  330.         sprintf(szLine, "Presentation file '%s' not found", pszFile);
  331.         WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szLine, szApp, 0, MB_ICONEXCLAMATION | MB_ENTER);
  332.         return FALSE;
  333.     }
  334.     PresInit();
  335.     sheet.usID = 0;
  336.     sheet.plFirst = NULL;
  337.     line = nlDefault;
  338.     while (!feof(f)) {
  339.         fscanf(f, "%s %[^\n]\n", szKeyword, szLine);
  340.         switch (KeywordId(szKeyword)) {
  341.         case K_TITLE    :    pres.pszTitle = strdup(szLine);            break;
  342.         case K_SIZE        :    PresSetSize(szLine);                            break;
  343.         case K_PAGE        :    PresLoadBmp(hpsBmp, szLine);                break;
  344.         case K_SHEET    :    SheetAddLine(&sheet, &line);
  345.                                 PresAddSheet(&pres, &sheet);
  346.                                 sheet.usID = atoi(szLine);                    break;
  347.         case K_MODE        :    sheet.usMode = toupper((*szLine));        break;
  348.         case K_NEXT        :    sheet.usNextID = atoi(szLine);            break;
  349.         case K_SLINE        :    SheetAddLine(&sheet, &line);
  350.                                 line.pszText = strdup(szLine);            break;
  351.         case K_ALIGN    :    line.usAlign = *szLine;                        break;
  352.         case K_FONT        :    strcpy(line.chFont, szLine);                break;
  353.         case K_TYPE        :    line.usType = LineParseType(szLine);    break;
  354.         case K_FX        :    line.usFx = LineParseFx(szLine);            break;
  355.         case K_POINT    :    line.usPoint = atoi(szLine);                break;
  356.         case K_COLOUR    :    line.lColour = LineParseColour(szLine);break;
  357.         case K_SUB        :    break;
  358.         case K_INVALID    :
  359.             sprintf(szLine, "Fout in presentatie bestand. (%s)", szKeyword);
  360.             WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szLine, szApp, 0, MB_ICONEXCLAMATION | MB_ENTER);
  361.             fclose(f);
  362.             return FALSE;
  363.         }
  364.     }
  365.     // term active line, term active sheet
  366.     SheetAddLine(&sheet, &line);
  367.     PresAddSheet(&pres, &sheet);
  368.     PresLinkSheets(&pres);
  369.     fclose(f);
  370.     return TRUE;
  371. }
  372.  
  373. CHAR  *apszFace[] = {
  374.     "Helv",
  375.     "Tms Rmn",
  376.    "Courier"
  377. };
  378.  
  379. VOID ClearScreen(HPS hps)
  380. {
  381.     GpiErase(hps);
  382.     if (pres.fHasbmp) {
  383.         POINTL aptl[3];
  384.         aptl[0].x = aptl[0].y = aptl[2].x = aptl[2].y = 0L;
  385.         aptl[1]   = ptlBmpsz;
  386.         GpiBitBlt(hps, hpsBmp, 3L, aptl, ROP_SRCCOPY, 0);
  387.     }
  388. }
  389.  
  390. #define X_MARGIN        10L
  391. #define Y_MARGIN        10L
  392. #define Y_DISTANCE    10L
  393.  
  394. VOID DrawScreen(HPS hps, PSHEET psh)
  395. {
  396.     PSLINE pl;
  397.     POINTL ptl;
  398.     ClearScreen(hps);
  399.     ptl.y = pres.ptlSize.y - Y_MARGIN;        
  400.     for (pl = psh->plFirst; pl != NULL; pl = pl->plNext) {
  401.         PresSetFont(hps, pl->hf);
  402.         switch (pl->usAlign) {
  403.         case 'C' :
  404.             ptl.x = (pres.ptlSize.x - pl->aptl[TXTBOX_BOTTOMRIGHT].x) / 2;
  405.             break;
  406.         case 'L' :
  407.             ptl.x = X_MARGIN;
  408.             if (psh->usMode == 'B') {                // bullet list
  409.                 POINTL ptlBullet;
  410.                 ULONG ulSize = pl->aptl[TXTBOX_TOPLEFT].y / 3;
  411.                 ptlBullet.x = X_MARGIN + ulSize;
  412.                 ptlBullet.y = ptl.y - pl->aptl[TXTBOX_TOPLEFT].y;
  413.                 GpiSetColor(hps, pl->lColour);
  414.                 GpiMove(hps, &ptlBullet);
  415.                 GpiFullArc(hps, DRO_FILL, MAKEFIXED(ulSize / 2, 0));
  416.                 ptl.x += ulSize * 3;
  417.             }
  418.             break;
  419.         case 'R' :
  420.             ptl.x = pres.ptlSize.x - pl->aptl[TXTBOX_BOTTOMRIGHT].x - X_MARGIN;
  421.             break;
  422.         case 'P' :        // previous so don't change
  423.             break;
  424.         }
  425.         ptl.y -= pl->aptl[TXTBOX_TOPLEFT].y * 5 / 4;
  426.         if (pl->usShadow) {
  427.             POINTL ptlSh;
  428.             ptlSh = ptl;
  429.             ptlSh.y -= pl->usShadow;
  430.             ptlSh.x += pl->usShadow;
  431.             GpiSetColor(hps, CLR_BLACK);
  432.             GpiCharStringAt(hps, &ptlSh, strlen(pl->pszText), pl->pszText);
  433.         }
  434.         if (pl->usDepth) {
  435.             POINTL ptlSh;
  436.             int i;
  437.             ptlSh = ptl;
  438.             ptlSh.y -= pl->usDepth;
  439.             ptlSh.x += pl->usDepth;
  440.             GpiSetColor(hps, CLR_BLACK);
  441.             for (i = pl->usDepth; i > 0; i--) {
  442.                 GpiCharStringAt(hps, &ptlSh, strlen(pl->pszText), pl->pszText);
  443.                 ptlSh.x--;
  444.                 ptlSh.y++;
  445.             }
  446.         }
  447.         GpiSetColor(hps, pl->lColour);
  448.         GpiCharStringAt(hps, &ptl, strlen(pl->pszText), pl->pszText);
  449.         ptl.y -= pl->aptl[TXTBOX_TOPLEFT].y / 4;
  450.     }
  451. }
  452.  
  453. VOID InitPresentation()
  454. {
  455.     CHAR szBuf[80];
  456.     SHORT y = (SHORT)pres.ptlSize.y +
  457.         WinQuerySysValue(HWND_DESKTOP, SV_CYTITLEBAR) +
  458.         WinQuerySysValue(HWND_DESKTOP, SV_CYMENU);
  459.     sprintf(szBuf, "%s : %s", szApp, pres.pszTitle);
  460.     WinSetWindowText(hwndFrame, szBuf);
  461.     WinSetWindowPos(hwndFrame, HWND_TOP, 0, 0,
  462.         (SHORT)pres.ptlSize.x, y, /*SWP_ACTIVATE |*/ SWP_SIZE /*| SWP_SHOW*/);
  463. }
  464.  
  465.  
  466. MRESULT EXPENTRY AboutDlgProc(HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  467. {
  468.     switch (msg) {
  469.     case WM_COMMAND :
  470.           switch (COMMANDMSG(&msg)->cmd) {
  471.           case ID_OK :
  472.            WinDismissDlg(hwnd, TRUE);
  473.            return 0;
  474.         }
  475.         break;
  476.     }
  477.    return WinDefDlgProc(hwnd, msg, mp1, mp2);
  478. }
  479.  
  480. MRESULT EXPENTRY GotoDlgProc(HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  481. {
  482.     switch (msg) {
  483.     case WM_COMMAND :              
  484.           switch (COMMANDMSG(&msg)->cmd) {
  485.           case ID_OK :
  486.            WinDismissDlg(hwnd, TRUE);
  487.            return 0;
  488.         }
  489.         break;
  490.     }
  491.    return WinDefDlgProc(hwnd, msg, mp1, mp2);
  492. }
  493.  
  494. VOID PresOpenFile(HWND hwnd)
  495. {
  496.     FILEDLG fdlg;
  497.     HWND hwndDlg;
  498.     memset(&fdlg, 0, sizeof(fdlg));
  499.     fdlg.cbSize = sizeof(fdlg);
  500.     fdlg.fl = FDS_CENTER | FDS_OPEN_DIALOG;
  501.     fdlg.pszTitle = "Select presentation file";
  502.     strcpy(fdlg.szFullFile, "*.PRS");
  503.     hwndDlg = WinFileDlg(HWND_DESKTOP, hwnd, &fdlg);
  504.     if (fdlg.lReturn == DID_OK) {
  505.         if (fPresSelected = LoadPresentation(fdlg.szFullFile)) {
  506.             InitPresentation();
  507.         }
  508.     }                
  509. }
  510.  
  511. MRESULT EXPENTRY PresWndProc(HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  512. {
  513.     static PSHEET psh = NULL;
  514.     static HWND hwndList;
  515.     HPS hpsPaint;
  516.     RECTL rcl;
  517.     static HPOINTER hptr;
  518.     POINTL aptl[3];
  519.     SIZEF sizf;
  520.     switch (msg) {
  521.     case WM_CREATE :
  522.         hptr = WinLoadPointer(HWND_DESKTOP, 0L, IDP_PTR);
  523.         GpiErase(hps);
  524.         PresSetFont(hps, PresGetFont(hps, "Tms Rmn", 120, FATTR_SEL_ITALIC));
  525.         GpiSetColor(hps, CLR_RED);
  526.         sizf.cx = MAKEFIXED(120, 0);
  527.         sizf.cy = MAKEFIXED(200, 0);
  528.         aptl[0].x = 20;
  529.         aptl[0].y = 80;
  530.         GpiSetCharBox(hps, &sizf);            // fix for this screen
  531.         GpiCharStringAt(hps, &aptl[0], 8L, "Present!");
  532.         PresSetFont(hps, PresGetFont(hps, "System Proportional", 10, FATTR_SEL_ITALIC));
  533.         aptl[0].y -= 24;
  534.         GpiSetColor(hps, CLR_DARKRED);
  535.         GpiCharStringAt(hps, &aptl[0], 57L, "(NC)Not Copyrighted by the Frobozz Magic Software Company");
  536.         break;
  537.     case WM_DESTROY :
  538.         WinDestroyPointer(hptr);
  539.         break;
  540.     case WM_MOUSEMOVE :
  541.         WinSetPointer(HWND_DESKTOP, hptr);
  542.         return (MRESULT)1L;
  543.     case WM_PAINT :
  544.         hpsPaint = WinBeginPaint(hwnd, 0L, &rcl);
  545.         WinFillRect(hpsPaint, &rcl, CLR_BACKGROUND);
  546.         aptl[1].x = rcl.xRight;
  547.         aptl[1].y = rcl.yTop;
  548.         aptl[0].x = aptl[2].x = rcl.xLeft;
  549.         aptl[0].y = aptl[2].y = rcl.yBottom;
  550.         GpiBitBlt(hpsPaint, hps, 3L, aptl, ROP_SRCCOPY, BBO_AND);
  551.         WinEndPaint(hpsPaint);
  552.         break;
  553.     case WM_BUTTON1UP :
  554.         if (psh->pshFollowing) {
  555.             psh = psh->pshFollowing;
  556.             WinPostMsg(hwnd, WM_USER, 0L, 0L);
  557.         }
  558.         break;
  559.     case WM_BUTTON2UP :
  560.         if (psh->pshPrev) {
  561.             psh = psh->pshPrev;
  562.             WinPostMsg(hwnd, WM_USER, 0L, 0L);
  563.         }
  564.         break;
  565.     case WM_SIZE :
  566.         WinInvalidateRect(hwnd, NULL, FALSE);    // repaint everything
  567.         break;
  568.     case WM_USER :
  569.         if (psh) {
  570.             DrawScreen(hps, psh);
  571.             WinInvalidateRect(hwnd, NULL, FALSE);
  572.         }
  573.         break;
  574.     case WM_CONTROL :
  575.         if (SHORT2FROMMP(mp1) == LN_ENTER) {
  576.             psh = WinSendMsg(hwndList, LM_QUERYITEMHANDLE,
  577.                 (MPARAM)WinSendMsg(hwndList, LM_QUERYSELECTION, 0L, 0L),
  578.                 0L);
  579.             WinSendMsg(hwndList, WM_DESTROY, 0L, 0L);    // drop list
  580.             WinSendMsg(hwnd, WM_USER, 0L, 0L);    // draw next sheet
  581.         }
  582.         break;
  583.     case WM_COMMAND :
  584.         switch (COMMANDMSG(&msg)->cmd) {
  585.         case IDM_OPEN :
  586.             PresOpenFile(hwnd);
  587.             psh = pres.pshFirst;
  588.             WinPostMsg(hwnd, WM_USER, 0L, 0L);
  589.             break;
  590.         case IDM_ABOUT :
  591.             WinDlgBox(HWND_DESKTOP, hwnd, (PFNWP)AboutDlgProc, 0L, IDD_ABOUT, 0L);
  592.             break;
  593.         case IDM_GOTO :
  594.         {
  595.             PSHEET psh = pres.pshFirst;
  596.             POINTL aptl[TXTBOX_COUNT];
  597.             hpsPaint = WinGetPS(hwnd);
  598.             GpiQueryTextBox(hpsPaint, 30, "The quick brown fox jumps over", TXTBOX_COUNT, aptl);
  599.             hwndList = WinCreateWindow(hwnd, WC_LISTBOX, "",
  600.                 WS_VISIBLE, 100, 100, (SHORT)aptl[TXTBOX_TOPRIGHT].x,
  601.                 6 * (SHORT)aptl[TXTBOX_TOPRIGHT].y, hwnd, HWND_TOP, ID_LISTWINDOW, NULL, NULL);
  602.             WinGetLastError(hab);
  603.             while (psh != NULL) {
  604.                 WinSendMsg(hwndList, LM_SETITEMHANDLE,
  605.                     (MPARAM)WinSendMsg(hwndList, LM_INSERTITEM, MPFROMSHORT(LIT_END), MPFROMP(psh->plFirst->pszText)),
  606.                     MPFROMP(psh));
  607.                 psh = psh->pshNext;
  608.             }
  609.             break;
  610.         }
  611.         case IDM_EXIT :
  612.             WinPostMsg(hwnd, WM_QUIT, 0L, 0L);
  613.             break;
  614.         }
  615.         break;
  616.     case WM_ERASEBACKGROUND :
  617.         return (MRESULT)TRUE;
  618.     default :
  619.        return WinDefWindowProc(hwnd, msg, mp1, mp2);
  620.     }
  621.     return 0L;
  622. }
  623.  
  624. VOID CreateHPS(VOID)
  625. {
  626.     BITMAPINFOHEADER bmp;
  627.     HBITMAP hbm;
  628.     SIZEL sizl;
  629.     hdcMem = DevOpenDC(hab, OD_MEMORY, "*", 0L, (PDEVOPENDATA)0, (HDC)0);
  630.     sizl.cx = 
  631.     sizl.cy = 0;
  632.     hps = GpiCreatePS(hab, hdcMem, &sizl, PU_PELS | GPIF_DEFAULT |
  633.                 GPIT_MICRO | GPIA_ASSOC);
  634.  
  635.     bmp.cbFix = sizeof(bmp);
  636.     bmp.cx = 640;
  637.     bmp.cy = 480;
  638.     bmp.cPlanes = 1;
  639.     bmp.cBitCount = 4;
  640.     hbm = GpiCreateBitmap(hps, (PBITMAPINFOHEADER2)&bmp, 0L, NULL, NULL);
  641.  
  642.     GpiSetBitmap(hps, hbm);
  643.  
  644.     hdcBmpmem = DevOpenDC(hab, OD_MEMORY, "*", 0L, NULL, (HDC)0);
  645.     hpsBmp = GpiCreatePS(hab, hdcBmpmem, &sizl, PU_PELS | GPIF_DEFAULT |
  646.                         GPIT_MICRO | GPIA_ASSOC);
  647.     PresInitFonts(hps);
  648. }
  649.  
  650. main()
  651. {
  652.     HMQ    hmq;
  653.     QMSG    qmsg;
  654.     ULONG    flFrameFlags = FCF_TITLEBAR | FCF_SYSMENU | FCF_SIZEBORDER | FCF_TASKLIST |
  655.                                 FCF_SHELLPOSITION | FCF_ICON | FCF_MENU | FCF_MINBUTTON;
  656.  
  657.     hab = WinInitialize(0);
  658.     hmq = WinCreateMsgQueue(hab, 0);
  659.  
  660.     CreateHPS();
  661.  
  662.     WinRegisterClass(hab, szApp, (PFNWP)PresWndProc, 0,  0);
  663.  
  664.     hwndFrame = WinCreateStdWindow(HWND_DESKTOP, WS_VISIBLE | WS_SYNCPAINT,
  665.                                             &flFrameFlags, szApp, szApp,
  666.                                             0L, (HMODULE)0, ID_APP, &hwndClient);
  667.  
  668.     while (WinGetMsg(hab, &qmsg, (HWND)0, 0, 0)) {
  669.         WinDispatchMsg(hab, &qmsg);
  670.     }
  671.     WinDestroyWindow(hwndFrame);
  672.     WinDestroyMsgQueue(hmq);
  673.     WinTerminate(hab);
  674.     return 0;
  675. }
  676.  
  677.  
  678.