home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-386-Vol-2of3.iso / t / triq.zip / TRI.C < prev    next >
C/C++ Source or Header  |  1991-09-10  |  21KB  |  723 lines

  1. /*----------------------------------------------------------------------------*\
  2. |   tri.c - A sample app to demonstrate the DIB Driver                   |
  3. |                                                                              |
  4. \*----------------------------------------------------------------------------*/
  5.  
  6. /*
  7.      (C) Copyright Microsoft Corp. 1991.  All rights reserved.
  8.  
  9.      You have a royalty-free right to use, modify, reproduce and 
  10.      distribute the Sample Files (and/or any modified version) in 
  11.      any way you find useful, provided that you agree that 
  12.      Microsoft has no warranty obligations or liability for any 
  13.      Sample Application Files which are modified. 
  14.  */
  15.  
  16.  
  17. /*----------------------------------------------------------------------------*\
  18. |                                                                              |
  19. |   g e n e r a l   c o n s t a n t s                                          |
  20. |                                                                              |
  21. \*----------------------------------------------------------------------------*/
  22.  
  23. #define MAXSTR   80
  24.  
  25. /*----------------------------------------------------------------------------*\
  26. |                                                                              |
  27. |   i n c l u d e   f i l e s                                                  |
  28. |                                                                              |
  29. \*----------------------------------------------------------------------------*/
  30.  
  31. #define SWAP(x,y)   ((x)^=(y)^=(x)^=(y))
  32.  
  33. // define if we want to force bitmap to <64K (ie, 320x200)
  34. // note: bitmap include BITMAPINFOHEADER and pal 
  35.  
  36. //#define SMALLBITMAP
  37.  
  38.  
  39. #define  NOLFILEIO
  40. #include <windows.h>
  41. #include <stdlib.h>    // for rand()
  42. #include "triq.h"
  43. #include "dib.h"
  44.  
  45. /*----------------------------------------------------------------------------*\
  46. |                                                                              |
  47. |   g l o b a l   v a r i a b l e s                                            |
  48. |                                                                              |
  49. \*----------------------------------------------------------------------------*/
  50. static  char    szAppName[]="Triangle App";
  51.  
  52. static  HANDLE  hInstApp;
  53. static  HWND    hwndApp;
  54. static  HPALETTE hpalApp;
  55. static  HPALETTE hpalT1;
  56. static  HPALETTE hpalT2;
  57.  
  58. BOOL    fActiveApp=TRUE;
  59.  
  60. BOOL    fUseBlit=TRUE;
  61. BOOL    fUseDIB=FALSE;
  62. BOOL    fUseCustom=FALSE;
  63. BOOL    fUseGDI=FALSE;
  64. BOOL    fSolidColors=FALSE;
  65. BOOL    fNullPen=TRUE;
  66. BOOL    fBoxes=FALSE;
  67. unsigned wUseSkip=MENU_EVERY;
  68. unsigned wskipmask=0xffff;
  69.  
  70.  
  71. PSTR    szText;
  72. char    szString[MAXSTR];
  73. short   xClient, yClient;
  74.  
  75.  
  76. HDC     hdcDib1;
  77. HANDLE  hdib1   = NULL;      // memory DIB
  78.  
  79. HDC    hdcDib2;
  80. HANDLE  hdib2   = NULL;      // memory DIB
  81.  
  82. LPSTR    lpdib1;
  83. LPSTR   lpdib2;
  84.  
  85. BOOL    fDibCur=0;
  86.  
  87. HPALETTE hpalEx;
  88. HPALETTE hpalSystem;
  89. HPALETTE hpalPalette   = NULL;      // current real-palette
  90. HPALETTE hpalCurrent   = NULL;      // current dib-palette
  91. HANDLE   hdibCurrent   = NULL;      // memory DIB
  92.  
  93. WORD askipmask[MENU_SKIP_MAX - MENU_SKIP_MIN +1]=
  94. {
  95.     0xffff,    // MENU_EVERY
  96.     0xfffe,    // MENU_SKIP2
  97.     0xfff7,    // MENU_SKIP4
  98.     0xfff0,     // MENU_SKIP8
  99.     0xffe0,    // MENU_SKIP16
  100.     0x0000    // MENU_SKIPALL
  101. };
  102.  
  103. /*----------------------------------------------------------------------------*\
  104. |                                                                              |
  105. |   f u n c t i o n   d e f i n i t i o n s                                    |
  106. |                                                                              |
  107. \*----------------------------------------------------------------------------*/
  108.  
  109. LONG FAR PASCAL AppWndProc (HWND hwnd, unsigned uiMessage, WORD wParam, LONG lParam);
  110. VOID FAR PASCAL Triangle(HDC hDC, LPPOINT lpPoints);
  111. VOID FAR PASCAL DIBTriangle(LPSTR lpdib, LPPOINT lpPoints, WORD crCol);
  112. BOOL fDialog(int id,HWND hwnd,FARPROC fpfn);
  113.  
  114. int ErrMsg (LPSTR sz,...);
  115.  
  116. void redraw(void);
  117.  
  118. /*----------------------------------------------------------------------------*\
  119. |   AppAbout( hDlg, uiMessage, wParam, lParam )                    |
  120. |                                           |
  121. |   Description:                                   |
  122. |    This function handles messages belonging to the "About" dialog box.    |
  123. |    The only message that it looks for is WM_COMMAND, indicating the use   |
  124. |    has pressed the "OK" button.  When this happens, it takes down           |
  125. |    the dialog box.                                |
  126. |                                           |
  127. |   Arguments:                                       |
  128. |    hDlg        window handle of about dialog window               |
  129. |    uiMessage    message number                           |
  130. |    wParam        message-dependent                       |
  131. |    lParam        message-dependent                       |
  132. |                                           |
  133. |   Returns:                                       |
  134. |    TRUE if message has been processed, else FALSE                   |
  135. |                                           |
  136. \*----------------------------------------------------------------------------*/
  137. BOOL FAR PASCAL AppAbout( hDlg, uiMessage, wParam, lParam )
  138.     HWND     hDlg;
  139.     unsigned uiMessage;
  140.     WORD     wParam;
  141.     long     lParam;
  142. {
  143.     switch (uiMessage) 
  144.     {
  145.         case WM_COMMAND:
  146.             if (wParam == IDOK)
  147.                 EndDialog(hDlg,TRUE);
  148.         break;
  149.  
  150.     case WM_INITDIALOG:
  151.         return TRUE;
  152.     }
  153.     return FALSE;
  154. }
  155.  
  156. /*----------------------------------------------------------------------------*\
  157. |   AppInit( hInst, hPrev)                               |
  158. |                                           |
  159. |   Description:                                   |
  160. |    This is called when the application is first loaded into           |
  161. |    memory.  It performs all initialization that doesn't need to be done   |
  162. |    once per instance.                               |
  163. |                                           |
  164. |   Arguments:                                       |
  165. |    hInstance    instance handle of current instance               |
  166. |    hPrev        instance handle of previous instance               |
  167. |                                           |
  168. |   Returns:                                       |
  169. |    TRUE if successful, FALSE if not                       |
  170. |                                           |
  171. \*----------------------------------------------------------------------------*/
  172. BOOL AppInit(HANDLE hInst,HANDLE hPrev,WORD sw,LPSTR szCmdLine)
  173. {
  174.     WNDCLASS cls;
  175.     int      dx,dy;
  176.     char     ach[80];
  177.     HMENU    hmenu;
  178.  
  179.     /* Save instance handle for DialogBoxs */
  180.     hInstApp = hInst;
  181.  
  182.     if (!hPrev) 
  183.     {
  184.     /*
  185.      *  Register a class for the main application window
  186.      */
  187.         cls.hCursor        = LoadCursor(NULL,IDC_ARROW);
  188.         cls.hIcon          = LoadIcon(hInst,MAKEINTATOM(ID_APP));
  189.         cls.lpszMenuName   = MAKEINTATOM(ID_APP);
  190.         cls.lpszClassName  = MAKEINTATOM(ID_APP);
  191.         cls.hbrBackground  = (HBRUSH)COLOR_WINDOW + 1;
  192.         cls.hInstance      = hInst;
  193.         cls.style          = CS_BYTEALIGNCLIENT | CS_VREDRAW | CS_HREDRAW | CS_DBLCLKS;
  194.         cls.lpfnWndProc    = AppWndProc;
  195.         cls.cbWndExtra     = 0;
  196.         cls.cbClsExtra     = 0;
  197.  
  198.         if (!RegisterClass(&cls))
  199.         return FALSE;
  200.     }
  201.  
  202.     
  203.     hpalApp = CreateExplicitPalette();
  204.  
  205.     dx = GetSystemMetrics (SM_CXSCREEN);
  206.     dy = GetSystemMetrics (SM_CYSCREEN);
  207.  
  208.     hwndApp = CreateWindow (MAKEINTATOM(ID_APP),    // Class name
  209.                             szAppName,              // Caption
  210.                             WS_OVERLAPPEDWINDOW,    // Style bits
  211.                             CW_USEDEFAULT, CW_USEDEFAULT,       // Position
  212.                             CW_USEDEFAULT, CW_USEDEFAULT,       // Size
  213.                             (HWND)NULL,             // Parent window (no parent)
  214.                             (HMENU)NULL,            // use class menu
  215.                             (HANDLE)hInst,          // handle to window instance
  216.                             (LPSTR)NULL             // no params to pass on
  217.                            );
  218.                
  219.     ShowWindow(hwndApp,sw);
  220.  
  221.     return TRUE;
  222. }
  223.  
  224. static drawcount=0;
  225.  
  226. void DrawTriangle(void)
  227. {
  228.     HBRUSH  hBrush;
  229.     DWORD   rgb;
  230.     POINT   pts[10];
  231.     int     n;
  232.     int     nPoints;
  233.     short   nRed, nGreen, nBlue;
  234.     LPSTR lpdib;
  235.  
  236.     HPALETTE hpalT;
  237.     HDC hdc;
  238.  
  239.     if(!fUseDIB)
  240.     {
  241.     hdc = GetDC(hwndApp);
  242.     if (hpalApp)
  243.     {
  244.         hpalT = SelectPalette(hdc,hpalApp,FALSE);
  245.         RealizePalette(hdc);
  246.     }
  247.  
  248.     }
  249.     else
  250.     {
  251.     if(fDibCur)
  252.     {
  253.         hdc=hdcDib2;
  254.         lpdib=lpdib2;
  255.     }
  256.     else
  257.     {
  258.         hdc=hdcDib1;
  259.         lpdib=lpdib1;
  260.     }
  261.     
  262.     }
  263.  
  264.     nPoints = fBoxes ? 4 : 3 ;
  265.     
  266.     for (n=0; n<nPoints; n++)
  267.     {
  268.     pts[n].x = rand() % xClient;
  269.     pts[n].y = rand() % yClient;
  270.     }
  271.  
  272.     pts[n] = pts[0];
  273.     
  274.     nRed    = rand() % 255;
  275.     nGreen  = rand() % 255;
  276.     nBlue   = rand() % 255;
  277.     
  278.     rgb = RGB(nRed, nGreen, nBlue);
  279.     
  280.     if (fSolidColors)
  281.     rgb = PALETTEINDEX(nRed);
  282.  
  283.     hBrush = CreateSolidBrush(rgb);
  284.     
  285.     hBrush = SelectObject(hdc, hBrush);
  286.  
  287.     if (fNullPen)
  288.     SelectObject(hdc, GetStockObject(NULL_PEN));
  289.  
  290.     if(fUseCustom)
  291.     {
  292.     DIBTriangle(lpdib, pts, nRed);
  293.     if (!fNullPen)
  294.         Polyline(hdc, pts, nPoints+1);
  295.     }
  296.     else if (fUseGDI) 
  297.     {
  298.     Polygon(hdc, pts, nPoints);
  299.     }
  300.     else // use special pat blit
  301.     {
  302.     Triangle(hdc, pts);
  303.     if (!fNullPen)
  304.         Polyline(hdc, pts, nPoints+1);
  305.     }
  306.     
  307.     DeleteObject(SelectObject(hdc, hBrush));
  308.     
  309.     drawcount++;
  310.     
  311.     if(!fUseDIB)
  312.     {
  313.     if (hpalApp)
  314.         SelectPalette(hdc,hpalT,FALSE);
  315.     
  316.         
  317.     ReleaseDC(hwndApp,hdc);
  318.     }
  319.     else
  320.     {
  321.     if((drawcount & wskipmask) == drawcount)
  322.         redraw();
  323.     
  324.     if(!fUseBlit)
  325.     {
  326.         // switch current dibs if delta-frame
  327.         fDibCur=!fDibCur;
  328.         // need to copy cur to last...
  329.     }
  330.     }
  331. }
  332.  
  333. void redraw(void)
  334. {
  335.     HDC hdc;
  336.     HPALETTE hpalT;
  337.     
  338.     hdc = GetDC(hwndApp);
  339.     if (hpalApp)
  340.     {
  341.     hpalT = SelectPalette(hdc,hpalApp,FALSE);
  342.     RealizePalette(hdc);
  343.     }
  344.     
  345.     DibBlt(hdc,0,0,-1,-1,fDibCur ? hdib2 : hdib1, 0,0, SRCCOPY, DIB_PAL_COLORS);
  346.     
  347.     if (hpalApp)
  348.     SelectPalette(hdc,hpalT,FALSE);
  349.     
  350.     ReleaseDC(hwndApp,hdc);
  351. }
  352.  
  353. /*----------------------------------------------------------------------------*\
  354. |   WinMain( hInst, hPrev, lpszCmdLine, cmdShow )                   |
  355. |                                                                              |
  356. |   Description:                                                               |
  357. |       The main procedure for the App.  After initializing, it just goes      |
  358. |       into a message-processing loop until it gets a WM_QUIT message         |
  359. |       (meaning the app was closed).                                          |
  360. |                                                                              |
  361. |   Arguments:                                                                 |
  362. |    hInst        instance handle of this instance of the app           |
  363. |    hPrev        instance handle of previous instance, NULL if first    |
  364. |       szCmdLine       ->null-terminated command line                         |
  365. |       cmdShow         specifies how the window is initially displayed        |
  366. |                                                                              |
  367. |   Returns:                                                                   |
  368. |       The exit code as specified in the WM_QUIT message.                     |
  369. |                                                                              |
  370. \*----------------------------------------------------------------------------*/
  371. int PASCAL WinMain(HANDLE hInst, HANDLE hPrev, LPSTR szCmdLine, WORD sw)
  372. {
  373.     MSG     msg;
  374.  
  375.     /* Call initialization procedure */
  376.     if (!AppInit(hInst,hPrev,sw,szCmdLine))
  377.         return FALSE;
  378.     
  379.     hdib1 = CreateDib(8,xClient,yClient);
  380.     hdib2 = CreateDib(8,xClient,yClient);
  381.     
  382.     SetDibUsage(hdib1, hpalApp, DIB_PAL_COLORS);
  383.     SetDibUsage(hdib2, hpalApp, DIB_PAL_COLORS);
  384.     
  385.     lpdib1=GlobalLock(hdib1);
  386.     lpdib2=GlobalLock(hdib2);
  387.     
  388.     hdcDib1 = CreateDC("DIB",NULL,NULL,lpdib1);
  389.     hdcDib2 = CreateDC("DIB",NULL,NULL,lpdib2);
  390.  
  391.     if (hpalApp)
  392.     {
  393.     hpalT1 = SelectPalette(hdcDib1,CreateExplicitPalette(),FALSE);
  394.     RealizePalette(hdcDib1);
  395.     hpalT2 = SelectPalette(hdcDib2,CreateExplicitPalette(),FALSE);
  396.     RealizePalette(hdcDib2);
  397.     }
  398.     
  399.     
  400.     /*
  401.      * Polling messages from event queue
  402.      */
  403.  
  404.     while (TRUE) 
  405.     {
  406.     if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) 
  407.     {
  408.         if (msg.message == WM_QUIT)
  409.         break;
  410.  
  411.         TranslateMessage(&msg);
  412.         DispatchMessage(&msg);
  413.     }
  414.     else if(fActiveApp)
  415.     {
  416.         DrawTriangle();
  417.  
  418.     }
  419.     else
  420.     {
  421.         // wait for a message so we don't chew time with loop
  422.             WaitMessage();
  423.     }
  424.  
  425.     }
  426.     if (hpalApp)
  427.     {
  428.     DeleteObject(SelectPalette(hdcDib1,hpalT1,FALSE));
  429.     DeleteObject(SelectPalette(hdcDib2,hpalT2,FALSE));
  430.     }
  431.     
  432.     DeleteDC(hdcDib1);
  433.     DeleteDC(hdcDib2);
  434.     
  435.     GlobalUnlock(hdib1);
  436.     GlobalUnlock(hdib2);
  437.     GlobalFree(hdib1);
  438.     GlobalFree(hdib2);
  439.  
  440.     return msg.wParam;
  441. }
  442.  
  443. /*----------------------------------------------------------------------------*\
  444. |                                                                              |
  445. |   w i n d o w   p r o c s                                                    |
  446. |                                                                              |
  447. \*----------------------------------------------------------------------------*/
  448.  
  449. /*----------------------------------------------------------------------------*\
  450. |   AppWndProc( hwnd, uiMessage, wParam, lParam )                   |
  451. |                                                                              |
  452. |   Description:                                                               |
  453. |       The window proc for the app's main (tiled) window.  This processes all |
  454. |       of the parent window's messages.                                       |
  455. |                                                                              |
  456. |   Arguments:                                                                 |
  457. |    hwnd        window handle for the window                   |
  458. |       uiMessage       message number                                         |
  459. |       wParam          message-dependent                                      |
  460. |       lParam          message-dependent                                      |
  461. |                                                                              |
  462. |   Returns:                                                                   |
  463. |       0 if processed, nonzero if ignored                                     |
  464. |                                                                              |
  465. \*----------------------------------------------------------------------------*/
  466. LONG FAR PASCAL AppWndProc(hwnd, msg, wParam, lParam)
  467.     HWND     hwnd;
  468.     unsigned msg;
  469.     WORD     wParam;
  470.     long     lParam;
  471. {
  472.     PAINTSTRUCT ps;
  473.     BOOL        f;
  474.     HDC         hdc;
  475.     DWORD       dwTime;
  476.     int         i;
  477.     HPALETTE    hpalT;
  478.  
  479.     switch (msg) 
  480.     {
  481.     case WM_ACTIVATEAPP:
  482.         fActiveApp=wParam;
  483.         break;
  484.     case WM_INITMENU:
  485.         if(fUseCustom)
  486.         {
  487.         CheckMenuItem((HMENU)wParam,MENU_USEGDI, MF_UNCHECKED);
  488.         CheckMenuItem((HMENU)wParam,MENU_USEPAT, MF_UNCHECKED);
  489.         CheckMenuItem((HMENU)wParam,MENU_USECUSTOM, MF_CHECKED);
  490.         }
  491.         else
  492.         {
  493.         CheckMenuItem((HMENU)wParam,MENU_USEGDI,
  494.             fUseGDI ? MF_CHECKED : MF_UNCHECKED);
  495.         CheckMenuItem((HMENU)wParam,MENU_USEPAT,
  496.             fUseGDI ? MF_UNCHECKED : MF_CHECKED);
  497.         CheckMenuItem((HMENU)wParam,MENU_USECUSTOM, MF_UNCHECKED);
  498.         }
  499.         for(i=MENU_DIB_MIN;i<=MENU_DIB_MAX;i++)
  500.         {
  501.         EnableMenuItem((HMENU)wParam, i ,
  502.                 fUseDIB ?  MF_ENABLED : MF_GRAYED);
  503.         CheckMenuItem((HMENU)wParam, i, MF_UNCHECKED);
  504.         }
  505.         CheckMenuItem((HMENU)wParam, wUseSkip, MF_CHECKED);
  506.         
  507.             EnableMenuItem((HMENU)wParam,MENU_DIB,
  508.             hdcDib1 ?  MF_ENABLED : MF_GRAYED);
  509.             
  510.             EnableMenuItem((HMENU)wParam,MENU_USECUSTOM,
  511.             fUseDIB ?  MF_ENABLED : MF_GRAYED);
  512.             
  513.         CheckMenuItem((HMENU)wParam,MENU_DIB,
  514.             fUseDIB ? MF_CHECKED : MF_UNCHECKED);
  515.         CheckMenuItem((HMENU)wParam,MENU_SCREEN,
  516.             fUseDIB ? MF_UNCHECKED : MF_CHECKED);
  517.         
  518.         CheckMenuItem((HMENU)wParam,MENU_SOLID,
  519.             fSolidColors ? MF_CHECKED : MF_UNCHECKED);
  520.         CheckMenuItem((HMENU)wParam,MENU_NULLPEN,
  521.             fNullPen ? MF_CHECKED : MF_UNCHECKED);
  522.         CheckMenuItem((HMENU)wParam,MENU_BOXES,
  523.             fBoxes ? MF_CHECKED : MF_UNCHECKED);
  524.         break;
  525.  
  526.     case WM_COMMAND:
  527.         switch (wParam) 
  528.         {
  529.         case MENU_ABOUT:
  530.             fDialog(ABOUTBOX,hwnd,AppAbout);
  531.             break;
  532.         
  533.         case MENU_USECUSTOM:
  534.             fUseCustom=!fUseCustom;
  535.             break;
  536.             
  537.         case MENU_SKIP2:
  538.         case MENU_SKIP4:
  539.         case MENU_SKIP8:
  540.         case MENU_SKIP16:
  541.         case MENU_SKIPALL:
  542.         case MENU_EVERY:
  543.             wskipmask=askipmask[wParam-MENU_SKIP_MIN];
  544.             wUseSkip=wParam;
  545.             break;
  546.             
  547.         case MENU_REDRAW:
  548.             redraw();
  549.             break;
  550.             
  551.             
  552.         case MENU_DIB:
  553.         case MENU_SCREEN:
  554.             fUseDIB=!fUseDIB;
  555.             if(!fUseDIB)
  556.             fUseCustom=FALSE;
  557.             break;
  558.             
  559.         case MENU_EXIT:
  560.             PostMessage(hwnd,WM_CLOSE,0,0L);
  561.             break;
  562.  
  563.         case MENU_USEPAT:
  564.         case MENU_USEGDI:
  565.             fUseGDI = !fUseGDI;
  566.             fUseCustom=FALSE;
  567.             break;
  568.             
  569.         case MENU_BOXES:
  570.             fBoxes = !fBoxes;
  571.             break;
  572.  
  573.         case MENU_SOLID:
  574.             fSolidColors = !fSolidColors;
  575.             break;
  576.  
  577.         case MENU_NULLPEN:
  578.             fNullPen = !fNullPen;
  579.             break;
  580.  
  581.                 case MENU_TIMEIT:
  582.             InvalidateRect(hwnd,NULL,TRUE);
  583.             UpdateWindow(hwnd);
  584.             
  585.             #define N 512
  586.  
  587. #if 0        
  588.             hdc = GetDC(hwnd);
  589.  
  590.             if (hpalApp)
  591.             {
  592.             hpalT = SelectPalette(hdc,hpalApp,FALSE);
  593.             RealizePalette(hdc);
  594.             }
  595. #endif
  596.             dwTime = GetCurrentTime();
  597.             
  598.             for (i=0; i<N; i++)
  599.             DrawTriangle();
  600.  
  601.             dwTime = GetCurrentTime() - dwTime;
  602. #if 0
  603.             if (hpalApp)
  604.             SelectPalette(hdc,hpalT,FALSE);
  605.  
  606.             ReleaseDC(hwnd,hdc);
  607. #endif
  608.             redraw();
  609.         
  610.             ErrMsg("%d Tri's in %d.%04d sec\n%d.%04d sec per Tri",
  611.                 N,
  612.                 (WORD)(dwTime / 1000), (WORD)(dwTime % 1000),
  613.                 (WORD)((dwTime/N)/1000), (WORD)((dwTime/N) % 1000)
  614.                     );
  615.  
  616.             break;
  617.         }
  618.         break;
  619.  
  620.     case WM_SIZE:
  621. #ifndef SMALLBITMAP        
  622.         xClient = LOWORD(lParam);
  623.         yClient = HIWORD(lParam);
  624. #else
  625.         xClient = 320;
  626.         yClient = 200;
  627. #endif        
  628.         break;
  629.  
  630.     case WM_DESTROY:
  631.         PostQuitMessage(0);
  632.         break;
  633.  
  634.     }
  635.  
  636.     return DefWindowProc(hwnd,msg,wParam,lParam);
  637. }
  638.  
  639. /*----------------------------------------------------------------------------*\
  640. |   ErrMsg - Opens a Message box with a error message in it.  The user can     |
  641. |         select the OK button to continue or the CANCEL button to kill     |
  642. |         the parent application.                           |
  643. \*----------------------------------------------------------------------------*/
  644. int ErrMsg (LPSTR sz,...)
  645. {
  646.     char ach[128];
  647.  
  648.     wvsprintf (ach,sz,(LPSTR)(&sz+1));   /* Format the string */
  649.     MessageBox(NULL,ach,NULL,MB_OK);
  650.     return FALSE;
  651. }
  652.  
  653. #if 0
  654.  
  655. void NEAR PASCAL DIBOutScan(LPSTR lpBuf, WORD curY, WORD start, WORD end, WORD val)
  656. {
  657.     // using huge allows big bitmaps... if you know bitmap is <64K, use
  658.     // just far for faster operation
  659. #ifndef SMALLBITMAP    
  660.     char huge * hpBuf;
  661. #else
  662.     char far * hpBuf;
  663. #endif
  664.     LPBITMAPINFOHEADER    lpbi;
  665.     WORD cy;
  666.  
  667.     
  668.     lpbi=(LPBITMAPINFOHEADER)lpBuf;
  669.  
  670. #if 1
  671.     if(end<start)
  672.     SWAP(end,start);
  673. #endif 
  674.     // invert coord system
  675.     cy=lpbi->biHeight-1 - curY;
  676.     
  677.     // assume 8-bit dib. (therefore, 256 pal entries)
  678.     // assume BITMAPINFOHEADER (therfore, RGBQUAD)
  679.     
  680.     hpBuf=lpBuf;
  681.     hpBuf+=(lpbi->biSize + 256*sizeof(RGBQUAD));
  682. //    hpBuf+=(char huge *)lpBuf;
  683.     hpBuf+=(WORD)(cy* (((WORD)lpbi->biWidth+3)&~3)) + start;
  684.     
  685.     cy=end-start+1;   // cy is num of pels
  686.     
  687.     while(cy--)
  688.     {
  689.     *hpBuf++=(BYTE)val;
  690.     }
  691. }
  692.  
  693. #endif
  694.  
  695. /*----------------------------------------------------------------------------*\
  696. |   fDialog(id,hwnd,fpfn)                               |
  697. |                                           |
  698. |   Description:                                                               |
  699. |    This function displays a dialog box and returns the exit code.           |
  700. |    the function passed will have a proc instance made for it.           |
  701. |                                           |
  702. |   Arguments:                                                                 |
  703. |    id        resource id of dialog to display               |
  704. |    hwnd        parent window of dialog                    |
  705. |    fpfn        dialog message function                    |
  706. |                                                                              |
  707. |   Returns:                                                                   |
  708. |    exit code of dialog (what was passed to EndDialog)               |
  709. |                                                                              |
  710. \*----------------------------------------------------------------------------*/
  711. BOOL fDialog(int id,HWND hwnd,FARPROC fpfn)
  712. {
  713.     BOOL    f;
  714.     HANDLE    hInst;
  715.  
  716.     hInst = GetWindowWord(hwnd,GWW_HINSTANCE);
  717.     fpfn  = MakeProcInstance(fpfn,hInst);
  718.     f = DialogBox(hInst,MAKEINTRESOURCE(id),hwnd,fpfn);
  719.     FreeProcInstance (fpfn);
  720.     return f;
  721. }
  722.  
  723.