ReactOS 0.4.15-dev-7958-gcd0bb1a
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
33const char* WndClassName = "GMainWnd";
35 LPARAM LParam);
36
37
38int 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"),
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
88const 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 }
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
169
171 return 0;
172 }
173 }
174 return DefWindowProc(HWnd, Msg, WParam, LParam);
175}
176//------------------------------------------------------------------
177
178
179
#define msg(x)
Definition: auth_time.c:54
struct @1632 Msg[]
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define APIENTRY
Definition: api.h:79
#define CALLBACK
Definition: compat.h:35
pKey DeleteObject()
const char * filename
Definition: ioapi.h:137
#define TEXT(s)
Definition: k32.h:26
BITMAP bmp
Definition: alphablend.c:62
static HBITMAP
Definition: button.c:44
static HDC
Definition: imagelist.c:92
unsigned int UINT
Definition: ndis.h:50
#define WS_CHILD
Definition: pedump.c:617
#define WS_CAPTION
Definition: pedump.c:624
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637
#define WS_VISIBLE
Definition: pedump.c:620
#define SS_CENTER
Definition: pedump.c:693
#define WS_CLIPSIBLINGS
Definition: pedump.c:618
#define DefWindowProc
Definition: ros2win.h:31
#define memset(x, y, z)
Definition: compat.h:39
Definition: bl.h:1331
HBRUSH hbrBackground
Definition: winuser.h:3170
HINSTANCE hInstance
Definition: winuser.h:3167
HCURSOR hCursor
Definition: winuser.h:3169
UINT style
Definition: winuser.h:3163
LPCSTR lpszClassName
Definition: winuser.h:3172
WNDPROC lpfnWndProc
Definition: winuser.h:3164
LONG right
Definition: windef.h:308
LONG bottom
Definition: windef.h:309
LONG top
Definition: windef.h:307
LONG left
Definition: windef.h:306
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1829
LONG_PTR LPARAM
Definition: windef.h:208
LONG_PTR LRESULT
Definition: windef.h:209
UINT_PTR WPARAM
Definition: windef.h:207
HGDIOBJ WINAPI GetStockObject(_In_ int)
#define COLORONCOLOR
Definition: wingdi.h:954
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1539
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
#define TRANSPARENT
Definition: wingdi.h:950
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)
#define SRCCOPY
Definition: wingdi.h:333
#define NULL_BRUSH
Definition: wingdi.h:901
int WINAPI SetBkMode(_In_ HDC, _In_ int)
Definition: dc.c:1056
#define GetObject
Definition: wingdi.h:4468
BOOL WINAPI DeleteDC(_In_ HDC)
int WINAPI SetStretchBltMode(_In_ HDC, _In_ int)
Definition: dc.c:1366
#define WM_ERASEBKGND
Definition: winuser.h:1625
#define CS_VREDRAW
Definition: winuser.h:658
#define WM_CTLCOLORSTATIC
Definition: winuser.h:1772
#define IMAGE_BITMAP
Definition: winuser.h:211
BOOL WINAPI TranslateMessage(_In_ const MSG *)
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
#define LR_LOADFROMFILE
Definition: winuser.h:1092
#define WM_CREATE
Definition: winuser.h:1608
__analysis_noreturn void WINAPI PostQuitMessage(_In_ int)
#define CS_HREDRAW
Definition: winuser.h:653
#define IDC_ARROW
Definition: winuser.h:687
#define CS_DBLCLKS
Definition: winuser.h:651
#define CreateWindow
Definition: winuser.h:5754
#define GetMessage
Definition: winuser.h:5790
BOOL WINAPI GetClientRect(_In_ HWND, _Out_ LPRECT)
BOOL WINAPI UpdateWindow(_In_ HWND)
#define LoadCursor
Definition: winuser.h:5812
#define CW_USEDEFAULT
Definition: winuser.h:225
#define LoadImage
Definition: winuser.h:5815
#define RegisterClass
Definition: winuser.h:5836
#define WM_DESTROY
Definition: winuser.h:1609
#define DispatchMessage
Definition: winuser.h:5765
#define COLOR_BTNFACE
Definition: winuser.h:928
HBITMAP HBmp
const char * WndClassName
HWND HStatic
HINSTANCE HPrevInst
HDC HMemDC
int APIENTRY WinMain(HINSTANCE HInstance, HINSTANCE HPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
LRESULT CALLBACK MainWndProc(HWND HWnd, UINT Msg, WPARAM WParam, LPARAM LParam)
TCHAR * cmdline
HINSTANCE HInst
HBITMAP HOldBmp
char TCHAR
Definition: xmlstorage.h:189
CHAR * LPTSTR
Definition: xmlstorage.h:192