重绘解决了 但是闪烁怎么消除 直接上cpp 代码了
-----
程序代码:
///////////////////////////////////////
// Program Name: Cartoon.cpp
// Programmer: YRJD
// Description: Several Cartoon transform
//////////////////////////////////////////
#define STRICT
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <Windowsx.h>
#pragma warning(disable: 4068)
#pragma warning (disable:4100) // Please think about these two sentences
#pragma hdrstop
#include "CartoonOne.h"
// Global variables
static char szAppName[] = "CartoonSeries"; // Why use 'static'?
static HINSTANCE hInstance;
static HANDLE hResource;
//*********************
// Initialization
//*********************
//---------------------------
// WinMain is the entry point
//---------------------------
#pragma argsused
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInstance,
LPSTR lpszCmdParam, int nCmdShow )
{
MSG msg;
if (!hPrevInstance) // In fact this sentence may be omitted
if (! Register(hInst)) // Registered Window Class
{
return FALSE;
}
if (!Create(hInst, nCmdShow)) // Create a window instance
{
return FALSE;
}
while (GetMessage(&msg, NULL, 0, 0)) // Message circulation
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
////////////////////////////////////
// Register the window
////////////////////////////////////
#pragma argsused
BOOL Register(HINSTANCE hInst)
{
WNDCLASS wndclass;
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.hInstance = hInst;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hIcon = LoadIcon(hInst, "Icon");
wndclass.hCursor = LoadCursor(hInst, "Cursor");
wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szAppName; // Notice this 'szAppName'
return (RegisterClass(&wndclass)); // The function here is very important
}
////////////////////////////////////
// Create the Window and show it.
////////////////////////////////////
#pragma argsused
BOOL Create(HINSTANCE hInst, int nCmdShow)
{
hInstance = hInst; // Connect with the global instance
HWND hWnd = CreateWindowEx(0, szAppName, "First Cartoon Demo",
WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0,
CW_USEDEFAULT, 0, NULL, NULL, hInst, NULL);
if (hWnd == NULL)
{
return FALSE;
}
ShowWindow(hWnd, nCmdShow); //...
UpdateWindow(hWnd); //...
return TRUE;
}
//*********************
// Implementation
//*********************
//--------------------------------
// The Window proc help control
// the program when it is running
//--------------------------------
LRESULT CALLBACK WndProc(HWND hWnd, UINT message,
WPARAM wParam, LPARAM lParam)
{
switch (message)
{
HANDLE_MSG(hWnd, WM_CREATE, yrjd_OnCreate);
HANDLE_MSG(hWnd, WM_DESTROY, yrjd_OnDestroy);
HANDLE_MSG(hWnd, WM_PAINT, yrjd_OnPaint);
HANDLE_MSG(hWnd, WM_TIMER, yrjd_OnTimer);
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
}
// Create Window
#define ID_TEXT 1
#define ID_DRAW 2
#pragma argsused
BOOL yrjd_OnCreate(HWND hWnd, CREATESTRUCT FAR *lpCreateStruct)
// Please make the 'CREATESTRUCT FAR' clear, what is it means
{
hResource = LoadResource(hInstance, FindResource(hInstance,
"love", "CUSTOM"));
/* hWndEdit1 = CreateWindow("Edit", NULL, WS_CHILD |
WS_VISIBLE | WS_BORDER | ES_LEFT | ES_MULTILINE
, 0, 0, 500, 350,
hWnd, HMENU(ID_TEXT), hInstance, NULL);*/
hWndEdit2 = CreateWindow("Static", "Look right! There is the Cartoon!", WS_CHILD |
WS_VISIBLE | WS_BORDER, 40, 400, 100, 60,
hWnd, HMENU(-1), hInstance, NULL);
SetTimer(hWnd, 1, 100, NULL);
return TRUE;
}
// Destroy Window
#pragma argsused
void yrjd_OnDestroy(HWND hWnd)
{
DeleteBitmap(hResource);
PostQuitMessage(0);
}
// Paint the Bitmap and the text
#pragma argsused
void yrjd_OnPaint(HWND hWnd)
{
PAINTSTRUCT ps;
RECT rt;
char far *love;
// HBRUSH hBrush;
POINT pt[8] = {240, 410, 340, 410, 340, 370, 400, 430, 340, 490,
340, 450, 240, 450, 240, 410};
HDC PaintDC = BeginPaint(hWnd, &ps);
//HDC PaintBuffer = CreateCompatibleDC(PaintDC);
SetBkMode(PaintDC, 0);
love = (char far *)LockResource(hResource);
GetClientRect(hWnd, &rt);
rt.left +=30;
rt.top += 30;
DrawText(PaintDC, love, -1, &rt, DT_EXTERNALLEADING | DT_LEFT);
GlobalUnlock(hResource);
SelectObject(PaintDC,GetStockObject(BLACK_BRUSH));
//MoveToEx(PaintDC1, pt[0].x, pt[0].y, NULL); // Polygon has the same function
//Polyline(PaintDC1, pt, 8);
SetPolyFillMode(PaintDC, ALTERNATE);
Polygon(PaintDC, pt, 8);
if (choice == 1)
Ellipse(PaintDC, 550, 220, 650, 320);
else if (choice == 2)
Ellipse(PaintDC, 550, 230, 650, 380);
else if (choice == 4)
Rectangle(PaintDC, 550, 220, 650, 320);
else if (choice == 5)
Rectangle(PaintDC, 550, 230, 650, 380);
else if (choice == 3)
{
POINT ptTri[4] = {600, 220, 650, 320, 550, 320, 600, 220};
Polyline(PaintDC, ptTri, 4);
}
else
TextOut(PaintDC, 600, 310, "hahahaha!", 9);
//BitBlt(PaintDC, 0, 0, 1000, 600, PaintBuffer, 0, 0, SRCCOPY);
EndPaint(hWnd, &ps);
}
void yrjd_OnTimer(HWND hWnd, UINT nIDEvent)
{
choice = (choice + 1) % 6;
InvalidateRect(hWnd, NULL, TRUE);
}
怎么实现双缓冲啊 大牛能在我这个实例上指导下吗
[
本帖最后由 有容就大 于 2012-5-3 21:32 编辑 ]