home *** CD-ROM | disk | FTP | other *** search
/ Windoware / WINDOWARE_1_6.iso / source / wbitmap / bitmaps.c < prev    next >
C/C++ Source or Header  |  1991-11-12  |  17KB  |  751 lines

  1. /*
  2. **    $id: ssvcid bitmaps.c 1.1 11/12/91  8:38 am$
  3. **        Main program for Bitmap and Icon File demo program.
  4. **
  5. **    (C) 1991 Larry Widing
  6. */
  7.  
  8. #include    <windows.h>
  9. #include    "bitmaps.h"
  10. #include    "bmfile.h"
  11. #include    "bmmanip.h"
  12. #include    "bminfo.h"
  13. #include    "icnfile.h"
  14.  
  15. /*
  16. **    Global Variables
  17. */
  18. HWND        MainWindow;            /* Handle to the application's main window */
  19. HANDLE    AppInstance;        /* Handle to application's instance */
  20. char        FileName[128];        /* Name of file returned by open file dialog */
  21. HBITMAP    BitmapHandle;        /* Handle of currently loaded bitmap */
  22. HICON        IconHandle;            /* Handle of currently loaded icon */
  23. HANDLE    DIBitmapHandle;    /* Handle of packed DI Bitmap */
  24. int        FileSaveMode = 0;    /* 0 to save as a normal DIB, 1 for RLE, 2 for OS2 */
  25.  
  26. const char    AppName[] = "Bitmaps";
  27.  
  28. /*
  29. **    Local function prototypes
  30. */
  31. BOOL                    RegisterWindows(HANDLE, HANDLE);
  32. BOOL                    InitializeApplication(HANDLE, HANDLE *, int);
  33. #if    defined(__TSC__)
  34.     #pragma    save
  35.     #pragma    call(windows=>on)
  36. #endif
  37. LONG FAR PASCAL    MainWndProc(HWND, WORD, WORD, DWORD);
  38. BOOL FAR PASCAL    OpenFileDialog(HWND, WORD, WORD, DWORD);
  39. BOOL FAR PASCAL    AboutBoxDialog(HWND, WORD, WORD, DWORD);
  40. #if    defined(__TSC__)
  41.     #pragma    restore
  42. #endif
  43.  
  44. /*
  45. ** int PASCAL
  46. ** WinMain(
  47. **   HANDLE hInstance,
  48. **   HANDLE hPrevInstance,
  49. **   LPSTR lpCmdLine,
  50. **   int nCmdShow);
  51. **
  52. **    Entry point from windows for this application.
  53. **
  54. ** Modification History:
  55. ** 08/20/91  LCW  Created
  56. */
  57. int PASCAL
  58. WinMain(HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
  59. {
  60.     MSG        msg;
  61.     HANDLE    accelTable;
  62.  
  63.     /*
  64.     **    Register main window class
  65.     */
  66.     if (!RegisterWindows(hInstance, hPrevInstance))
  67.         return 1;
  68.  
  69.     /*
  70.     **    Initialize main window, and application
  71.     */
  72.     if (!InitializeApplication(hInstance, &accelTable, nCmdShow))
  73.         return 1;
  74.  
  75.     while (GetMessage((LPMSG)&msg, NULL, 0, 0))
  76.     {
  77.         if (!TranslateAccelerator(MainWindow, accelTable, (LPMSG)&msg))
  78.         {
  79.             TranslateMessage((LPMSG)&msg);
  80.             DispatchMessage((LPMSG)&msg);
  81.         }
  82.     }
  83.  
  84.     return msg.wParam;
  85. }
  86.  
  87. /*
  88. ** BOOL                                // TRUE if successful, FALSE if an error occurred
  89. ** RegisterWindows(
  90. **   HANDLE hInstance,            // Application instance handle
  91. **   HANDLE hPrevInstance);    // handle of previous instance of this application
  92. **
  93. **    Register window classes used in this application.
  94. **
  95. ** Modification History:
  96. ** 08/20/91  LCW  Created
  97. */
  98. BOOL
  99. RegisterWindows(HANDLE hInstance, HANDLE hPrevInstance)
  100. {
  101.     WNDCLASS    class;
  102.  
  103.     if (hPrevInstance)
  104.         return TRUE;
  105.  
  106.     class.style = 0;
  107.     class.lpfnWndProc = MainWndProc;
  108.     class.cbClsExtra = 0;
  109.     class.hInstance = hInstance;
  110.     class.hIcon = LoadIcon(hInstance, (LPSTR)AppName);
  111.     class.hCursor = LoadCursor((HANDLE)NULL, IDC_ARROW);
  112.     class.hbrBackground = COLOR_APPWORKSPACE + 1;
  113.     class.lpszMenuName = (LPSTR)AppName;
  114.     class.lpszClassName = (LPSTR)AppName;
  115.  
  116.     if (!RegisterClass((LPWNDCLASS)&class))
  117.     {
  118.         MessageBox((HWND)NULL, (LPSTR)"Cannot register main window class",
  119.             (LPSTR)"Bitmaps Error", MB_APPLMODAL | MB_OK | MB_ICONSTOP);
  120.         return FALSE;
  121.     }
  122.  
  123.     return TRUE;
  124. }
  125.  
  126. /*
  127. ** BOOL
  128. ** InitializeApplication(
  129. **   HANDLE hInstance,
  130. **   HANDLE *accelTable,
  131. **   int nCmdShow);
  132. **
  133. **    Initialize this application.  This involves loading the menu for the
  134. **    main window, creating the main window, and loading the accelerator table
  135. **    from the resource file.
  136. **
  137. ** Modification History:
  138. ** 08/20/91  LCW  Created
  139. */
  140. BOOL
  141. InitializeApplication(HANDLE hInstance, HANDLE *accelTable, int nCmdShow)
  142. {
  143.     HMENU        menu;
  144.  
  145.     menu = LoadMenu(hInstance, (LPSTR)AppName);
  146.  
  147.     MainWindow = CreateWindow((LPSTR)AppName,
  148.         (LPSTR)"Bitmap and Icon File Demo",
  149.         WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
  150.         CW_USEDEFAULT, (HWND)NULL, menu, hInstance, (LPSTR)NULL);
  151.  
  152.     if (MainWindow == (HWND)NULL)
  153.     {
  154.         MessageBox((HWND)NULL, (LPSTR)"Cannot open main window", (LPSTR)"Bitmaps Error",
  155.             MB_APPLMODAL | MB_OK | MB_ICONSTOP);
  156.         return FALSE;
  157.     }
  158.  
  159.     ShowWindow(MainWindow, nCmdShow);
  160.     *accelTable = LoadAccelerators(hInstance, (LPSTR)AppName);
  161.  
  162.     AppInstance = hInstance;
  163.     BitmapHandle = (HBITMAP)NULL;
  164.     IconHandle = (HICON)NULL;
  165.  
  166.     return TRUE;
  167. }
  168.  
  169. static void
  170. ClearHandles(void)
  171. {
  172.     if (DIBitmapHandle != (HANDLE)NULL)
  173.     {
  174.         GlobalFree(DIBitmapHandle);
  175.         DIBitmapHandle = (HANDLE)NULL;
  176.     }
  177.  
  178.     if (BitmapHandle != (HBITMAP)NULL)
  179.     {
  180.         DeleteObject(BitmapHandle);
  181.         BitmapHandle = (HBITMAP)NULL;
  182.     }
  183.  
  184.     if (IconHandle != (HICON)NULL)
  185.     {
  186.         DestroyIcon(IconHandle);
  187.         IconHandle = (HICON)NULL;
  188.     }
  189. }
  190.  
  191. /*
  192. ** LONG FAR PASCAL
  193. ** MainWndProc(
  194. **   HWND wnd,                Handle of window
  195. **   WORD message,        Message received from Windows
  196. **   WORD wParam,            word parameter
  197. **   DWORD lParam);        long parameter
  198. **
  199. **    Handle message from the main window.
  200. **
  201. ** Modification History:
  202. ** 09/06/91  LCW  Created
  203. */
  204. LONG FAR PASCAL
  205. MainWndProc(HWND wnd, WORD message, WORD wParam, DWORD lParam)
  206. {
  207.     FARPROC    pfn;
  208.     int        rc;
  209.     HANDLE    handle;
  210.  
  211.     switch (message)
  212.     {
  213.         case WM_COMMAND:
  214.             switch (wParam)
  215.             {
  216.                 case IDM_FILE_OPENBITMAP:
  217.                     pfn = MakeProcInstance((FARPROC)OpenFileDialog, AppInstance);
  218.                     if (pfn != (FARPROC)NULL)
  219.                     {
  220.                         lstrcpy((LPSTR)FileName, (LPSTR)"*.bmp");
  221.                         rc = DialogBox(AppInstance, (LPSTR)"OpenFile", wnd, pfn);
  222.                         FreeProcInstance(pfn);
  223.                         if (rc == 1)
  224.                         {
  225.                             /* Attempt to load the bitmap */
  226.                             handle = ReadBitmapFile(FileName);
  227.                             if (handle != (HBITMAP)NULL)
  228.                             {
  229.                                 ClearHandles();
  230.                                 DIBitmapHandle = handle;
  231.                                 InvalidateRect(wnd, NULL, TRUE);
  232.                             }
  233.                         }
  234.                     }
  235.                     break;
  236.  
  237.                 case IDM_FILE_OPENICON:
  238.                     pfn = MakeProcInstance((FARPROC)OpenFileDialog, AppInstance);
  239.                     if (pfn != (FARPROC)NULL)
  240.                     {
  241.                         lstrcpy((LPSTR)FileName, (LPSTR)"*.ico");
  242.                         rc = DialogBox(AppInstance, (LPSTR)"OpenFile", wnd, pfn);
  243.                         FreeProcInstance(pfn);
  244.  
  245.                         if (rc == 1)
  246.                         {
  247.                             /* Attempt to load the icon */
  248.                             handle = ReadIconFile(FileName);
  249.                             if (handle != (HICON)NULL)
  250.                             {
  251.                                 ClearHandles();
  252.                                 IconHandle = handle;
  253.                                 InvalidateRect(wnd, NULL, TRUE);
  254.                             }
  255.                         }
  256.                     }
  257.                     break;
  258.  
  259.                 case IDM_FILE_FMT_DIB:
  260.                     FileSaveMode = 0;
  261.                     break;
  262.  
  263.                 case IDM_FILE_FMT_RLE:
  264.                     FileSaveMode = 1;
  265.                     break;
  266.  
  267.                 case IDM_FILE_FMT_OS2:
  268.                     FileSaveMode = 2;
  269.                     break;
  270.  
  271.                 case IDM_FILE_SAVEBITMAP:
  272.                     pfn = MakeProcInstance((FARPROC)OpenFileDialog, AppInstance);
  273.                     if (pfn != (FARPROC)NULL)
  274.                     {
  275.                         lstrcpy((LPSTR)FileName, (LPSTR)"*.bmp");
  276.                         rc = DialogBox(AppInstance, (LPSTR)"SaveFile", wnd, pfn);
  277.                         FreeProcInstance(pfn);
  278.  
  279.                         if (rc == 1)
  280.                         {
  281.                             /* Attempt to save the bitmap */
  282.                             if (DIBitmapHandle == (HANDLE)NULL)
  283.                             {
  284.                                 /* First, convert to a DIB */
  285.                                 handle = BitmapToDIB(BitmapHandle, FileSaveMode);
  286.                                 if (handle != (HANDLE)NULL)
  287.                                 {
  288.                                     WriteBitmapFile(FileName, handle);
  289.                                     GlobalFree(handle);
  290.                                 }
  291.                             }
  292.                             else
  293.                             {
  294.                                 WriteBitmapFile(FileName, DIBitmapHandle);
  295.                             }
  296.                         }
  297.                     }
  298.                     break;
  299.  
  300.                 case IDM_FILE_EXIT:
  301.                     DestroyWindow(wnd);
  302.                     break;
  303.  
  304.                 case IDM_FILE_ABOUT:
  305.                     pfn = MakeProcInstance((FARPROC)AboutBoxDialog, AppInstance);
  306.                     if (pfn != (FARPROC)NULL)
  307.                     {
  308.                         DialogBox(AppInstance, (LPSTR)"AboutBox", wnd, pfn);
  309.                         FreeProcInstance(pfn);
  310.                     }
  311.                     break;
  312.  
  313.                 case IDM_EDIT_COPY:
  314.                     if (OpenClipboard(wnd))
  315.                     {
  316.                         int    fmt = 0;
  317.  
  318.                         handle = (HANDLE)NULL;
  319.  
  320.                         if (DIBitmapHandle != (HANDLE)NULL)
  321.                         {
  322.                             handle = CopyDIBitmap(DIBitmapHandle);
  323.                             fmt = CF_DIB;
  324.                         }
  325.                         else if (BitmapHandle != (HBITMAP)NULL)
  326.                         {
  327.                             handle = CopyBitmap(BitmapHandle);
  328.                             fmt = CF_BITMAP;
  329.                         }
  330.  
  331.                         if (handle != (HANDLE)NULL)
  332.                         {
  333.                             EmptyClipboard();
  334.                             SetClipboardData(fmt, handle);
  335.                         }
  336.                         CloseClipboard();
  337.                     }
  338.                     break;
  339.  
  340.                 case IDM_EDIT_PASTE:
  341.                     if (OpenClipboard(wnd))
  342.                     {
  343.                         HANDLE    handle;
  344.                         int        fmt = 0, fbmp = FALSE, fdib = FALSE;
  345.  
  346.                         while ((fmt = EnumClipboardFormats(fmt)) != 0)
  347.                         {
  348.                             if (fmt == CF_BITMAP)
  349.                             {
  350.                                 fbmp = TRUE;
  351.                             }
  352.                             if (fmt == CF_DIB)
  353.                             {
  354.                                 fdib = TRUE;
  355.                             }
  356.                         }
  357.                         if (fdib)
  358.                         {
  359.                             fmt = CF_DIB;
  360.                         }
  361.                         else if (fbmp)
  362.                         {
  363.                             fmt = CF_BITMAP;
  364.                         }
  365.  
  366.                         if (fmt != 0)
  367.                         {
  368.                             handle = GetClipboardData(fmt);
  369.                             if (fmt == CF_BITMAP)
  370.                             {
  371.                                 HBITMAP    hbm;
  372.  
  373.                                 hbm = CopyBitmap(handle);
  374.                                 if (hbm != (HBITMAP)NULL)
  375.                                 {
  376.                                     ClearHandles();
  377.                                     BitmapHandle = hbm;
  378.                                     InvalidateRect(wnd, NULL, TRUE);
  379.                                 }
  380.                             }
  381.                             else if (fmt == CF_DIB)
  382.                             {
  383.                                 HANDLE    hbm;
  384.  
  385.                                 hbm = CopyDIBitmap(handle);
  386.                                 if (hbm != (HANDLE)NULL)
  387.                                 {
  388.                                     ClearHandles();
  389.                                     DIBitmapHandle = hbm;
  390.                                     InvalidateRect(wnd, NULL, TRUE);
  391.                                 }
  392.                             }
  393.                         }
  394.  
  395.                         CloseClipboard();
  396.                     }
  397.                     break;
  398.  
  399.                 case IDM_INFO_ABOUT:
  400.                     InfoDisplay();
  401.                     break;
  402.  
  403.                 case IDM_FILE_PRINT:
  404.                     break;
  405.  
  406.                 case IDM_FILE_PRSETUP:
  407.                     break;
  408.  
  409.                 case IDM_CONVERT_LOGICAL:
  410.                     handle = DibToBitmap(DIBitmapHandle);
  411.                     if (handle)
  412.                     {
  413.                         ClearHandles();
  414.                         BitmapHandle = handle;
  415.                         InvalidateRect(wnd, NULL, TRUE);
  416.                     }
  417.                     break;
  418.  
  419.                 case IDM_CONVERT_DIB:
  420.                     if (BitmapHandle)
  421.                     {
  422.                         handle = BitmapToDIB(BitmapHandle, 0);
  423.                     }
  424.                     else
  425.                     {
  426.                         HBITMAP    hbm = DibToBitmap(DIBitmapHandle);
  427.  
  428.                         if (hbm)
  429.                         {
  430.                             handle = BitmapToDIB(hbm, 0);
  431.                             DeleteObject(hbm);
  432.                         }
  433.                     }
  434.                     if (handle)
  435.                     {
  436.                         ClearHandles();
  437.                         DIBitmapHandle = handle;
  438.                         InvalidateRect(wnd, NULL, TRUE);
  439.                     }
  440.                     break;
  441.  
  442.                 case IDM_CONVERT_RLE:
  443.                     if (BitmapHandle)
  444.                     {
  445.                         handle = BitmapToDIB(BitmapHandle, 1);
  446.                     }
  447.                     else
  448.                     {
  449.                         HBITMAP    hbm = DibToBitmap(DIBitmapHandle);
  450.  
  451.                         if (hbm)
  452.                         {
  453.                             handle = BitmapToDIB(hbm, 1);
  454.                             DeleteObject(hbm);
  455.                         }
  456.                     }
  457.                     if (handle)
  458.                     {
  459.                         ClearHandles();
  460.                         DIBitmapHandle = handle;
  461.                         InvalidateRect(wnd, NULL, TRUE);
  462.                     }
  463.                     break;
  464.  
  465.                 case IDM_CONVERT_OS2:
  466.                     if (BitmapHandle)
  467.                     {
  468.                         handle = BitmapToDIB(BitmapHandle, 2);
  469.                     }
  470.                     else
  471.                     {
  472.                         HBITMAP    hbm = DibToBitmap(DIBitmapHandle);
  473.  
  474.                         if (hbm)
  475.                         {
  476.                             handle = BitmapToDIB(hbm, 2);
  477.                             DeleteObject(hbm);
  478.                         }
  479.                     }
  480.                     if (handle)
  481.                     {
  482.                         ClearHandles();
  483.                         DIBitmapHandle = handle;
  484.                         InvalidateRect(wnd, NULL, TRUE);
  485.                     }
  486.                     break;
  487.             }
  488.             break;
  489.  
  490.         case WM_PAINT:
  491.         {
  492.             HDC            hdc;
  493.             PAINTSTRUCT    ps;
  494.  
  495.             hdc = BeginPaint(wnd, (LPPAINTSTRUCT)&ps);
  496.  
  497.             /*
  498.             **    Draw the current bitmap or icon, if either one is loaded
  499.             */
  500.             if (DIBitmapHandle != (HANDLE)NULL)
  501.             {
  502.                 DrawDIBitmap(hdc, 0, 0, DIBitmapHandle);
  503.             }
  504.             else if (BitmapHandle != (HBITMAP)NULL)
  505.             {
  506.                 DrawBitmap(hdc, 0, 0, BitmapHandle);
  507.             }
  508.             else if (IconHandle != (HICON)NULL)
  509.             {
  510.                 DrawIcon(hdc, 0, 0, IconHandle);
  511.             }
  512.  
  513.             EndPaint(wnd, (LPPAINTSTRUCT)&ps);
  514.             break;
  515.         }
  516.  
  517.         case WM_INITMENUPOPUP:
  518.             if (HIWORD(lParam) == 0)
  519.             {
  520.                 switch (LOWORD(lParam))
  521.                 {
  522.                     case 0:    /* File Menu */
  523.                         /*
  524.                         **    Enable bitmap saving only if a bitmap is loaded
  525.                         */
  526.                         if (BitmapHandle != (HBITMAP)NULL || DIBitmapHandle != (HANDLE)NULL)
  527.                         {
  528.                             EnableMenuItem(wParam, IDM_FILE_SAVEBITMAP, MF_ENABLED);
  529.                         }
  530.                         else
  531.                         {
  532.                             EnableMenuItem(wParam, IDM_FILE_SAVEBITMAP, MF_GRAYED);
  533.                         }
  534.  
  535.                         /*
  536.                         **    Check appropriate save mode
  537.                         */
  538.                         CheckMenuItem(wParam, IDM_FILE_FMT_DIB, MF_UNCHECKED);
  539.                         CheckMenuItem(wParam, IDM_FILE_FMT_RLE, MF_UNCHECKED);
  540.                         CheckMenuItem(wParam, IDM_FILE_FMT_OS2, MF_UNCHECKED);
  541.  
  542.                         CheckMenuItem(wParam, IDM_FILE_FMT_DIB + FileSaveMode, MF_CHECKED);
  543.                         break;
  544.  
  545.                     case 1:    /* Edit menu */
  546.                         /*
  547.                         **    Enable copy menu item if we have a bitmap to copy
  548.                         */
  549.                         if (BitmapHandle != (HBITMAP)NULL
  550.                             || DIBitmapHandle != (HANDLE)NULL)
  551.                         {
  552.                             EnableMenuItem(wParam, IDM_EDIT_COPY, MF_ENABLED);
  553.                         }
  554.                         else
  555.                         {
  556.                             EnableMenuItem(wParam, IDM_EDIT_COPY, MF_GRAYED);
  557.                         }
  558.  
  559.                         /*
  560.                         **    Enable paste menu item if the clipboard has a bitmap to paste
  561.                         */
  562.                         EnableMenuItem(wParam, IDM_EDIT_PASTE, MF_GRAYED);
  563.                         if (OpenClipboard(MainWindow))
  564.                         {
  565.                             int    fmt = 0;
  566.  
  567.                             while ((fmt = EnumClipboardFormats(fmt)) != 0)
  568.                             {
  569.                                 if (fmt == CF_BITMAP || fmt == CF_DIB)
  570.                                 {
  571.                                     break;
  572.                                 }
  573.                             }
  574.                             if (fmt != 0)
  575.                             {
  576.                                 EnableMenuItem(wParam, IDM_EDIT_PASTE, MF_ENABLED);
  577.                             }
  578.                             CloseClipboard();
  579.                         }
  580.                         break;
  581.  
  582.                     case 2:    /* Information Menu */
  583.                         break;
  584.  
  585.                     case 3:    /* Conversion Menu */
  586.                     {
  587.                         int    logical, dib, rle, os2;
  588.  
  589.                         logical = dib = rle = os2 = MF_ENABLED;
  590.  
  591.                         if (IconHandle)
  592.                         {
  593.                             logical = dib = rle = os2 = MF_GRAYED;
  594.                         }
  595.                         else if (BitmapHandle)
  596.                         {
  597.                             logical = MF_GRAYED;
  598.                         }
  599.                         else if (DIBitmapHandle)
  600.                         {
  601.                             if (DibIsOs2(DIBitmapHandle))
  602.                             {
  603.                                 os2 = MF_GRAYED;
  604.                             }
  605.                             else if (DibIsCompressed(DIBitmapHandle))
  606.                             {
  607.                                 rle = MF_GRAYED;
  608.                             }
  609.                             else
  610.                             {
  611.                                 dib = MF_GRAYED;
  612.                             }
  613.                         }
  614.                         else
  615.                         {
  616.                             logical = dib = rle = os2 = MF_GRAYED;
  617.                         }
  618.  
  619.                         EnableMenuItem(wParam, IDM_CONVERT_LOGICAL, logical);
  620.                         EnableMenuItem(wParam, IDM_CONVERT_DIB, dib);
  621.                         EnableMenuItem(wParam, IDM_CONVERT_RLE, rle);
  622.                         EnableMenuItem(wParam, IDM_CONVERT_OS2, os2);
  623.                         break;
  624.                     }
  625.                 }
  626.             }
  627.             break;
  628.  
  629.         case WM_DESTROY:
  630.             ClearHandles();
  631.             PostQuitMessage(0);
  632.             break;
  633.  
  634.         default:
  635.             return DefWindowProc(wnd, message, wParam, lParam);
  636.     }
  637.  
  638.     return FALSE;
  639. }
  640.  
  641. /*
  642. ** BOOL FAR PASCAL
  643. ** AboutBoxDialog(
  644. **   HWND dlg,                Handle of dialog
  645. **   WORD message,        Message received from Windows
  646. **   WORD wParam,            word parameter
  647. **   DWORD lParam);        long parameter
  648. **
  649. **    Handle the events related to the About Box.
  650. **
  651. ** Modification History:
  652. ** 09/06/91  LCW  Created
  653. */
  654. BOOL FAR PASCAL
  655. AboutBoxDialog(HWND dlg, WORD message, WORD wParam, DWORD lParam)
  656. {
  657.     switch (message)
  658.     {
  659.         case WM_COMMAND:
  660.             switch (wParam)
  661.             {
  662.                 case IDOK:
  663.                     EndDialog(dlg, 0);
  664.                     return TRUE;
  665.             }
  666.     }
  667.  
  668.     return FALSE;
  669. }
  670.  
  671. /*
  672. ** BOOL FAR PASCAL
  673. ** OpenFileDialog(
  674. **   HWND dlg,                Handle of dialog
  675. **   WORD message,        Message received from Windows
  676. **   WORD wParam,            word parameter
  677. **   DWORD lParam);        long parameter
  678. **
  679. **    Handle the getting of a name to use for opening or saving a bitmap
  680. **    or icon.
  681. **
  682. ** Modification History:
  683. ** 09/06/91  LCW  Created
  684. */
  685. BOOL FAR PASCAL
  686. OpenFileDialog(HWND dlg, WORD message, WORD wParam, DWORD lParam)
  687. {
  688.     int    rc;
  689.     HWND    wnd;
  690.  
  691.     switch (message)
  692.     {
  693.         case WM_COMMAND:
  694.             switch (wParam)
  695.             {
  696.                 case IDOK:
  697.                     wnd = GetDlgItem(dlg, IDD_FILENAME);
  698.                     rc = GetWindowTextLength(wnd);
  699.                     if (rc > 0 && rc < sizeof(FileName))
  700.                     {
  701.                         GetWindowText(wnd, (LPSTR)FileName, sizeof(FileName));
  702.                     }
  703.                     else
  704.                     {
  705.                         FileName[0] = '\0';
  706.                     }
  707.                     EndDialog(dlg, 1);
  708.                     return TRUE;
  709.  
  710.                 case IDCANCEL:
  711.                     EndDialog(dlg, 0);
  712.                     return TRUE;
  713.             }
  714.             return FALSE;
  715.  
  716.         case WM_INITDIALOG:
  717.             wnd = GetDlgItem(dlg, IDD_FILENAME);
  718.             SendMessage(wnd, EM_LIMITTEXT, sizeof(FileName), 0L);
  719.             SetWindowText(wnd, (LPSTR)FileName);
  720.             SetFocus(wnd);
  721.             return TRUE;
  722.     }
  723.  
  724.     return FALSE;
  725. }
  726.  
  727. /*
  728. ** void
  729. ** ErrorBox(char *msg);        pointer to message to be displayed
  730. **
  731. **    This function displays a simple error message in a Windows message box
  732. **    to inform the user of a problem.
  733. **
  734. ** Modification History:
  735. ** 09/06/91  LCW  Created
  736. */
  737. void
  738. ErrorBox(char *msg)
  739. {
  740.     MessageBox(MainWindow, (LPSTR)msg, NULL, MB_OK | MB_ICONSTOP | MB_TASKMODAL);
  741. }
  742.  
  743. /*
  744. **    Modification History
  745. **    --------------------
  746. **    $lgb$
  747. ** 10/15/91     Larry Widing   Initial version for Win Tech Journal Article.
  748. ** 11/12/91     Larry Widing   Added support for bitmap conversion.
  749. **    $lge$
  750. */
  751.