home *** CD-ROM | disk | FTP | other *** search
/ CICA 1992 November / CICA_MS_Windows_CD-ROM_Walnut_Creek_November_1992.iso / win3 / misc / instal / install.c < prev    next >
C/C++ Source or Header  |  1991-06-12  |  25KB  |  678 lines

  1. /*----------------------------------------------------------------------------*\
  2. |   install.c - A template for a Windows application installer                   |
  3. |                                                                              |
  4. \*----------------------------------------------------------------------------*/
  5.  
  6. /*----------------------------------------------------------------------------*\
  7. |                                                                              |
  8. |   i n c l u d e   f i l e s                                                  |
  9. |                                                                              |
  10. \*----------------------------------------------------------------------------*/
  11.  
  12. #include "lobotomy.h"
  13. #include <windows.h>
  14.  
  15. #include "wslib\sulib.h"
  16. #include "wslib\ws.h"
  17. #include "wslib\progdde.h"
  18. #include "wslib\gauge.h"
  19. #include "install.h"
  20.  
  21. /*----------------------------------------------------------------------------*\
  22. |                                                                              |
  23. |   g l o b a l   v a r i a b l e s                                            |
  24. |                                                                              |
  25. \*----------------------------------------------------------------------------*/
  26.  
  27. char    szCaption[] = "Setup Application";
  28. char    szNull[]    = "";
  29. HWND    hwndWS;
  30. HANDLE    hInstWS;
  31. BOOL    fMono;
  32. PSTR    szText;
  33. char    szString[MAXSTR];
  34. int    dyChar;
  35. int    dxChar;
  36. WORD    capsScreen;
  37. WORD    fExit;
  38. char    bufTmp[MAXSTR];
  39. PSTR    pErrMsg;
  40.  
  41. /*----------------------------------------------------------------------------*\
  42. |                                                                              |
  43. |   f u n c t i o n   d e f i n i t i o n s                                    |
  44. |                                                                              |
  45. \*----------------------------------------------------------------------------*/
  46.  
  47. LONG FAR PASCAL AppWndProc (HWND hwnd, unsigned uiMessage, WORD wParam, LONG lParam);
  48. void PRIVATE infDlgFixup(HWND hwnd);
  49. LONG NEAR PASCAL AppCommand(HWND hwnd, unsigned msg, WORD wParam, LONG lParam);
  50. BOOL FAR PASCAL AppExit(HWND hDlg, unsigned uiMessage, WORD wParam, LONG lParam);
  51. BOOL PRIVATE fnCheckDiskSpace(void);
  52.  
  53. /*----------------------------------------------------------------------------*\
  54. |   AppInit( hInst, hPrev)                                                     |
  55. |                                                                              |
  56. |   Description:                                                               |
  57. |    This procedure is called when the application is first loaded into         |
  58. |    memory.  It performs any initialization tasks that need to be done only     |
  59. |  for the first instance of the application.                                  |
  60. |                                                                              |
  61. |   Arguments:                                                                 |
  62. |    hInstance    instance handle of current instance                             |
  63. |    hPrev        instance handle of previous instance                               |
  64. |                                                                              |
  65. |   Returns:                                                                   |
  66. |    TRUE if successful, FALSE if not                                            |
  67. |                                                                              |
  68. \*----------------------------------------------------------------------------*/
  69. BOOL AppInit(HANDLE hInst,HANDLE hPrev,WORD sw,LPSTR szCmdLine)
  70. {
  71.     WNDCLASS    cls;
  72.     int         dx,dy;
  73.     char        ach[80];
  74.     HMENU       hmenu;
  75.     HDC         hdc;
  76.     OFSTRUCT    os;
  77.     char        szAppName[MAXSTR];
  78.     char        buf[MAXSTR];
  79.     RECT        rc;
  80.     TEXTMETRIC  tm;
  81.     PINF    pinf;
  82.  
  83. #ifdef DEBUG
  84.     dprintf("%C");
  85. #endif
  86.  
  87.     /* Save the instance handle for the DialogBox */
  88.     hInstWS = hInst;
  89.  
  90.     /* Display the hourglass cursor */
  91.     wsStartWait();
  92.  
  93.     if (OpenFile(wsLoadSz(IDS_INFNAME,NULL), &os, OF_EXIST) == -1) {
  94.         wsEndWait();
  95.     MessageBox(NULL, wsLoadSz(IDS_NOINF, NULL), szCaption, MB_OK | MB_ICONEXCLAMATION);
  96.     return FALSE;
  97.     }
  98.  
  99.     GlobalCompact((LONG)(-1));        // help infOpen() succeed
  100.  
  101.     pinf = infOpen(os.szPathName);
  102.  
  103.     wsEndWait();
  104.  
  105.     WinAssert(pinf);
  106.     if (!pinf) {
  107.     MessageBox(NULL, wsLoadSz(IDS_NOINFMEM, NULL), szCaption, MB_OK | MB_ICONEXCLAMATION);
  108.     return FALSE;
  109.     }
  110.     
  111.     hdc  = GetDC(NULL);
  112.     fMono = GetDeviceCaps(hdc, NUMCOLORS) == 2;
  113.     capsScreen = GetDeviceCaps(hdc, RASTERCAPS);
  114.     GetTextMetrics(hdc,&tm);
  115.     dyChar = tm.tmHeight;
  116.     dxChar = tm.tmAveCharWidth;
  117.     ReleaseDC(NULL,hdc);
  118.  
  119.     if (!hPrev) {
  120.  
  121.        /* Register a class for the main application window */
  122.  
  123.         cls.hCursor        = LoadCursor(NULL,IDC_ARROW);
  124.         cls.hIcon          = NULL; //LoadIcon(hInst,MAKEINTATOM(ID_APP));
  125.         cls.lpszMenuName   = NULL;
  126.         cls.lpszClassName  = MAKEINTATOM(ID_APP);
  127.         cls.hbrBackground  = (HBRUSH)COLOR_WINDOW + 1;
  128.         cls.hInstance      = hInst;
  129.         cls.style          = CS_BYTEALIGNCLIENT | CS_VREDRAW | CS_HREDRAW | CS_DBLCLKS;
  130.         cls.lpfnWndProc    = AppWndProc;
  131.         cls.cbWndExtra     = 0;
  132.         cls.cbClsExtra     = 0;
  133.  
  134.         if (!RegisterClass(&cls))
  135.         return FALSE;
  136.     }
  137.  
  138.     hwndWS = CreateWindow (MAKEINTATOM(ID_APP),     // Class name
  139.                             szAppName,              // Caption
  140.                             WS_OVERLAPPEDWINDOW,    // Style bits
  141.                             0,0,0,0,                // Position, size
  142.                             (HWND)NULL,             // Parent window (no parent)
  143.                             (HMENU)NULL,            // use class menu
  144.                             (HANDLE)hInst,          // handle to window instance
  145.                             (LPSTR)NULL             // no params to pass on
  146.                             );
  147.  
  148.  
  149.     /* Create the "stext" class used in progress dialogs */
  150.     if (!ControlInit(hPrev,hInst))
  151.         return FALSE;
  152.  
  153.     if (!ProInit(hPrev,hInst))
  154.         return FALSE;
  155.  
  156.     if (!ddeInit(hInst, hPrev))
  157.         return FALSE;
  158.  
  159.     fExit = 0;
  160.  
  161. /*
  162.  *  szSetupInf   is the directory or file name where SETUP.INF can be found
  163.  *
  164.  *  szSetupPath  is the directory to which application files will be copied        
  165.  *
  166.  *  szDiskPath   is the directory where the root of the setup disks are
  167.  *
  168.  */
  169.  
  170.     DosCwd(szDiskPath);
  171.     lstrcpy(szSetupInf,szDiskPath);
  172.  
  173.     return TRUE;
  174. }
  175.  
  176. /*----------------------------------------------------------------------------*\
  177. |   WinMain( hInst, hPrev, lpszCmdLine, cmdShow )                              |
  178. |                                                                              |
  179. |   Description:                                                               |
  180. |                                                                              |
  181. |   Arguments:                                                                 |
  182. |    hInst            instance handle of this instance of the application            |
  183. |    hPrev            instance handle of previous instance. NULL if this is the      |
  184. |                   instance of the application                                |
  185. |  szCmdLine    null-terminated command line                                   |
  186. |  cmdShow      specifies how the application's window is initially displayed  |
  187. |                                                                              |
  188. |   Returns:                                                                   |
  189. |       The exit code as specified in the WM_QUIT message.                     |
  190. |                                                                              |
  191. \*----------------------------------------------------------------------------*/
  192. int PASCAL WinMain(HANDLE hInst, HANDLE hPrev, LPSTR szCmdLine, WORD sw)
  193. {
  194.     char    szLocalTmp[MAXSTR];
  195.  
  196.     /* Call the initialization procedure */
  197.  
  198.     if (!AppInit(hInst,hPrev,sw,szCmdLine))
  199.         return FALSE;
  200.  
  201.     /* Loop until the user specifies a destination with sufficent disk space */
  202.  
  203.     while(TRUE) {
  204.        if (! fDialog(DLG_WINSETUP, hwndWS, wsInstallDlg) ) {
  205.           DestroyWindow(hwndWS);         // Kill the appllication, right now!
  206.           return TRUE;
  207.        }
  208.        if (! fnCheckDiskSpace() )
  209.           fnOkMsgBox(IDS_NEEDROOM);
  210.        else
  211.           break;
  212.     }
  213.  
  214.     ProOpen(hwndWS, NULL);
  215.  
  216.     /* Build groups only if all the copy tasks are successful. */
  217.  
  218.     if ( wsCopy(wsLoadSz(IDS_WINCOPY,szLocalTmp)) ) {
  219.        wsProgman(hwndWS);
  220.  
  221.        /* Inform user that the copy process is complete. */
  222.        MessageBox(NULL,wsLoadSz(IDS_FINISHED,NULL),szCaption,MB_OK);
  223.        return TRUE;
  224.     }
  225.     return FALSE;
  226. }
  227.  
  228. /* BOOL PRIVATE fnCheckDiskSpace(void);
  229.  *
  230.  * This function checks disk space on the specified destination drive
  231.  * against the minimum disk space requirement specified in the .INF file.
  232.  *
  233.  * Arguments: None.
  234.  *
  235.  * Returns:
  236.  *
  237.  *   Boolean value:
  238.  *   TRUE if the current destination provides sufficent disk space.
  239.  *   FALSE if the current destination does not provide sufficient disk space.
  240.  *
  241.  */
  242. BOOL PRIVATE fnCheckDiskSpace(void)
  243. {
  244.    char    szLocalTmp[MAXSTR];
  245.  
  246.    infLookup(wsLoadSz(IDS_DISKSPACE,NULL),szLocalTmp);
  247.  
  248.    if ( DosDiskFreeSpace(szSetupPath[0] - '@') >= atoi(szLocalTmp) )
  249.       return TRUE;
  250.    else
  251.       return FALSE;
  252.  
  253. }
  254.  
  255. /*----------------------------------------------------------------------------*\
  256. |   AppWndProc( hwnd, uiMessage, wParam, lParam )                              |
  257. |                                                                              |
  258. |   Description:                                                               |
  259. |       The window proc for the application's main window.  This processes all |
  260. |       of the parent window's messages.                                       |
  261. |                                                                              |
  262. |   Arguments:                                                                 |
  263. |       hwnd            window handle for the window                               |
  264. |       uiMessage       message number                                         |
  265. |       wParam          message-dependent                                      |
  266. |       lParam          message-dependent                                      |
  267. |                                                                              |
  268. |   Returns:                                                                   |
  269. |       0 if processed, nonzero if ignored                                     |
  270. |                                                                              |
  271. \*----------------------------------------------------------------------------*/
  272. LONG FAR PASCAL AppWndProc(hwnd, msg, wParam, lParam)
  273.     HWND     hwnd;
  274.     unsigned msg;
  275.     WORD     wParam;
  276.     long     lParam;
  277. {
  278.     PAINTSTRUCT ps;
  279.     BOOL        f;
  280.     HDC         hdc;
  281.  
  282.     switch (msg) {
  283.         case WM_COMMAND:
  284.             return AppCommand(hwnd,msg,wParam,lParam);
  285.  
  286.     case WM_DESTROY:
  287.         PostQuitMessage(0);
  288.         break;
  289.  
  290.     }
  291.     return DefWindowProc(hwnd,msg,wParam,lParam);
  292. }
  293.  
  294. /* AppCommand (hwnd, msg, wParam, lParam)
  295.  *
  296.  * This function handles commands passed to main application windows.
  297.  *
  298.  */
  299. LONG NEAR PASCAL AppCommand (hwnd, msg, wParam, lParam)
  300.     HWND     hwnd;
  301.     unsigned msg;
  302.     WORD     wParam;
  303.     long     lParam;
  304. {
  305.     char szTmpStr[256];
  306.  
  307.     switch(wParam)
  308.     {
  309.     case ID_EXITSETUP:
  310.             if ( fnErrorMsg(IDS_EXITMSG) ) {
  311.                ProClose();
  312.                DestroyWindow(hwndWS);
  313.             }
  314.             break;
  315.     }
  316.     return 0L;
  317. }
  318.  
  319. /* fnErrorMsg(int ID_Error_Message);
  320.  *
  321.  * This function displays a system-modal message box and
  322.  * lets user choose yes or no in response to the message box.
  323.  *
  324.  * Arguments:
  325.  *
  326.  *    ID_Error_Message       Resource ID of message to be displayed in the
  327.  *                           message box.
  328.  * Returns:
  329.  *
  330.  *    TRUE if the user chooses the Yes button.
  331.  *    FALSE if the user chooses the No button.
  332.  *
  333.  */
  334. BOOL PUBLIC fnErrorMsg(ID_Error_Message)
  335. int    ID_Error_Message;
  336. {
  337.    char   szTmpStr[256];
  338.  
  339.    wsLoadSz(ID_Error_Message,szTmpStr);
  340.  
  341.    if ( MessageBox(NULL,szTmpStr,wsLoadSz(IDS_EXITCAPTION,NULL),STD_EXIT_MSGBOX) == IDYES )
  342.       return TRUE;
  343.    else
  344.       return FALSE;
  345. }
  346.  
  347. /* fnOkMsgBox(int ID_Error_Message);
  348.  *
  349.  * This function displays a system-modal message box and
  350.  * lets user choose yes or no in response to the message box.
  351.  *
  352.  * Arguments:
  353.  *
  354.  *    ID_Error_Message       Resource ID of message to be displayed in the
  355.  *                           message box.
  356.  * Returns:
  357.  *
  358.  *    Nothing.
  359.  *
  360.  */
  361. VOID PUBLIC fnOkMsgBox(ID_Error_Message)
  362. int    ID_Error_Message;
  363. {
  364.    char   szTmpStr[256];
  365.  
  366.    wsLoadSz(ID_Error_Message,szTmpStr);
  367.  
  368.    MessageBox(NULL,szTmpStr,wsLoadSz(IDS_EXITCAPTION,NULL),STD_OK_MSGBOX);
  369. }
  370.  
  371. /*----------------------------------------------------------------------------*\
  372. |   fDialog(id,hwnd,fpfn)                                                      |
  373. |                                                                              |
  374. |   Description:                                                               |
  375. |    This function displays a dialog box and returns the exit code.              |
  376. |    The function passed will have a proc instance made for it.                  |
  377. |                                                                              |
  378. |    This also handles special keyboard input by calling CheckSpecialKeys().     |
  379. |                                                                              |
  380. |                                                                              |
  381. |   Arguments:                                                                 |
  382. |    id        resource id of dialog to display                                      |
  383. |    hwnd        parent window of dialog                                            |
  384. |    fpfn        dialog message function                                            |
  385. |                                                                              |
  386. |   Returns:                                                                   |
  387. |    exit code of dialog (what was passed to EndDialog)                          |
  388. |                                                                              |
  389. \*----------------------------------------------------------------------------*/
  390. int FAR fDialog(int id, HWND hwnd, FARPROC fpfn)
  391. {
  392.     int   result = 0;
  393.  
  394.     fpfn  = MakeProcInstance(fpfn,hInstWS);
  395.  
  396.     if (!fpfn)
  397.         goto ERR_EXIT;
  398.  
  399.     result = DialogBox(hInstWS, MAKEINTRESOURCE(id), hwnd, fpfn);
  400.     FreeProcInstance(fpfn);
  401.  
  402. ERR_EXIT:
  403.     return result;
  404. }
  405.  
  406. /*----------------------------------------------------------------------------*\
  407. |   wsDlgInit(hDlg)                                                            |
  408. |                                                                              |
  409. |   Handle the init message for a dialog box.                                  |
  410. |                                                                              |
  411. \*----------------------------------------------------------------------------*/
  412. void PUBLIC wsDlgInit(HWND hDlg)
  413. {
  414.     RECT rc;
  415.  
  416.     /*
  417.      *   Center the dialog.
  418.      */
  419.     GetWindowRect(hDlg,&rc);
  420.     SetWindowPos(hDlg,NULL,
  421.         (GetSystemMetrics(SM_CXSCREEN) - (rc.right - rc.left)) / 2,
  422.         (GetSystemMetrics(SM_CYSCREEN) - (rc.bottom - rc.top)) / 3,
  423.         0, 0, SWP_NOSIZE | SWP_NOACTIVATE);
  424.  
  425.     infDlgFixup(hDlg);
  426.  
  427.     // enable hwndWS to allow keyboard input
  428.  
  429.     if (hwndWS == GetParent(hDlg))
  430.         EnableWindow(hwndWS,TRUE);
  431. }
  432.  
  433. /*----------------------------------------------------------------------------*\
  434. |   infDlgFixup()                                                              |
  435. |                                                                              |
  436. |   If the dialog caption text or the text of any control has the form         |
  437. |                                                                              |
  438. |                         section.text                                           |
  439. |                                                                              |
  440. |   then this function changes the text to the text found in APPSETUP.INF.        |
  441. |                                                                              |
  442. \*----------------------------------------------------------------------------*/
  443. void PRIVATE infDlgFixup(HWND hwnd)
  444. {
  445.  
  446.     if (GetWindowText(hwnd,bufTmp,sizeof(bufTmp)))
  447.     {
  448.         if (infLookup(bufTmp,bufTmp))
  449.             SetWindowText(hwnd,bufTmp);
  450.     }
  451.  
  452.     hwnd = GetWindow(hwnd,GW_CHILD);
  453.     while (hwnd)
  454.     {
  455.     infDlgFixup(hwnd);
  456.     hwnd = GetWindow(hwnd,GW_HWNDNEXT);
  457.     }
  458. }
  459.  
  460. /*----------------------------------------------------------------------------*\
  461. |   wsStartWait()                                                              |
  462. |                                                                              |
  463. |   Displays an hourglass cursor.                                              |
  464. |                                                                              |
  465. \*----------------------------------------------------------------------------*/
  466. void PUBLIC wsStartWait()
  467. {
  468.         SetCursor(LoadCursor(NULL,MAKEINTATOM(IDC_WAIT)));
  469. }
  470.  
  471. /*----------------------------------------------------------------------------*\
  472. |   wsEndWait()                                                                |
  473. |                                                                              |
  474. |   Restores the cursor to its original shape.                                 |
  475. |                                                                              |
  476. \*----------------------------------------------------------------------------*/
  477. void PUBLIC wsEndWait()
  478. {
  479.  
  480.         SetCursor(LoadCursor(NULL,MAKEINTATOM(IDC_ARROW)));
  481. }
  482.  
  483. /*---------------------------------------------------------------------------*/
  484. /*                                                                           */
  485. /*  PRIV text control that uses ExtTextOut(), thus avoiding flicker.         */
  486. /*                                                                           */
  487. /*---------------------------------------------------------------------------*/
  488.  
  489. LONG FAR PASCAL fnText( hwnd, msg, wParam, lParam )
  490.     HWND hwnd;
  491.     unsigned msg;
  492.     WORD wParam;
  493.     LONG lParam;
  494. {
  495.     PAINTSTRUCT ps;
  496.     RECT rc;
  497.     char        ach[128];
  498.     int  len;
  499.  
  500.     switch (msg)
  501.     {
  502.     case WM_SETTEXT:
  503.         DefWindowProc(hwnd, msg, wParam, lParam);
  504.         InvalidateRect(hwnd,NULL,FALSE);
  505.         UpdateWindow(hwnd);
  506.         return 0L;
  507.  
  508.     case WM_ERASEBKGND:
  509.         return 0L;
  510.  
  511.     case WM_PAINT:
  512.         BeginPaint(hwnd, &ps);
  513.         GetClientRect(hwnd,&rc);
  514.  
  515.         len = GetWindowText(hwnd,ach,sizeof(ach));
  516.         SetBkColor(ps.hdc,GetSysColor(COLOR_WINDOW));
  517.         SetTextColor(ps.hdc,GetSysColor(COLOR_WINDOWTEXT));
  518.         ExtTextOut(ps.hdc,0,0,ETO_OPAQUE,&rc,ach,len,NULL);
  519.  
  520.         EndPaint(hwnd, &ps);
  521.         return 0L;
  522.     }
  523.     return DefWindowProc(hwnd, msg, wParam, lParam);
  524. }
  525.  
  526. /*----------------------------------------------------------------------------*\
  527. |   wsLoadSz()                                                                 |
  528. |                                                                              |
  529. |   Description:                                                               |
  530. |       Loads a string from our resource file                                  |
  531. |                                                                              |
  532. |       ids     ID of string to load                                           |
  533. |       pch     buffer in which to place the string. If pch is NULL, the       |
  534. |               string will be placed in a global buffer.                      |
  535. |                                                                              |
  536. |   Returns:                                                                   |
  537. |       near pointer to the loaded string                                      |
  538. |                                                                              |
  539. \*----------------------------------------------------------------------------*/
  540. PSTR PUBLIC wsLoadSz(int ids, PSTR pch)
  541. {
  542.     if (pch == NULL)
  543.     pch = bufTmp;
  544.  
  545.     LoadString(hInstWS,ids,pch,MAXSTR);
  546.  
  547.     return pch;
  548. }
  549.  
  550. /*----------------------------------------------------------------------------*\
  551. |   wsInstallDlg( hDlg, uiMessage, wParam, lParam )                            |
  552. |                                                                              |
  553. |   Returns:                                                                   |
  554. |       TRUE if message has been processed, else FALSE                         |
  555. |                                                                              |
  556. \*----------------------------------------------------------------------------*/
  557. BOOL EXPORT wsInstallDlg( hDlg, uiMessage, wParam, lParam )
  558.     HWND     hDlg;
  559.     unsigned uiMessage;
  560.     WORD     wParam;
  561.     long     lParam;
  562. {
  563.     WORD    fOptions;
  564.     HWND    hEditFld;
  565.     char    szTmpBuf[MAXSTR];
  566.  
  567.     switch (uiMessage)
  568.     {
  569.     case WM_SYSCOMMAND:        // suppress taskman
  570.         if (wParam == SC_TASKLIST)
  571.             return TRUE;
  572.         break;
  573.  
  574.     case WM_COMMAND:
  575.         switch (wParam)
  576.         {
  577.                 case ID_OK:
  578.                     GetDlgItemText(hDlg,ID_EDIT1,szSetupPath,MAXPATHLEN);
  579.                     EndDialog(hDlg, TRUE);
  580.             break;
  581.  
  582.                 case ID_CANCEL:
  583.             // make this the same as pressing F3
  584.                     if ( fnErrorMsg(IDS_EXITMSG) )
  585.                    EndDialog(hDlg, FALSE);
  586.                     break;
  587.         }
  588.         return TRUE;
  589.  
  590.         /*  On init we need to:
  591.          *     - Put default text in edit field.
  592.          *     - Set focus to edit field.
  593.          *     - Place cursor at end of edit field text.
  594.          */
  595.  
  596.     case WM_INITDIALOG:
  597.             wsDlgInit(hDlg);
  598.             hEditFld = GetDlgItem(hDlg,ID_EDIT1);
  599.             infLookup(wsLoadSz(IDS_DEFAULT_DIR,NULL),szTmpBuf);
  600.             SetDlgItemText(hDlg,ID_EDIT1,szTmpBuf);
  601.             SetFocus(hEditFld);
  602.             SendMessage(hEditFld,EM_SETSEL,0,MAKELONG(lstrlen(szTmpBuf),lstrlen(szTmpBuf)));
  603.         return FALSE;
  604.     }
  605.     return FALSE;
  606. }
  607.  
  608. /*----------------------------------------------------------------------------*\
  609. |   wsErrorDlg( hDlg, uiMessage, wParam, lParam )                   |
  610. |                                                                              |
  611. |   Arguments:                                                                 |
  612. |       hDlg            window handle of About dialog's window                   |
  613. |       uiMessage       message number                                         |
  614. |       wParam          message-dependent                                      |
  615. |       lParam          message-dependent                                      |
  616. |                                                                              |
  617. |   Returns:                                                                   |
  618. |       TRUE if message has been processed, else FALSE                         |
  619. |                                                                              |
  620. \*----------------------------------------------------------------------------*/
  621. BOOL FAR PASCAL wsErrorDlg(HWND hDlg, unsigned uiMessage, WORD wParam, long lParam)
  622. {
  623.     switch (uiMessage)
  624.     {
  625.     case WM_COMMAND:
  626.         switch (wParam)
  627.         {
  628.         case ID_RETRY:
  629.                     EndDialog(hDlg,FC_RETRY);
  630.             break;
  631.  
  632.         case ID_ABORT:
  633.             EndDialog(hDlg,FC_ABORT);
  634.             break;
  635.  
  636.         case ID_IGNORE:
  637.             EndDialog(hDlg,FC_IGNORE);
  638.             break;
  639.         }
  640.         return TRUE;
  641.  
  642.         case WM_INITDIALOG:
  643.         SetDlgItemText(hDlg, ID_STATUS1, pErrMsg);
  644.         wsDlgInit(hDlg);
  645.             return TRUE;
  646.     }
  647.     return FALSE;
  648. }
  649.  
  650. #ifdef DEBUG
  651. /* FAR _Assert(char*,int);
  652.  *
  653.  * Called as a result of an assertion failure. Will print out an error
  654.  * dialog containing the file and line number at which the assertion failure
  655.  * occured.
  656.  *
  657.  * ENTRY: Only from an assertion failure.
  658.  * EXIT : Fatal Error (exit to MS-DOS).
  659.  *
  660.  */
  661. int FAR _Assert(PSTR szFile, int iLine)
  662. {
  663.     int     id;
  664.     char    buf[128];
  665.  
  666.     fsprintf(buf,"%s : %d",szFile,iLine);
  667.     id = MessageBox(NULL,buf,"WinAssert",MB_ABORTRETRYIGNORE|MB_ICONEXCLAMATION|MB_DEFBUTTON3|MB_SYSTEMMODAL);
  668.     switch (id)
  669.     {
  670.         case IDABORT:
  671.             DosExit(-1);  /* Terminate application immediately. */
  672.         case IDIGNORE:
  673.             break;
  674.     }
  675.     return 0;
  676. }
  677. #endif
  678.