home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / win_lrn / text / setbkmd.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-08-11  |  2.7 KB  |  79 lines

  1. /*
  2.  *  SetBkMode
  3.  *  setbkmd.c
  4.  *
  5.  *  This program demonstrates the use of the function SetBkMode.
  6.  *  It sets the background mode used with text, hatched brushes, and 
  7.  *  line styles. This program only illustrates with text in the client
  8.  *  area. 
  9.  *
  10.  */
  11.  
  12. #include "windows.h"
  13.  
  14. /* Procedure called when the application is loaded for the first time */
  15. BOOL WinInit( hInstance )
  16. HANDLE hInstance;
  17. {
  18.     WNDCLASS   wcClass;
  19.  
  20.     /* registering the parent window class */
  21.     wcClass.hCursor        = LoadCursor( NULL, IDC_ARROW );
  22.     wcClass.hIcon          = LoadIcon (hInstance, (LPSTR)"WindowIcon");
  23.     wcClass.lpszMenuName   = (LPSTR)NULL;
  24.     wcClass.lpszClassName  = (LPSTR)"Setbkmd";
  25.     wcClass.hbrBackground  = (HBRUSH)GetStockObject( LTGRAY_BRUSH );
  26.     wcClass.hInstance      = hInstance;
  27.     wcClass.style          = CS_HREDRAW | CS_VREDRAW;
  28.     wcClass.lpfnWndProc    = DefWindowProc;
  29.     wcClass.cbClsExtra     = 0;
  30.     wcClass.cbWndExtra     = 0;
  31.  
  32.     RegisterClass( (LPWNDCLASS)&wcClass );
  33.     return TRUE;        /* Initialization succeeded */
  34. }
  35.  
  36. int PASCAL WinMain( hInstance, hPrevInstance, lpszCmdLine, cmdShow )
  37. HANDLE hInstance, hPrevInstance;
  38. LPSTR lpszCmdLine;
  39. int cmdShow;
  40. {
  41.     HWND  hWnd;                        /* Handle to the parent window    */
  42.     HDC   hDC;                         /* Display context of client area */
  43.  
  44.     WinInit (hInstance);
  45.  
  46.     hWnd = CreateWindow((LPSTR)"Setbkmd",
  47.                         (LPSTR)"Setting Background Mode",
  48.                         WS_OVERLAPPEDWINDOW,
  49.                         50,                /* x         */
  50.                         50,                /* y         */
  51.                         600,               /* width     */
  52.                         250,               /* height    */
  53.                         (HWND)NULL,        /* no parent */
  54.                         (HMENU)NULL,       /* use class menu */
  55.                         (HANDLE)hInstance, /* handle to window instance */
  56.                         (LPSTR)NULL        /* no params to pass on */
  57.                        );
  58.  
  59.     /* Make window visible according to the way the app is activated */
  60.     ShowWindow( hWnd, cmdShow );
  61.     UpdateWindow( hWnd );
  62.  
  63.     /* Get a DC before writing to the client area */
  64.     hDC = GetDC (hWnd);
  65.  
  66.     /* The default background mode is Opaque */
  67.     TextOut(hDC, 20, 10, (LPSTR) "This is Opaque Background Mode", 30);
  68.  
  69.     /* Change the background mode to Transparent */
  70.     SetBkMode (hDC, TRANSPARENT);
  71.     TextOut(hDC, 20, 30, (LPSTR) "This is Transparent Background mode", 35);
  72.  
  73.     ReleaseDC (hWnd, hDC);
  74.     
  75.     MessageBox (hWnd, (LPSTR)"The background mode has changed", (LPSTR)"Done", MB_OK);
  76.  
  77.     return 0;
  78. }
  79.