home *** CD-ROM | disk | FTP | other *** search
/ cyber.net interactivo 13 / cybernetinteractivo13.ISO / wing / halftone.c_ / halftone.c
Text File  |  1994-08-13  |  22KB  |  575 lines

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