|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
初始窗口是正确的 但是一改变窗口大小 结果就不对了 没有重绘 上一次的图形和新的图形都存在
而视频里,随便移动窗口图形都是重绘一下
#include "stdio.h"
#include <windows.h>
#include <strsafe.h>
# include <math.h>
#define NUM 1000
#define twopi (2*3.14159)
LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) {
HDC hdc;
PAINTSTRUCT ps;
//RECT rect;
static int cxclient, cyclient;
int i;
POINT apt[NUM];
switch (Message) {
case WM_SIZE: {
cxclient = LOWORD(lParam);
cyclient = HIWORD(lParam);
break;
}
case WM_PAINT: {
hdc = BeginPaint(hwnd, &ps);
MoveToEx(hdc, 0, cyclient/2, NULL);
LineTo(hdc, cxclient, cyclient/2);
for (i = 0; i < NUM; i++)
{
apt[i].x = i * cxclient / NUM;
apt.y = (int)cyclient/2 * (1- sin(twopi * i / NUM));
}
PolylineTo(hdc,apt,NUM);
EndPaint(hwnd, &ps);
break;
}
case WM_DESTROY: {
PostQuitMessage(0);
break;
}
default:
return DefWindowProc(hwnd, Message, wParam, lParam);
}
return 0;
}
/* The 'main' function of Win32 GUI programs: this is where execution starts */
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
WNDCLASSEX wc; /* A properties struct of our window */
HWND hwnd; /* A 'HANDLE', hence the H, or a pointer to our window */
MSG msg; /* A temporary location for all messages */
/* zero out the struct and set the stuff we want to modify */
memset(&wc, 0, sizeof(wc));
wc.cbSize = sizeof(WNDCLASSEX);
wc.lpfnWndProc = WndProc; /* This is where we will send messages to */
wc.hInstance = hInstance;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
/* White, COLOR_WINDOW is just a #define for a system color, try Ctrl+Clicking it */
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wc.lpszClassName = (LPCWSTR)"WindowClass";
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); /* Load a standard icon */
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION); /* use the name "A" to use the project icon */
if (!RegisterClassEx(&wc)) {
MessageBox(NULL, (LPCWSTR)"Window Registration Failed!", (LPCWSTR) "Error!", MB_ICONEXCLAMATION | MB_OK);
return 0;
}
hwnd = CreateWindowEx(WS_EX_CLIENTEDGE, (LPCWSTR) "WindowClass", TEXT("paint"),
WS_OVERLAPPEDWINDOW | WS_VISIBLE ,
CW_USEDEFAULT, /* x */
CW_USEDEFAULT, /* y */
800, /* width */
480, /* height */
NULL, NULL, hInstance, NULL);
if (hwnd == NULL) {
MessageBox(NULL, (LPCWSTR)"Window Creation Failed!", (LPCWSTR)"Error!", MB_ICONEXCLAMATION | MB_OK);
return 0;
}
/*
This is the heart of our program where all input is processed and
sent to WndProc. Note that GetMessage blocks code flow until it receives something, so
this loop will not produce unreasonably high CPU usage
*/
while (GetMessage(&msg, NULL, 0, 0) > 0) { /* If no error is received... */
TranslateMessage(&msg); /* Translate key codes to chars if present */
DispatchMessage(&msg); /* Send it to WndProc */
}
return msg.wParam;
}[/i] |
|