ddrawwrapper.cpp
来自「VC++高级编程技巧与示例」· C++ 代码 · 共 148 行
CPP
148 行
// DDrawWrapper.cpp : Defines the entry point for the application.
//
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
//-----------------------------------------------------------------------------
// Include files
//-----------------------------------------------------------------------------
#include <windows.h>
#include <ddraw.h>
#include <stdio.h>
#include <stdarg.h>
#include "stdafx.h"
#include "HDirectDraw.h"
#define TIMER_ID 1
#define TIMER_RATE 500
#define CX 320
#define CY 240
#define LEN 100
BOOL g_bActive=FALSE;
LPCTSTR szMsg ="Press the fucked F12!";
LPCTSTR szFrontMsg="Front!";
LPCTSTR szBackMsg ="Back!";
CDirectDraw DDraw;
UINT x[4]={
CX-LEN,CX,CX+LEN,CX
};
UINT y[4]={
CY,CY-LEN,CY,CY+LEN
};
static void DeleteAllObjects()
{
DDraw.CloseDDraw();
}
void UpdateFrame(HWND hWnd)
{
static BYTE phase = 0;
static BYTE count = 0;
static BYTE bc = 0;
DDraw.ClearBackBuffer();
DDraw.GetDC(DDraw.lpDDSBack);
DDraw.SetTextColor(RGB(255,255,0));
DDraw.SetBkColor(RGB(0,0,255));
if(phase==0)
{
DDraw.TextOut(400,20,"Prime");
phase=1;
}
else
{
DDraw.TextOut(400,20,"Back");
phase=0;
}
DDraw.TextOut(320,240,"Press the F12 key!");
//画线:
HPEN op;
HPEN hp=::CreatePen(PS_SOLID,1,RGB(255,255,0));
op=(HPEN)::SelectObject(DDraw.hDC,hp);
DDraw.MoveTo(CX,CY);
::LineTo(DDraw.hDC,x[count],y[count]);
::SelectObject(DDraw.hDC,op);
::DeleteObject(hp);
count++;
if(count==4) count=0;
DDraw.ReleaseDC();
}
long FAR PASCAL
WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_ACTIVATEAPP:
// Pause if minimized or not the top window
g_bActive = (wParam == WA_ACTIVE) || (wParam == WA_CLICKACTIVE);
return 0L;
case WM_DESTROY:
// Clean up and close the app
DeleteAllObjects();
PostQuitMessage(0);
return 0L;
case WM_KEYDOWN:
// Handle any non-accelerated key commands
switch (wParam)
{
case VK_ESCAPE:
case VK_F12:
PostMessage(hWnd, WM_CLOSE, 0, 0);
return 0L;
}
break;
case WM_SETCURSOR:
// Turn off the cursor since this is a full-screen app
SetCursor(NULL);
return TRUE;
case WM_TIMER:
// Update and flip surfaces
if (g_bActive && TIMER_ID == wParam)
{
UpdateFrame(hWnd);
DDraw.Flip();
}
break;
}
return DefWindowProc(hWnd, message, wParam, lParam);
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
MSG msg;
if (DDraw.CreateDDrawWnd(hInstance, nCmdShow,WindowProc) != TRUE)
{
return FALSE;
}
if(DDraw.InitDDraw(640,480,32)!=TRUE)
{
return FALSE;
}
if(DDraw.SetTimer(1,1)!=TRUE)
{
return FALSE;
}
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?