home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_03_06 / 3n06036a < prev    next >
Text File  |  1992-04-29  |  3KB  |  120 lines

  1. bitmap.c
  2. #include <windows.h>
  3. #include "bitmap.h"
  4.  
  5. static HANDLE hInst;
  6.  
  7. BOOL FAR PASCAL AboutDlgProc (HWND hDlg, WORD message, WORD wParam, LONG lParam)
  8.     {
  9.     HDC hdcFrame, hdcMem;
  10.     HWND hwndFrame;
  11.     HBITMAP hbmpOld, hbmpBitmap;
  12.     RECT rect;
  13.  
  14.     switch (message)
  15.         {
  16.         case WM_PAINT:
  17.             hwndFrame = GetDlgItem (hDlg, ID_BLACKFRAME);
  18.             hdcFrame = GetDC (hwndFrame);
  19.             GetClientRect (hwndFrame, &rect);
  20.  
  21.             hdcMem = CreateCompatibleDC (hdcFrame);
  22.             hbmpBitmap = LoadBitmap (hInst, szBitmap);
  23.             hbmpOld = SelectObject (hdcMem, hbmpBitmap);
  24.  
  25.             BitBlt (hdcFrame, 0, 0, rect.right, rect.bottom, hdcMem, 0, 0, SRCCOPY);
  26.             ReleaseDC (hwndFrame, hdcFrame);
  27.  
  28.             hwndFrame = GetDlgItem (hDlg, ID_GRAYFRAME);
  29.             hdcFrame = GetDC (hwndFrame);
  30.  
  31.             BitBlt (hdcFrame, 0, 0, rect.right, rect.bottom, hdcMem, 0, 0, SRCCOPY);
  32.             ReleaseDC (hwndFrame, hdcFrame);
  33.  
  34.             hwndFrame = GetDlgItem (hDlg, ID_WHITEFRAME);
  35.             hdcFrame = GetDC (hwndFrame);
  36.  
  37.             BitBlt (hdcFrame, 0, 0, rect.right, rect.bottom, hdcMem, 0, 0, SRCCOPY);
  38.             ReleaseDC (hwndFrame, hdcFrame);
  39.  
  40.             SelectObject (hdcMem, hbmpOld);
  41.             DeleteObject (hbmpBitmap);
  42.             DeleteDC (hdcMem);
  43.             break;
  44.         case WM_COMMAND:
  45.             switch (wParam)
  46.                 {
  47.                 case IDOK:
  48.                     EndDialog (hDlg, 0);
  49.                     return TRUE;
  50.                 }
  51.             break;
  52.         }
  53.     return FALSE;
  54.     }
  55.  
  56. int PASCAL WinMain (HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpszCmdParam, int nCmdShow)
  57.     {
  58.     HWND hwnd;
  59.     MSG msg;
  60.     WNDCLASS wndclass;
  61.  
  62.     if (!hPrevInstance)
  63.         {
  64.         wndclass.style = CS_HREDRAW | CS_VREDRAW;
  65.         wndclass.lpfnWndProc = WndProc;
  66.         wndclass.cbClsExtra = 0;
  67.         wndclass.cbWndExtra = 0;
  68.         wndclass.hInstance = hInstance;
  69.         wndclass.hIcon = LoadIcon (hInstance, szAppIcon);
  70.         wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
  71.         wndclass.hbrBackground = GetStockObject (WHITE_BRUSH);
  72.         wndclass.lpszMenuName = NULL;
  73.         wndclass.lpszClassName = szAppName;
  74.         RegisterClass (&wndclass);
  75.         }
  76.     hInst = hInstance;
  77.     hwnd = CreateWindow (szAppName, szAppName, WS_BORDER | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX, CW_USEDEFAULT, CW_USEDEFAULT, 300, 75, NULL, NULL, hInstance, NULL);
  78.     ShowWindow (hwnd, SW_SHOWMINIMIZED);
  79.     UpdateWindow (hwnd);
  80.  
  81.     while (GetMessage (&msg, NULL, 0, 0))
  82.         {
  83.         TranslateMessage (&msg);
  84.         DispatchMessage (&msg);
  85.         }
  86.     return msg.wParam;
  87.     }
  88.  
  89. long FAR PASCAL WndProc (HWND hwnd, WORD message, WORD wParam, LONG lParam)
  90.     {
  91.     FARPROC lpfnDlgProc;
  92.     HMENU hMenu;
  93.  
  94.     switch (message)
  95.         {
  96.         case WM_CREATE:
  97.             hMenu = GetSystemMenu (hwnd, FALSE);
  98.             AppendMenu (hMenu, MF_SEPARATOR, 0, NULL);
  99.             AppendMenu (hMenu, MF_STRING, IDM_ABOUT, szSysAbout);
  100.             return 0;
  101.         case WM_SYSCOMMAND:
  102.             switch (wParam)
  103.                 {
  104.                 case IDM_ABOUT:
  105.                     lpfnDlgProc = MakeProcInstance (AboutDlgProc, hInst);
  106.                     DialogBox (hInst, szAppAbout, hwnd, lpfnDlgProc);
  107.                     FreeProcInstance (lpfnDlgProc);
  108.                     return 0;
  109.                 }
  110.             break;
  111.         case WM_DESTROY:
  112.             PostQuitMessage (0);
  113.             return 0;
  114.         default:
  115.             return DefWindowProc (hwnd, message, wParam, lParam);
  116.         }
  117.     return DefWindowProc (hwnd, message, wParam, lParam);
  118.     }
  119.  
  120.