该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
//你要的白框框
#include
//#include
#include
//#pragma comment(lib,"winmm.lib")
//参数窗口句柄(窗口号),消息id,消息id的两个参数#define NUM 1000
#define TWOPI (2*3.14159)
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);//窗口过程int WINAPI WinMain(
HINSTANCE hInstacne,
HINSTANCE hPrevInstance,
PSTR szCmdLine,
int iCmdShow
)
{
static TCHAR szAppName[] = TEXT("SineWave");
HWND hwnd;
MSG msg;
WNDCLASS wndclass; wndclass.style = CS_HREDRAW | CS_VREDRAW;//框口风格
wndclass.lpfnWndProc = WndProc;//指向窗口过程
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstacne;
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION); //载入图图像
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); //载入鼠标
wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);//取得图形对象(台译物件),中文直译获得库存物件(白色刷)
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szAppName;
//RegisterClass为程序视窗注册视窗类别
if (!RegisterClass(&wndclass)) {
//显示讯息方块
MessageBox(NULL, TEXT("this program requires Windows nt"), szAppName, MB_ICONERROR);
return 0;
}
//创建视窗
hwnd = CreateWindow(szAppName,
TEXT("Sine Wave"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,CW_USEDEFAULT,
CW_USEDEFAULT,CW_USEDEFAULT,
NULL,NULL,hInstacne,NULL);
ShowWindow(hwnd, iCmdShow);//在屏幕上显示视窗
UpdateWindow(hwnd);//指示视窗进行自我更新
while (GetMessage(&msg, NULL, 0, 0)) {//不断的从讯息队列中取得讯息,中文常见翻译是从消息队列中取得消息
TranslateMessage(&msg);//信息转译
DispatchMessage(&msg);//将消息发送给视窗讯息处理程式
}
return msg.wParam;}
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
HDC hdc;
PAINTSTRUCT ps; //绘制结构体
// RECT rect;
static int cxClient, cyClient;
//缓冲区
POINT apt[NUM];
// TCHAR szBuffer[10];
int i;
switch (message) {
case WM_SIZE: cxClient = LOWORD(lParam);
cyClient = HIWORD(lParam); return 0;
case WM_PAINT://绘制消息
hdc = BeginPaint(hwnd, &ps);//开始绘制视窗
MoveToEx(hdc, 0, cyClient / 2,NULL);
LineTo(hdc, cxClient, cyClient / 2); for (i = 0;i
apt[i].x = i * cxClient / NUM;
apt[i].y = (int)(cyClient / 2 * (1 - sin(TWOPI*i / NUM)));
}
Polyline(hdc, apt, NUM);
EndPaint(hwnd, &ps);//结束绘制
return 0;
case WM_DESTROY:
PostQuitMessage(0);//加入退出讯息
return 0; }
//执行消息处理
return DefWindowProc(hwnd, message, wParam, lParam);
}