home *** CD-ROM | disk | FTP | other *** search
/ CD-ROM User 1995 January / CDuser6Jan95.iso / DYNASTY / WING / HALFTONE.C_ / HALFTONE.C
Text File  |  1994-06-19  |  21KB  |  576 lines

  1. /*
  2.  *    HALFTONE.C
  3.  *
  4.  *    (C) Copyright Microsoft Corp. 1994.  All rights reserved.
  5.  *
  6.  *    You have a royalty-free right to use, modify, reproduce and 
  7.  *    distribute the Sample Files (and/or any modified version) in 
  8.  *    any way you find useful, provided that you agree that 
  9.  *    Microsoft has no warranty obligations or liability for any 
  10.  *    Sample Application Files which are modified. 
  11.  */
  12.  
  13.  
  14. #include <windows.h>
  15. #include <windowsx.h>
  16. #include <commdlg.h>
  17.  
  18. #include <wing.h>
  19.  
  20. #include "halftone.h"
  21. #include "dib.h"
  22.  
  23. /*----------------------------------------------------------------------------*\
  24. |                                                                              |
  25. |   g l o b a l   v a r i a b l e s                                            |
  26. |                                                                              |
  27. \*----------------------------------------------------------------------------*/
  28. static    char    szAppName[]="WinG Halftoning Sample";
  29. static    char    szAppFilter[]="Bitmaps\0*.bmp;*.dib\0";
  30.  
  31. static  HINSTANCE hInstApp;
  32. static  HWND      hwndApp;
  33. static    HPALETTE  hpalApp;
  34. static    BOOL      fAppActive;
  35.  
  36. static BOOL fCustomDither = TRUE;
  37.  
  38. static PDIB pdibOriginal = 0;
  39. static PDIB pdibHalftone = 0;
  40.  
  41. #ifdef WIN32
  42.     #define _export
  43. #endif
  44.  
  45. /*----------------------------------------------------------------------------*\
  46. |                                                                              |
  47. |   f u n c t i o n   d e f i n i t i o n s                                    |
  48. |                                                                              |
  49. \*----------------------------------------------------------------------------*/
  50.  
  51. LONG FAR PASCAL _export AppWndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam);
  52. LONG AppCommand (HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam);
  53.  
  54. void AppExit(void);
  55. BOOL AppIdle(void);
  56. void AppOpenFile(HWND hwnd, LPSTR szFileName);
  57.  
  58. PDIB DibHalftoneDIB( PDIB pSource );
  59.  
  60. /*----------------------------------------------------------------------------*\
  61. |   AppAbout( hDlg, uiMessage, wParam, lParam )                                |
  62. |                                                                              |
  63. |   Description:                                                               |
  64. |       This function handles messages belonging to the "About" dialog box.    |
  65. |       The only message that it looks for is WM_COMMAND, indicating the use   |
  66. |       has pressed the "OK" button.  When this happens, it takes down         |
  67. |       the dialog box.                                                        |
  68. |                                                                              |
  69. |   Arguments:                                                                 |
  70. |       hDlg            window handle of about dialog window                   |
  71. |       uiMessage       message number                                         |
  72. |       wParam          message-dependent                                      |
  73. |       lParam          message-dependent                                      |
  74. |                                                                              |
  75. |   Returns:                                                                   |
  76. |       TRUE if message has been processed, else FALSE                         |
  77. |                                                                              |
  78. \*----------------------------------------------------------------------------*/
  79. BOOL FAR PASCAL _export AppAbout(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
  80. {
  81.     switch (msg)
  82.     {
  83.         case WM_COMMAND:
  84.         if (LOWORD(wParam) == IDOK)
  85.             {
  86.                 EndDialog(hwnd,TRUE);
  87.             }
  88.             break;
  89.  
  90.         case WM_INITDIALOG:
  91.             return TRUE;
  92.     }
  93.     return FALSE;
  94. }
  95.  
  96. /*----------------------------------------------------------------------------*\
  97. |   AppInit( hInst, hPrev)                                                     |
  98. |                                                                              |
  99. |   Description:                                                               |
  100. |       This is called when the application is first loaded into               |
  101. |       memory.  It performs all initialization that doesn't need to be done   |
  102. |       once per instance.                                                     |
  103. |                                                                              |
  104. |   Arguments:                                                                 |
  105. |       hInstance       instance handle of current instance                    |
  106. |       hPrev           instance handle of previous instance                   |
  107. |                                                                              |
  108. |   Returns:                                                                   |
  109. |       TRUE if successful, FALSE if not                                       |
  110. |                                                                              |
  111. \*----------------------------------------------------------------------------*/
  112. BOOL AppInit(HINSTANCE hInst,HINSTANCE hPrev,int sw,LPSTR szCmdLine)
  113. {
  114.     WNDCLASS cls;
  115.     int      dx,dy;
  116.       HMENU hMenu;
  117.  
  118.     /* Save instance handle for DialogBoxs */
  119.     hInstApp = hInst;
  120.  
  121.     if (!hPrev)
  122.     {
  123.         /*
  124.          *  Register a class for the main application window
  125.          */
  126.         cls.hCursor        = LoadCursor(NULL,IDC_ARROW);
  127.         cls.hIcon          = LoadIcon(hInst,"AppIcon");
  128.         cls.lpszMenuName   = "AppMenu";
  129.         cls.lpszClassName  = szAppName;
  130.         cls.hbrBackground  = (HBRUSH)(COLOR_WINDOW + 1);
  131.         cls.hInstance      = hInst;
  132.         cls.style          = CS_BYTEALIGNCLIENT | CS_VREDRAW | CS_HREDRAW | CS_DBLCLKS;
  133.         cls.lpfnWndProc    = (WNDPROC)AppWndProc;
  134.         cls.cbWndExtra     = 0;
  135.         cls.cbClsExtra     = 0;
  136.  
  137.         if (!RegisterClass(&cls))
  138.             return FALSE;
  139.     }
  140.  
  141.     dx = GetSystemMetrics (SM_CXSCREEN) / 2;
  142.     dy = GetSystemMetrics (SM_CYSCREEN) / 2;
  143.  
  144.     hpalApp = WinGCreateHalftonePalette();
  145.  
  146.     hwndApp = CreateWindow (szAppName,    // Class name
  147.                             szAppName,              // Caption
  148.                             WS_OVERLAPPEDWINDOW,    // Style bits
  149.                             CW_USEDEFAULT, 0,       // Position
  150.                 dx,dy,            // Size
  151.                             (HWND)NULL,             // Parent window (no parent)
  152.                             (HMENU)NULL,            // use class menu
  153.                             hInst,                  // handle to window instance
  154.                             (LPSTR)NULL             // no params to pass on
  155.                            );
  156.     ShowWindow(hwndApp,sw);
  157.  
  158.     //*** Check the default dither selection
  159.     hMenu = GetMenu(hwndApp);
  160.     CheckMenuItem(hMenu, MENU_WING, fCustomDither ? MF_CHECKED : MF_UNCHECKED);
  161.     CheckMenuItem(hMenu, MENU_GDI, fCustomDither ? MF_UNCHECKED : MF_CHECKED);
  162.  
  163.     if (*szCmdLine)
  164.     AppOpenFile(hwndApp, szCmdLine);
  165.  
  166.     return TRUE;
  167. }
  168.  
  169.  
  170. /*----------------------------------------------------------------------------*\
  171. |   AppExit()                                       |
  172. |                                                                              |
  173. |   Description:                                                               |
  174. |    app is just about to exit, cleanup                       |
  175. |                                                                              |
  176. \*----------------------------------------------------------------------------*/
  177. void AppExit()
  178. {
  179.     if (hpalApp)
  180.         DeleteObject(hpalApp);
  181.     if (pdibOriginal)
  182.         DibFree(pdibOriginal);
  183.     if (pdibHalftone)
  184.         DibFree(pdibHalftone);
  185. }
  186.  
  187. /*----------------------------------------------------------------------------*\
  188. |   WinMain( hInst, hPrev, lpszCmdLine, cmdShow )                              |
  189. |                                                                              |
  190. |   Description: