ReactOS  0.4.15-dev-341-g17c5fb8
wm_erasebkgnd.cpp
Go to the documentation of this file.
1 
2 // ------------------------------------------------------------------
3 // Windows 2000 Graphics API Black Book
4 // Chapter 2 - CD-ROM (WM_ERASEBKGND Demo)
5 //
6 // Created by Damon Chandler <dmc27@ee.cornell.edu>
7 // Updates can be downloaded at: <www.coriolis.com>
8 //
9 // Please do not hesistate to e-mail me at dmc27@ee.cornell.edu
10 // if you have any questions about this code.
11 // ------------------------------------------------------------------
12 
13 //*********************************************************//
14 // //
15 // SYNOPSIS: //
16 // This sample project demonstrates how to render //
17 // a background image in response to the WM_ERASEBKGND //
18 // message. It also shows how to create a transparent //
19 // static (text) control by handling the //
20 // WM_CTLCOLORSTATIC message. //
21 // //
22 //*********************************************************//
23 
24 
25 //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
26 #include <windows.h>
27 //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
28 
29 
33 const char* WndClassName = "GMainWnd";
35  LPARAM LParam);
36 
37 
38 int APIENTRY WinMain(HINSTANCE HInstance, HINSTANCE HPrevInstance,
39  LPTSTR lpCmdLine, int nCmdShow)
40 {
41  HInst = HInstance;
42  HPrevInst = HPrevInstance;
43  cmdline = lpCmdLine;
44 
45  WNDCLASS wc;
46  memset(&wc, 0, sizeof(WNDCLASS));
47 
50  wc.hInstance = HInstance;
52  wc.hbrBackground =
53  reinterpret_cast<HBRUSH>(COLOR_BTNFACE + 1);
55 
56  if (RegisterClass(&wc))
57  {
58  HWND HWnd =
60  TEXT("WM_ERASEBKGND Demo"),
63  CW_USEDEFAULT, CW_USEDEFAULT, 205, 85,
64  NULL, NULL, HInstance, NULL);
65 
66  if (HWnd)
67  {
68  ShowWindow(HWnd, nCmdShow);
69  UpdateWindow(HWnd);
70 
71  MSG msg;
72  while (GetMessage(&msg, NULL, 0, 0))
73  {
76  }
77  }
78  }
79  return 0;
80 }
81 //------------------------------------------------------------------
82 
83 
84 // static text and bitmap-related variables
88 const char* filename = "BACKBITMAP.BMP";
89 
91  LPARAM LParam)
92 {
93  switch (Msg)
94  {
95  case WM_CREATE:
96  {
97  HStatic =
98  CreateWindow(TEXT("STATIC"), TEXT("Static Text"),
100  10, 20, 175, 30,
101  HWnd, NULL, HInst, NULL);
102 
103  // create a memory DC compatible with the screen
105  if (HMemDC)
106  {
107  // load a DDB from file
108  HBmp = static_cast<HBITMAP>(
110  0, 0, LR_LOADFROMFILE)
111  );
112  if (HBmp)
113  {
114  // associate the DDB with the memory DC
115  HOldBmp = static_cast<HBITMAP>(
117  );
118  }
119  }
120  }
121  case WM_CTLCOLORSTATIC:
122  {
123  if (reinterpret_cast<HWND>(LParam) == HStatic)
124  {
125  HDC HStaticDC = reinterpret_cast<HDC>(WParam);
126  SetBkMode(HStaticDC, TRANSPARENT);
127 
128  return reinterpret_cast<LRESULT>(
130  );
131  }
132  break;
133  }
134  case WM_ERASEBKGND:
135  {
136  BITMAP bmp;
137  if (GetObject(HBmp, sizeof(BITMAP), &bmp))
138  {
139  RECT RClient;
140  GetClientRect(HWnd, &RClient);
141 
142  HDC Hdc = reinterpret_cast<HDC>(WParam);
144 
145  //
146  // TODO: add palette handling code for
147  // palettized displays (see Chapter 9)...
148  //
149 
150  // render the background image
151  StretchBlt(Hdc, 0, 0,
152  RClient.right - RClient.left,
153  RClient.bottom - RClient.top,
154  HMemDC, 0, 0, bmp.bmWidth, bmp.bmHeight,
155  SRCCOPY);
156  return TRUE;
157  }
158  break;
159  }
160  case WM_DESTROY:
161  {
162  if (HBmp)
163  {
164  // free the bitmap
166  }
167  // free the memory DC
168  DeleteDC(HMemDC);
169 
170  PostQuitMessage(0);
171  return 0;
172  }
173  }
174  return DefWindowProc(HWnd, Msg, WParam, LParam);
175 }
176 //------------------------------------------------------------------
177 
178 
179 
HGDIOBJ WINAPI GetStockObject(_In_ int)
struct @1608 Msg[]
#define WS_CLIPSIBLINGS
Definition: pedump.c:618
#define DispatchMessage
Definition: winuser.h:5740
BOOL WINAPI TranslateMessage(_In_ const MSG *)
#define TRUE
Definition: types.h:120
#define CreateWindow
Definition: winuser.h:5729
HINSTANCE HInst
LRESULT CALLBACK MainWndProc(HWND HWnd, UINT Msg, WPARAM WParam, LPARAM LParam)
#define LR_LOADFROMFILE
Definition: winuser.h:1082
#define NULL_BRUSH
Definition: wingdi.h:900
#define WM_CTLCOLORSTATIC
Definition: winuser.h:1754
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1827
static HDC
Definition: imagelist.c:92
#define CALLBACK
Definition: compat.h:27
BOOL WINAPI UpdateWindow(_In_ HWND)
LONG top
Definition: windef.h:307
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1497
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
#define CS_HREDRAW
Definition: winuser.h:648
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
int APIENTRY WinMain(HINSTANCE HInstance, HINSTANCE HPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
UINT_PTR WPARAM
Definition: windef.h:207
HBRUSH hbrBackground
Definition: winuser.h:3145
#define WS_CHILD
Definition: pedump.c:617
LONG left
Definition: windef.h:306
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
#define COLORONCOLOR
Definition: wingdi.h:953
const char * filename
Definition: ioapi.h:135
LONG right
Definition: windef.h:308
BOOL WINAPI StretchBlt(_In_ HDC, _In_ int, _In_ int, _In_ int, _In_ int, _In_opt_ HDC, _In_ int, _In_ int, _In_ int, _In_ int, _In_ DWORD)
CHAR * LPTSTR
Definition: xmlstorage.h:192
int WINAPI SetBkMode(_In_ HDC, _In_ int)
Definition: dc.c:1032
HCURSOR hCursor
Definition: winuser.h:3144
#define TRANSPARENT
Definition: wingdi.h:949
#define CW_USEDEFAULT
Definition: winuser.h:225
smooth NULL
Definition: ftsmooth.c:416
LONG_PTR LPARAM
Definition: windef.h:208
#define DefWindowProc
Definition: ros2win.h:31
#define WM_DESTROY
Definition: winuser.h:1591
#define WS_CAPTION
Definition: pedump.c:624
const char * WndClassName
#define CS_VREDRAW
Definition: winuser.h:653
char TCHAR
Definition: xmlstorage.h:189
#define SS_CENTER
Definition: pedump.c:693
HINSTANCE HPrevInst
#define GetObject
Definition: wingdi.h:4467
BITMAP bmp
Definition: alphablend.c:62
#define COLOR_BTNFACE
Definition: winuser.h:918
#define CS_DBLCLKS
Definition: winuser.h:646
LPCSTR lpszClassName
Definition: winuser.h:3147
#define LoadCursor
Definition: winuser.h:5787
int WINAPI SetStretchBltMode(_In_ HDC, _In_ int)
Definition: dc.c:1324
UINT style
Definition: winuser.h:3138
BOOL WINAPI GetClientRect(_In_ HWND, _Out_ LPRECT)
#define TEXT(s)
Definition: k32.h:26
BOOL WINAPI DeleteDC(_In_ HDC)
HINSTANCE hInstance
Definition: winuser.h:3142
Definition: bl.h:1331
unsigned int UINT
Definition: ndis.h:50
#define IMAGE_BITMAP
Definition: winuser.h:211
#define GetMessage
Definition: winuser.h:5765
HDC HMemDC
WNDPROC lpfnWndProc
Definition: winuser.h:3139
#define msg(x)
Definition: auth_time.c:54
#define IDC_ARROW
Definition: winuser.h:682
#define WM_CREATE
Definition: winuser.h:1590
TCHAR * cmdline
HWND HStatic
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637
LONG bottom
Definition: windef.h:309
#define LoadImage
Definition: winuser.h:5790
static HBITMAP
Definition: button.c:44
#define RegisterClass
Definition: winuser.h:5811
HBITMAP HOldBmp
#define WM_ERASEBKGND
Definition: winuser.h:1607
LONG_PTR LRESULT
Definition: windef.h:209
#define WS_VISIBLE
Definition: pedump.c:620
#define memset(x, y, z)
Definition: compat.h:39
__analysis_noreturn void WINAPI PostQuitMessage(_In_ int)
#define SRCCOPY
Definition: wingdi.h:332
#define APIENTRY
Definition: api.h:79
HBITMAP HBmp