📄 testgdi.cpp
字号:
/**********************************************************************
#
# Filename: testgdi.cpp
#
# Description:
#
# THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
# ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
# PARTICULAR PURPOSE.
#
# Use of this source code is subject to the terms of the Cirrus end-user
# license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
# If you did not accept the terms of the EULA, you are not authorized to
# use this source code. For a copy of the EULA, please see the
# EULA.RTF on your install media.
#
# Copyright(c) Cirrus Logic Corporation 2005, All Rights Reserved
#
#**********************************************************************/
#include <windows.h>
#include <string.h>
#include "resource.h"
#define MAX_PERF_LOOP 100000
#ifndef DBGLOG
#define DBGLOG(S)
#endif
#ifndef ASSERT
#define ASSERT(F)
#endif
#ifndef VERIFY
#define VERIFY(S) if(!(S)) ASSERT(0); else
#endif
#ifdef DEBUG
DBGPARAM dpCurSettings = { TEXT("TestGdi"), {
TEXT("Undefined"), TEXT("Undefined"), TEXT("Undefined"), TEXT("Undefined"),
TEXT("Undefined"), TEXT("Undefined"), TEXT("Undefined"), TEXT("Undefined"),
TEXT("Undefined"), TEXT("Undefined"), TEXT("Undefined"), TEXT("Undefined"),
TEXT("Undefined"), TEXT("Undefined"), TEXT("Undefined"), TEXT("Undefined") },
0x00000000 };
#endif
TCHAR v_wszAppName[] = TEXT("TestGDI");
TCHAR v_wszTitle[] = TEXT("TestGDI");
TCHAR v_wszPegasus1[] = TEXT("Press 'P' to begin");
TCHAR v_wszPegasus2[] = TEXT("Performance Measurement");
TCHAR v_wszPegasus3[128];
TCHAR v_wszPegasus4[] = TEXT("Measuring Performance for");
TCHAR v_wszPegasus5[128] = TEXT("");
TCHAR v_wszPegasus6[128] = TEXT("");
HWND v_hWndMain = NULL;
HINSTANCE v_hInst;
int v_nGdiOperations = 1;
int v_nWidthDisplay;
int v_nHeightDisplay;
int v_peg_text_y1;
int v_peg_text_y2;
#define NUM_BRUSHES 256
extern "C"
void
DisplayText(
HDC hdc,
LPWSTR lpwStr,
int x,
int y,
int yoffset
);
extern "C"
void
DisplayMeasuringText(
HDC hdc,
int n,
BOOL *pfBlinking
);
extern "C"
LRESULT CALLBACK
WndProc (
HWND hWnd,
UINT message,
WPARAM uParam,
LPARAM lParam
);
extern "C"
BOOL
PerfDlgProc(
HWND hWnd,
UINT msg,
WPARAM wParam,
LPARAM lParam
);
extern "C"
BOOL
CenterWindow(
HWND hwndChild,
HWND hwndParent
);
static UINT32
rand(UINT32 max)
{
static UINT32 randseed = 0xed0000ed;
register INT32 x, hi, lo, t;
/*
* Compute x[n + 1] = (7^5 * x[n]) mod (2^31 - 1).
* From "Random number generators: good ones are hard to find",
* Park and Miller, Communications of the ACM, vol. 31, no. 10,
* October 1988, p. 1195.
*/
x = randseed;
hi = x / 127773;
lo = x % 127773;
t = 16807 * lo - 2836 * hi;
if (t <= 0)
t += 0x7fffffff;
randseed = t;
return (t % max);
}
#define MIN(X,Y) (((X) < (Y)) ? (X) : (Y))
#define MAX(X,Y) (((X) > (Y)) ? (X) : (Y))
static void
randomize_rect(RECT *pRect)
{
LONG u,v;
u = rand(320);
v = rand(320);
pRect->left = MIN(u,v);
pRect->right = MAX(u,v);
u = rand(240);
v = rand(240);
pRect->top = MIN(u,v);
pRect->bottom = MAX(u,v);
return;
}
extern "C"
int
WINAPI
WinMain (
HINSTANCE hInstance,
HINSTANCE hPreviousInstance,
LPWSTR pszCommandLine,
int nCommandShow
)
{
WNDCLASSW wc;
MSG msg;
if(hPreviousInstance){
return FALSE;
}
v_hInst = hInstance;
if(pszCommandLine && *pszCommandLine){
v_nGdiOperations = _wtol(pszCommandLine);
if(v_nGdiOperations < 0){
v_nGdiOperations = -v_nGdiOperations;
}
if(v_nGdiOperations > MAX_PERF_LOOP){
v_nGdiOperations = MAX_PERF_LOOP;
}
}
wc.style = 0;
wc.lpfnWndProc = (WNDPROC) WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = sizeof(DWORD);
wc.hInstance = hInstance;
wc.hIcon = 0;
wc.hCursor = 0;
wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = 0;
wc.lpszClassName = v_wszAppName;
if ( RegisterClassW(&wc) == FALSE ) {
OutputDebugStringW(TEXT("RegisterClassW Failed\n"));
return(FALSE);
}
v_hWndMain = CreateWindowExW(0, v_wszAppName, v_wszTitle,
WS_OVERLAPPED | WS_VISIBLE | WS_SYSMENU,
0, 0, 400, 300,
NULL, NULL, hInstance, NULL);
if (v_hWndMain == 0){
OutputDebugStringW(TEXT("CreateWindowExW Failed\n"));
return(FALSE);
}
UpdateWindow(v_hWndMain);
ShowWindow(v_hWndMain, nCommandShow);
while ( GetMessage(&msg, NULL, 0, 0) != FALSE ) {
DispatchMessage(&msg);
}
return(TRUE);
}
extern "C"
LRESULT CALLBACK
WndProc (
HWND hWnd,
UINT message,
WPARAM uParam,
LPARAM lParam
)
{
static BOOL fInit = TRUE;
static int nTest = 0;
static HPEN hpnDashed = NULL;
static HRGN hrgn = NULL;
static HBRUSH rghbr[NUM_BRUSHES];
static int peg_text_x2;
static HPEN hpnSolid;
static BOOL fNeedToDisplayText = TRUE;
static BOOL fBlinking;
static HRGN hrgnText1 = NULL;
static HRGN hrgnText2 = NULL;
static RECT rect1;
static RECT rect2;
HBRUSH oldhbr;
HRGN hrgn1,hrgn2;
HPEN oldhpn;
TEXTMETRIC tm;
LOGPEN lgpn;
HDC hdc;
RECT rect;
DWORD dwTime;
int i;
switch (message) {
case WM_CREATE :
//
// Create four brushes
//
for (i = 0; i < NUM_BRUSHES; i++) {
rghbr[i] = CreateSolidBrush(RGB(rand(256), rand(256),
rand(256)));
}
//
// Create a dashed pen
//
lgpn.lopnStyle = PS_DASH;
lgpn.lopnWidth.x = 1;
lgpn.lopnColor = 0x03;
hpnDashed = CreatePenIndirect(&lgpn);
hpnSolid = (HPEN) GetStockObject(BLACK_PEN);
//
// Initiate the drawing sequences
//
// Note: We use a timer here with a timeout 0
// so that while we are busy drawing, the system
// can still carry out all other operations
// (WM_TIMER is the lowest priority message).
// Otherwise, since WM_PAINT is the second lowest
// priority message, it will yield to
// anything bug WM_TIMER and thus when we
// move the window, the window, including the NC area,
// does not get re-painted.
//
SetTimer(hWnd, 1, 0, NULL);
break;
case WM_KEYDOWN:
if(uParam == 'P'){
//
// Move window back first
//
SetWindowLong(hWnd, GWL_STYLE, WS_BORDER | WS_VISIBLE);
SetWindowPos(hWnd,
NULL,
0, 0,
0, 0,
SWP_NOSIZE | SWP_NOZORDER);
if(DialogBox(v_hInst,
MAKEINTRESOURCE(DLG_PERF),
hWnd,
(DLGPROC)PerfDlgProc) == 1){
v_nGdiOperations = _wtol(v_wszPegasus3);
if(v_nGdiOperations < 0){
v_nGdiOperations = -v_nGdiOperations;
} else if(v_nGdiOperations == 0){
v_nGdiOperations = 1;
}
if(v_nGdiOperations > MAX_PERF_LOOP){
v_nGdiOperations = MAX_PERF_LOOP;
}
}
#if 0
} else if(uParam == 'Q'){
SetTimer(hWnd, 1, 0, NULL);
#endif
} else if(uParam == 'X'){
PostMessage(hWnd, WM_CLOSE, 0, 0);
}
break;
case WM_WINDOWPOSCHANGED:
hdc = GetDC(hWnd);
GetClientRect(hWnd, &rect);
v_nWidthDisplay = rect.right - rect.left;
v_nHeightDisplay = rect.bottom - rect.top;
peg_text_x2 = v_nWidthDisplay / 5 * 3;
rect1.left = 0;
rect1.top = 0;
rect1.right = peg_text_x2;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -