2004-10-21 04:48:46 +00:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------
|
|
|
|
// Windows 2000 Graphics API Black Book
|
|
|
|
// Chapter 1 - Listing 1.1 (WM_PAINT Demo)
|
|
|
|
//
|
|
|
|
// Created by Damon Chandler <dmc27@ee.cornell.edu>
|
|
|
|
// Updates can be downloaded at: <www.coriolis.com>
|
|
|
|
//
|
2005-05-07 21:24:31 +00:00
|
|
|
// Please do not hesistate to e-mail me at dmc27@ee.cornell.edu
|
2004-10-21 04:48:46 +00:00
|
|
|
// if you have any questions about this code.
|
|
|
|
// ------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|
|
|
#include <windows.h>
|
|
|
|
#include <string.h>
|
|
|
|
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
|
|
|
|
|
|
|
|
|
|
|
const char* WndClassName = "GMainWnd";
|
2005-05-07 21:24:31 +00:00
|
|
|
LRESULT CALLBACK MainWndProc(HWND HWnd, UINT Msg, WPARAM WParam,
|
2004-10-21 04:48:46 +00:00
|
|
|
LPARAM LParam);
|
|
|
|
|
|
|
|
|
|
|
|
int APIENTRY WinMain(HINSTANCE HInstance, HINSTANCE HPrevInstance,
|
|
|
|
LPTSTR lpCmdLine, int nCmdShow)
|
|
|
|
{
|
|
|
|
MSG msg;
|
|
|
|
WNDCLASS wc;
|
|
|
|
memset(&wc, 0, sizeof(WNDCLASS));
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2004-10-21 04:48:46 +00:00
|
|
|
wc.style = CS_VREDRAW | CS_HREDRAW | CS_DBLCLKS;
|
|
|
|
wc.lpfnWndProc = MainWndProc;
|
|
|
|
wc.hInstance = HInstance;
|
|
|
|
wc.hCursor = LoadCursor(NULL, (LPCTSTR)IDC_ARROW);
|
|
|
|
wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
|
|
|
|
wc.lpszClassName = WndClassName;
|
|
|
|
|
|
|
|
if (RegisterClass(&wc))
|
|
|
|
{
|
2005-05-07 21:24:31 +00:00
|
|
|
HWND HWnd =
|
2004-10-21 04:48:46 +00:00
|
|
|
CreateWindow(WndClassName, TEXT("WM_PAINT Demo"),
|
|
|
|
WS_OVERLAPPEDWINDOW | WS_CAPTION | WS_VISIBLE,
|
|
|
|
CW_USEDEFAULT, CW_USEDEFAULT, 200, 150,
|
|
|
|
NULL, NULL, HInstance, NULL);
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2004-10-21 04:48:46 +00:00
|
|
|
if (HWnd)
|
|
|
|
{
|
|
|
|
ShowWindow(HWnd, nCmdShow);
|
|
|
|
UpdateWindow(HWnd);
|
|
|
|
|
|
|
|
while (GetMessage(&msg, NULL, 0, 0))
|
|
|
|
{
|
|
|
|
TranslateMessage(&msg);
|
|
|
|
DispatchMessage(&msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
2005-05-07 21:24:31 +00:00
|
|
|
LRESULT CALLBACK MainWndProc(HWND HWnd, UINT Msg, WPARAM WParam,
|
2004-10-21 04:48:46 +00:00
|
|
|
LPARAM LParam)
|
|
|
|
{
|
2005-05-07 21:24:31 +00:00
|
|
|
const char* text = "Persistent Text";
|
2004-10-21 04:48:46 +00:00
|
|
|
|
|
|
|
switch (Msg)
|
|
|
|
{
|
|
|
|
case WM_PAINT:
|
|
|
|
{
|
2005-05-07 21:24:31 +00:00
|
|
|
// determine the invalidated area of the window
|
2004-10-21 04:48:46 +00:00
|
|
|
RECT RUpdate;
|
|
|
|
HDC Hdc;
|
|
|
|
GetUpdateRect(HWnd, &RUpdate, FALSE);
|
|
|
|
|
|
|
|
// grab a handle to our window's
|
|
|
|
// common display device context
|
|
|
|
Hdc = GetDC(HWnd);
|
|
|
|
#if 0
|
|
|
|
try
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
RECT RClient;
|
|
|
|
GetClientRect(HWnd, &RClient);
|
|
|
|
|
|
|
|
// set the clipping region
|
2005-05-07 21:24:31 +00:00
|
|
|
IntersectClipRect(Hdc, RUpdate.left, RUpdate.top,
|
2004-10-21 04:48:46 +00:00
|
|
|
RUpdate.right, RUpdate.bottom);
|
|
|
|
|
|
|
|
// fill the client area with the background brush
|
2006-09-09 11:41:24 +00:00
|
|
|
/*HBRUSH HBrush =
|
|
|
|
reinterpret_cast<HBRUSH>
|
2004-10-21 04:48:46 +00:00
|
|
|
(HBRUSH)(GetClassLong(HWnd, GCL_HBRBACKGROUND)
|
2006-09-09 11:41:24 +00:00
|
|
|
);*/
|
2004-10-21 04:48:46 +00:00
|
|
|
FillRect(Hdc, &RClient, NULL);
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2004-10-21 04:48:46 +00:00
|
|
|
// render the persistent text
|
|
|
|
SetTextColor(Hdc, PALETTERGB(0, 0, 255));
|
|
|
|
DrawText(Hdc, text, strlen(text), &RClient,
|
|
|
|
DT_CENTER | DT_VCENTER | DT_SINGLELINE);
|
|
|
|
}
|
|
|
|
#if 0
|
|
|
|
catch (...)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
// release the device context
|
|
|
|
ReleaseDC(HWnd, Hdc);
|
|
|
|
|
2005-05-07 21:24:31 +00:00
|
|
|
// validate the update area
|
2004-10-21 04:48:46 +00:00
|
|
|
ValidateRect(HWnd, &RUpdate);
|
|
|
|
}
|
|
|
|
// release the device context
|
|
|
|
ReleaseDC(HWnd, Hdc);
|
|
|
|
|
2005-05-07 21:24:31 +00:00
|
|
|
// validate the update area
|
2004-10-21 04:48:46 +00:00
|
|
|
ValidateRect(HWnd, &RUpdate);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case WM_DESTROY:
|
|
|
|
{
|
|
|
|
PostQuitMessage(0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return DefWindowProc(HWnd, Msg, WParam, LParam);
|
|
|
|
}
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|