home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / COMDLG32.PAK / COMDLG32.C next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  18.7 KB  |  587 lines

  1. //THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF 
  2. //ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO 
  3. //THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 
  4. // PARTICULAR PURPOSE.
  5. //
  6. // Copyright  1994-1995  Microsoft Corporation.  All Rights Reserved.
  7. //
  8. //    PROGRAM:    Comdlg32.c
  9. //
  10. //    PURPOSE:    Demonstrates how to manipulate the file open common dialog.
  11. //
  12. //    PLATFORMS:    Windows 95
  13. //
  14. //    FUNCTIONS:    
  15. //        WinMain() - calls initialization function, processes message loop
  16. //        InitApplication() - Initializes window data nd registers window
  17. //        InitInstance() -saves instance handle and creates main window
  18. //        MainWindProc() Processes messages
  19. //        About() - Process menssages for "About" dialog box
  20. //          OpenTheFile() - Processes the File Open common dialog box
  21. //          ComDlg32DlgProc() - Hook procedure for GetOpenFileName() common dialog
  22. //        TestNotify() - Processes the WM_NOTIFY function for ComDlg32DlgProc
  23. //        ProcessCDError() - uses CommonDialogExtendedError() to output useful error 
  24. //              messages
  25. //
  26. //    SPECIAL INSTRUCTIONS: N/A
  27. //
  28.  
  29. #include <windows.h>    // includes basic windows functionality
  30. #include <commdlg.h>    // includes common dialog functionality
  31. #include <dlgs.h>       // includes common dialog template defines
  32. #include <cderr.h>      // includes the common dialog error codes
  33. #include "COMDLG32.h"   // includes application-specific information
  34.  
  35. const char szmsgSHAREVIOLATION[] = SHAREVISTRING;  // string for sharing violation
  36. const char szmsgFILEOK[]         = FILEOKSTRING;   // string for OK button
  37. const char szCommdlgHelp[]       = HELPMSGSTRING;  // string for Help button
  38.  
  39. UINT cdmsgShareViolation = 0;  // identifier from RegisterWindowMessage
  40. UINT cdmsgFileOK         = 0;  // identifier from RegisterWindowMessage
  41. UINT cdmsgHelp           = 0;  // identifier from RegisterWindowMessage
  42.  
  43. typedef struct _MYDATA
  44. {
  45.     char szTest1[80];        // a test buffer containing the file selected
  46.     char szTest2[80];       // a test buffer containing the file path
  47. } MYDATA, FAR * LPMYDATA;
  48.  
  49. HINSTANCE g_hInst;        // the current instance        
  50. MYDATA sMyData;            // an instance of a MYDATA
  51.  
  52. //
  53. //  FUNCTION: WinMain(HANDLE, HANDLE, LPSTR, int)
  54. //
  55. //  PURPOSE: Entry point for the application.
  56. //
  57. //  COMMENTS:
  58. //
  59. //    This function initializes the application and processes the
  60. //    message loop.
  61. //
  62. #pragma argsused
  63. int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
  64.     LPSTR lpCmdLine, int nCmdShow )
  65. {
  66.  
  67.     MSG msg;                         
  68.      OSVERSIONINFO osVer; // for GetVersionEx()
  69.  
  70.      // Verify presence of Windows 95
  71.      osVer.dwOSVersionInfoSize = sizeof(osVer);
  72.      if (!GetVersionEx(&osVer))
  73.           return (FALSE);
  74.  
  75.      if (osVer.dwPlatformId != VER_PLATFORM_WIN32_WINDOWS)
  76.      {
  77.      MessageBox(NULL, "This example requires Windows 95.",
  78.                     "Common Dialog Example", MB_OK );
  79.      return (FALSE);
  80.      }
  81.  
  82.      if (!InitApplication(hInstance))
  83.                 return (FALSE);
  84.  
  85.      // Create the main window.
  86.      if (!InitInstance(hInstance, nCmdShow))
  87.           return (FALSE);
  88.  
  89.     // Acquire and dispatch messages until a WM_QUIT message is received.
  90.      while (GetMessage(&msg,NULL,0,0))
  91.         {
  92.             TranslateMessage(&msg);    // Translates virtual key codes.
  93.             DispatchMessage(&msg);     // Dispatches message to window.
  94.         }
  95.     return (msg.wParam);           // Returns the value from PostQuitMessage.
  96.  
  97. }
  98.  
  99. //
  100. //  FUNCTION: InitApplication(HANDLE)
  101. //
  102. //  PURPOSE: Initializes window data and registers window class 
  103. //
  104. //  COMMENTS:
  105. //
  106. //       In this function, we initialize a window class by filling out a data
  107. //       structure of type WNDCLASS and calling the Windows RegisterClass()
  108. //       function.
  109. //
  110. BOOL InitApplication(HANDLE hInstance)       
  111. {
  112.     WNDCLASS  wc;
  113.  
  114.     // Register the window class for my window.                                                           */
  115.     wc.style = 0;                       // Class style.
  116.     wc.lpfnWndProc = (WNDPROC)MainWndProc; // Window procedure for this class.
  117.     wc.cbClsExtra = 0;                  // No per-class extra data.
  118.     wc.cbWndExtra = 0;                  // No per-window extra data.
  119.     wc.hInstance = hInstance;           // Application that owns the class.
  120.     wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  121.     wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  122.     wc.hbrBackground = GetStockObject(WHITE_BRUSH); 
  123.     wc.lpszMenuName =  "Comdlg32Menu";   // Name of menu resource in .RC file. 
  124.     wc.lpszClassName = "Comdlg32WClass"; // Name used in call to CreateWindow.
  125.  
  126.     return (RegisterClass(&wc));
  127. }
  128.  
  129. //
  130. //   FUNCTION: InitInstance(HANDLE, int)
  131. //
  132. //   PURPOSE: Saves instance handle and creates main window 
  133. //
  134. //   COMMENTS:
  135. //
  136. //        In this function, we save the instance handle in a global variable and
  137. //        create and display the main program window.
  138. //
  139. BOOL InitInstance( HANDLE hInstance, int nCmdShow)           
  140. {
  141.     HWND            hWnd;              
  142.  
  143.     // Save off the handle to the current instance.
  144.     g_hInst = hInstance;
  145.  
  146.     // Create a main window for this application instance. 
  147.     hWnd = CreateWindow(
  148.         "Comdlg32WClass",
  149.         "Common Dialog Sample Application",
  150.         WS_OVERLAPPEDWINDOW,            // Window style.
  151.         CW_USEDEFAULT,                  // Default horizontal position.
  152.         CW_USEDEFAULT,                  // Default vertical position.
  153.         CW_USEDEFAULT,                  // Default width.
  154.         CW_USEDEFAULT,                  // Default height.
  155.         NULL,                           // Overlapped windows have no parent.
  156.         NULL,                           // Use the window class menu.
  157.         g_hInst,                        // This instance owns this window.
  158.         NULL                            // Pointer not needed.
  159.     );
  160.  
  161.     // If window could not be created, return "failure".
  162.     if (!hWnd)
  163.         return (FALSE);
  164.  
  165.     // Register the window messages to receive.
  166.     cdmsgShareViolation = RegisterWindowMessage(szmsgSHAREVIOLATION);
  167.     cdmsgFileOK         = RegisterWindowMessage(szmsgFILEOK);
  168.     cdmsgHelp           = RegisterWindowMessage(szCommdlgHelp);
  169.  
  170.     // Make the window visible; update its client area; and return "success".
  171.     ShowWindow(hWnd, nCmdShow);  
  172.     UpdateWindow(hWnd);          
  173.     return (TRUE);               
  174.  
  175. }
  176.  
  177. //
  178. //  FUNCTION: MainWndProc(HWND, unsigned, WORD, LONG)
  179. //
  180. //  PURPOSE:  Processes messages for the main window.
  181. //
  182. //  MESSAGES:
  183. //
  184. //    WM_CREATE - initialize window and create the MLE
  185. //    WM_COMMAND - process the application menu
  186. //    WM_SIZE - size the MLE in the main window
  187. //    WM_DESTROY - post a quit message and return
  188. //
  189. //
  190. LONG APIENTRY MainWndProc( HWND hWnd, UINT message, UINT wParam, LONG lParam)
  191. {
  192.     static HWND hwndEdit;
  193.     CHAR lpszHello[] = "Choose File Open from the Options menu for a demo.";
  194.  
  195.     switch (message) {
  196.  
  197.         case WM_CREATE:
  198.             // Create an MLE for the file contents.
  199.             hwndEdit = CreateWindow(
  200.                 "EDIT",     
  201.                 NULL,       
  202.                 WS_CHILD | WS_VISIBLE | WS_VSCROLL |
  203.                     ES_LEFT | ES_MULTILINE | ES_AUTOVSCROLL,
  204.                 0, 0, 0, 0, 
  205.                 hWnd,       
  206.                 (HMENU) ID_EDITCHILD, 
  207.                 (HINSTANCE) GetWindowLong(hWnd, GWL_HINSTANCE),
  208.                 NULL);               
  209.  
  210.             // Update the MLE. 
  211.             SendMessage(hwndEdit, WM_SETTEXT, 0, (LPARAM) lpszHello);
  212.             return 0;
  213.  
  214.         case WM_SIZE:
  215.             // Make the edit control the size of the window's client area. 
  216.             MoveWindow(hwndEdit, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);          
  217.             return 0;
  218.  
  219.         case WM_COMMAND:           // message: command from application menu 
  220.             switch( LOWORD( wParam ))
  221.             {
  222.                 case IDM_FILEOPEN:
  223.                     // Call the FileOpen common dialog to open the file.
  224.                     OpenTheFile( hWnd, hwndEdit );
  225.                     break;
  226.  
  227.                 case IDM_EXIT:
  228.                     PostQuitMessage(0);
  229.                     break;
  230.  
  231.                 case IDM_ABOUT:
  232.                     DialogBox(g_hInst,
  233.                         MAKEINTRESOURCE(IDD_ABOUT),
  234.                         hWnd,           
  235.                         (DLGPROC)About);
  236.                     break;
  237.  
  238.                 default:
  239.                     return (DefWindowProc(hWnd, message, wParam, lParam));
  240.  
  241.             }
  242.             break;
  243.  
  244.         case WM_DESTROY:                  // message: window being destroyed
  245.             PostQuitMessage(0);
  246.             break;
  247.  
  248.  
  249.         default:
  250.             return (DefWindowProc(hWnd, message, wParam, lParam));
  251.     }
  252.     return (0);
  253. }
  254.  
  255.  
  256. //
  257. //   FUNCTION: OpenTheFile(HWND hwnd, HWND hwndEdit)
  258. //
  259. //   PURPOSE: Invokes common dialog function to open a file and opens it.
  260. //
  261. //   COMMENTS:
  262. //
  263. //    This function initializes the OPENFILENAME structure and calls
  264. //            the GetOpenFileName() common dialog function.  
  265. //    
  266. //    RETURN VALUES:
  267. //        TRUE - The file was opened successfully and read into the buffer.
  268. //        FALSE - No files were opened.
  269. //
  270. //
  271. BOOL OpenTheFile( HWND hWnd, HWND hWndEdit )
  272. {
  273.     HANDLE hFile;
  274.     DWORD dwBytesRead;
  275.     DWORD dwFileSize;
  276.     OPENFILENAME OpenFileName;
  277.     TCHAR         szFile[MAX_PATH]      = "\0";
  278.     char *lpBufPtr;
  279.  
  280.     strcpy( szFile, "");
  281.  
  282.  
  283.     // Fill in the OPENFILENAME structure to support a template and hook.
  284.     OpenFileName.lStructSize       = sizeof(OPENFILENAME);
  285.     OpenFileName.hwndOwner         = hWnd;
  286.     OpenFileName.hInstance         = g_hInst;
  287.     OpenFileName.lpstrFilter       = NULL;
  288.     OpenFileName.lpstrCustomFilter = NULL;
  289.     OpenFileName.nMaxCustFilter    = 0;
  290.     OpenFileName.nFilterIndex      = 0;
  291.     OpenFileName.lpstrFile         = szFile;
  292.     OpenFileName.nMaxFile          = sizeof(szFile);
  293.     OpenFileName.lpstrFileTitle    = NULL;
  294.     OpenFileName.nMaxFileTitle     = 0;
  295.     OpenFileName.lpstrInitialDir   = NULL;
  296.     OpenFileName.lpstrTitle        = "Open a File";
  297.     OpenFileName.nFileOffset       = 0;
  298.     OpenFileName.nFileExtension    = 0;
  299.     OpenFileName.lpstrDefExt       = NULL;
  300.      OpenFileName.lCustData         = (LPARAM)&sMyData;
  301.     OpenFileName.lpfnHook            = (LPOFNHOOKPROC) ComDlg32DlgProc;
  302.     OpenFileName.lpTemplateName    = MAKEINTRESOURCE(IDD_COMDLG32);
  303.     OpenFileName.Flags             = OFN_SHOWHELP | OFN_EXPLORER | OFN_ENABLEHOOK | OFN_ENABLETEMPLATE;
  304.  
  305.     // Call the common dialog function.
  306.     if (GetOpenFileName(&OpenFileName))
  307.     {
  308.         // Open the file.
  309.         if ((hFile = CreateFile((LPCTSTR)OpenFileName.lpstrFile,
  310.             GENERIC_READ,
  311.             FILE_SHARE_READ,
  312.             NULL,
  313.             OPEN_EXISTING,
  314.             FILE_ATTRIBUTE_NORMAL,
  315.             (HANDLE)NULL)) == (HANDLE)-1)
  316.         {
  317.             MessageBox( hWnd, "File open failed.", NULL, MB_OK );
  318.             return FALSE;
  319.         }
  320.  
  321.         // Get the size of the file.
  322.         dwFileSize = GetFileSize(hFile, NULL);
  323.         if (dwFileSize == 0xFFFFFFFF)
  324.         {
  325.             MessageBox( NULL, "GetFileSize failed!", NULL, MB_OK);
  326.             return FALSE;
  327.         }
  328.  
  329.         // Allocate a buffer for the file to be read into.
  330.         lpBufPtr = (char *)GlobalAlloc( GMEM_FIXED, dwFileSize );
  331.         if (lpBufPtr == NULL)
  332.         {
  333.             MessageBox( NULL, "GlobalAlloc failed!", NULL, MB_OK);
  334.             CloseHandle( hFile );
  335.             return FALSE;
  336.         }
  337.  
  338.         // Read it's contents into a buffer.
  339.         ReadFile(hFile,(LPVOID)lpBufPtr, dwFileSize, &dwBytesRead, NULL);
  340.  
  341.         if (dwBytesRead == 0)
  342.         {
  343.             MessageBox( hWnd, "Zero bytes read.", NULL, MB_OK );
  344.             GlobalFree(lpBufPtr);
  345.                 return FALSE;
  346.         }
  347.  
  348.         // Update the MLE with the file contents.
  349.         SendMessage(hWndEdit, WM_SETTEXT, 0, (LPARAM) lpBufPtr);
  350.  
  351.         // Close the file.
  352.         CloseHandle(hFile);
  353.         GlobalFree(lpBufPtr);
  354.  
  355.         return TRUE;
  356.     }
  357.     else
  358.        {
  359.         ProcessCDError(CommDlgExtendedError(), hWnd );
  360.         return FALSE;
  361.     }
  362.     
  363. }
  364.  
  365. //
  366. //   FUNCTION: TestNotify( HWND hDlg, LPOFNOTIFY pofn)
  367. //
  368. //  PURPOSE:  Processes the WM_NOTIFY message notifications that is sent
  369. //    to the hook dialog procedure for the File Open common dialog.
  370. //
  371. //
  372. BOOL NEAR PASCAL TestNotify(HWND hDlg, LPOFNOTIFY pofn)
  373. {
  374.     switch (pofn->hdr.code)
  375.     {
  376.         // The selection has changed. 
  377.         case CDN_SELCHANGE:
  378.         {
  379.             char szFile[MAX_PATH];
  380.  
  381.             // Get the file specification from the common dialog.
  382.             if (CommDlg_OpenSave_GetSpec(GetParent(hDlg),
  383.                 szFile, sizeof(szFile)) <= sizeof(szFile))
  384.             {
  385.                 // Set the dialog item to reflect this.
  386.                 SetDlgItemText(hDlg, IDE_SELECTED, szFile);
  387.             }
  388.  
  389.             // Get the path of the selected file.
  390.             if (CommDlg_OpenSave_GetFilePath(GetParent(hDlg),
  391.                 szFile, sizeof(szFile)) <= sizeof(szFile))
  392.             {
  393.                 // Display this path in the appropriate box.
  394.                 SetDlgItemText(hDlg, IDE_PATH, szFile);
  395.             }
  396.         }
  397.         break;
  398.  
  399.         // A new folder has been opened.
  400.         case CDN_FOLDERCHANGE:
  401.         {
  402.             char szFile[MAX_PATH];
  403.  
  404.             if (CommDlg_OpenSave_GetFolderPath(GetParent(hDlg),
  405.                 szFile, sizeof(szFile)) <= sizeof(szFile))
  406.             {
  407.                 // Display this new path in the appropriate box.
  408.                 SetDlgItemText(hDlg, IDE_SELECTED, szFile);
  409.             }
  410.         }
  411.         break;
  412.  
  413.         // The "Help" pushbutton has been pressed.
  414.         case CDN_HELP:
  415.             MessageBox(hDlg, "Got the Help button notify.", "ComDlg32 Test", MB_OK);
  416.             break;
  417.  
  418.         // The 'OK' pushbutton has been pressed.
  419.         case CDN_FILEOK:
  420.             // Update the appropriate box.
  421.             SetDlgItemText(hDlg,IDE_SELECTED, pofn->lpOFN->lpstrFile);
  422.             SetWindowLong(hDlg, DWL_MSGRESULT, 1L);
  423.             break;
  424.  
  425.         // Received a sharing violation.
  426.         case CDN_SHAREVIOLATION:
  427.             // Update the appropriate box.
  428.             SetDlgItemText(hDlg, IDE_SELECTED, pofn->pszFile);
  429.             MessageBox(hDlg, "Got a sharing violation notify.", "ComDlg32 Test", MB_OK);
  430.             break;
  431.     }
  432.  
  433.     return(TRUE);
  434. }
  435.  
  436. //
  437. //   FUNCTION: ComDlg32DlgProc( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  438. //
  439. //  PURPOSE:  Processes messages for the File Open common dialog box.
  440. //
  441. //    MESSAGES:
  442. //
  443. //    WM_INITDIALOG - save pointer to the OPENFILENAME structure in User data
  444. //    WM_DESTROY - get the text entered and fill in the MyData structure
  445. //    WM_NOTIFY - pass this message onto the TestNotify function
  446. //    default - check for a sharing violation or the OK button and
  447. //        display a message box.
  448. //
  449. //
  450. #pragma argsused
  451. BOOL CALLBACK ComDlg32DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  452. {
  453.  
  454.     switch (uMsg)
  455.     {
  456.         case WM_INITDIALOG:
  457.             // Save off the long pointer to the OPENFILENAME structure.
  458.             SetWindowLong(hDlg, DWL_USER, lParam);
  459.             break;
  460.  
  461.         case WM_DESTROY:
  462.             {
  463.             LPOPENFILENAME lpOFN = (LPOPENFILENAME)GetWindowLong(hDlg, DWL_USER);
  464.             LPMYDATA psMyData = (LPMYDATA)lpOFN->lCustData;
  465.  
  466.             GetDlgItemText(hDlg, IDE_PATH, psMyData->szTest1, sizeof(psMyData->szTest1));
  467.             GetDlgItemText(hDlg, IDE_SELECTED, psMyData->szTest2, sizeof(psMyData->szTest2));
  468.             }
  469.             break;
  470.  
  471.         case WM_NOTIFY:
  472.             TestNotify(hDlg, (LPOFNOTIFY)lParam);
  473.  
  474.         default:
  475.             if (uMsg == cdmsgFileOK)
  476.             {
  477.                 SetDlgItemText(hDlg, IDE_SELECTED, ((LPOPENFILENAME)lParam)->lpstrFile);
  478.                 if (MessageBox(hDlg, "Got the OK button message.\n\nShould I open it?", "ComDlg32 Test", MB_YESNO)
  479.                     == IDNO)
  480.                 {
  481.                     SetWindowLong(hDlg, DWL_MSGRESULT, 1L);
  482.                 }
  483.                 break;
  484.             }
  485.             else if (uMsg == cdmsgShareViolation)
  486.             {
  487.                 SetDlgItemText(hDlg, IDE_SELECTED, (LPSTR)lParam);
  488.                 MessageBox(hDlg, "Got a sharing violation message.", "ComDlg32 Test", MB_OK);
  489.                 break;
  490.             }
  491.             return FALSE;
  492.     }
  493.     return TRUE;
  494. }
  495.  
  496. //
  497. //  FUNCTION: About(HWND, unsigned, WORD, LONG)
  498. //
  499. //  PURPOSE:  Processes messages for "About" dialog box
  500. //
  501. //  MESSAGES:
  502. //
  503. //    WM_INITDIALOG - initialize dialog box
  504. //    WM_COMMAND    - Input received
  505. //
  506. //
  507. #pragma argsused
  508. BOOL APIENTRY About( HWND hDlg, UINT message, UINT wParam, LONG lParam)
  509. {
  510.     switch (message)
  511.     {
  512.         case WM_INITDIALOG:                
  513.             return (TRUE);
  514.  
  515.         case WM_COMMAND:                      
  516.             if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) 
  517.             {        
  518.                 EndDialog(hDlg, TRUE);        
  519.                 return TRUE;
  520.             }
  521.             break;
  522.     }
  523.     return FALSE;                           
  524.  
  525. }
  526.  
  527. //
  528. //  FUNCTION: ProcessCDError(DWORD) 
  529. //
  530. //  PURPOSE: Processes errors from the common dialog functions.
  531. //
  532. //  COMMENTS:
  533. //
  534. //        This function is called whenever a common dialog function
  535. //        fails.  The CommonDialogExtendedError() value is passed to
  536. //        the function which maps the error value to a string table.
  537. //        The string is loaded and displayed for the user. 
  538. //
  539. //
  540. void ProcessCDError(DWORD dwErrorCode, HWND hWnd)
  541. {
  542.    WORD  wStringID;
  543.    TCHAR  buf[MAX_PATH];
  544.  
  545.    switch(dwErrorCode)
  546.       {
  547.      case CDERR_DIALOGFAILURE:   wStringID=IDS_DIALOGFAILURE;   break;
  548.      case CDERR_STRUCTSIZE:      wStringID=IDS_STRUCTSIZE;      break;
  549.      case CDERR_INITIALIZATION:  wStringID=IDS_INITIALIZATION;  break;
  550.      case CDERR_NOTEMPLATE:      wStringID=IDS_NOTEMPLATE;      break;
  551.      case CDERR_NOHINSTANCE:     wStringID=IDS_NOHINSTANCE;     break;
  552.      case CDERR_LOADSTRFAILURE:  wStringID=IDS_LOADSTRFAILURE;  break;
  553.      case CDERR_FINDRESFAILURE:  wStringID=IDS_FINDRESFAILURE;  break;
  554.      case CDERR_LOADRESFAILURE:  wStringID=IDS_LOADRESFAILURE;  break;
  555.      case CDERR_LOCKRESFAILURE:  wStringID=IDS_LOCKRESFAILURE;  break;
  556.      case CDERR_MEMALLOCFAILURE: wStringID=IDS_MEMALLOCFAILURE; break;
  557.      case CDERR_MEMLOCKFAILURE:  wStringID=IDS_MEMLOCKFAILURE;  break;
  558.      case CDERR_NOHOOK:          wStringID=IDS_NOHOOK;          break;
  559.      case PDERR_SETUPFAILURE:    wStringID=IDS_SETUPFAILURE;    break;
  560.      case PDERR_PARSEFAILURE:    wStringID=IDS_PARSEFAILURE;    break;
  561.      case PDERR_RETDEFFAILURE:   wStringID=IDS_RETDEFFAILURE;   break;
  562.      case PDERR_LOADDRVFAILURE:  wStringID=IDS_LOADDRVFAILURE;  break;
  563.      case PDERR_GETDEVMODEFAIL:  wStringID=IDS_GETDEVMODEFAIL;  break;
  564.      case PDERR_INITFAILURE:     wStringID=IDS_INITFAILURE;     break;
  565.      case PDERR_NODEVICES:       wStringID=IDS_NODEVICES;       break;
  566.      case PDERR_NODEFAULTPRN:    wStringID=IDS_NODEFAULTPRN;    break;
  567.      case PDERR_DNDMMISMATCH:    wStringID=IDS_DNDMMISMATCH;    break;
  568.      case PDERR_CREATEICFAILURE: wStringID=IDS_CREATEICFAILURE; break;
  569.      case PDERR_PRINTERNOTFOUND: wStringID=IDS_PRINTERNOTFOUND; break;
  570.      case CFERR_NOFONTS:         wStringID=IDS_NOFONTS;         break;
  571.      case FNERR_SUBCLASSFAILURE: wStringID=IDS_SUBCLASSFAILURE; break;
  572.      case FNERR_INVALIDFILENAME: wStringID=IDS_INVALIDFILENAME; break;
  573.      case FNERR_BUFFERTOOSMALL:  wStringID=IDS_BUFFERTOOSMALL;  break;
  574.  
  575.      case 0:   //User may have hit CANCEL or we got a *very* random error
  576.         return;
  577.  
  578.      default:
  579.         wStringID=IDS_UNKNOWNERROR;
  580.       }
  581.  
  582.    LoadString(NULL, wStringID, buf, sizeof(buf));
  583.    MessageBox(hWnd, buf, NULL, MB_OK);
  584.    return;
  585. }
  586.  
  587.