如题 ,最好举个例子
先谢谢各位前辈了。
先谢谢各位前辈了。
解决方案 »
- VC++或者MFC中有没有提供接口将监控视频流封装为AVI格式的视频?
- 求助!!!Windows和Linux下的语音对讲功能
- 在vc2005使用_sleek处理文件发生Expression : (fh >=0 &&(unsigned)fh < (unsigned)_nhandle),求高手指教!!多谢
- GetModuleHandle 总是返回null(大家可能经常遇到)
- 关于文件截取的问题
- MFC的现状和未来!!!大家快来讨论!!!
- 如何在vc中定义全局变量。
- <<虚拟机的设计与实现-C/C++>>的光盘哪有下载的?
- 请教如何手动将多线程中的不同线程分配到不同核上!谢谢
- 这句话是什么意思!!!!
- 散分二 还差1871分升星星
- 懂API的前辈们,帮忙看个程序???
能帮忙改改吗#include<windows.h>
#include<stdio.h>
#include<Wingdi.h>
#include<math.h>
#define SEGMENTS 500
#define PI 3.1415926
#define ID_TIMER 1LRESULT CALLBACK WinProc(HWND hwnd,UINT message,WPARAM wparam,LPARAM lparam);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInst,LPSTR lpszCmdLine,int nCmdShow)
{
WNDCLASS wndclass;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclass.hInstance=hInstance;
wndclass.lpfnWndProc=WinProc;
wndclass.lpszClassName="第四章";
wndclass.lpszMenuName=NULL;
wndclass.style=CS_HREDRAW|CS_VREDRAW;
if(!RegisterClass(&wndclass))
{
MessageBeep(0);
return FALSE;
}
HWND hwnd;
hwnd=CreateWindow(
"第四章",
"习题4—6",
WS_OVERLAPPEDWINDOW,
100,
100,
400,
500,
NULL,
NULL,
hInstance,
NULL
); ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd); MSG msg;
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK WinProc(HWND hwnd,UINT message,WPARAM wparam,LPARAM lparam)
{
HDC hdc;
PAINTSTRUCT ps;
HBRUSH hb;
HPEN pen;
POINT po[SEGMENTS];
int nWidth,nHeigh,i;
static j=0;
switch(message)
{
case WM_CREATE:
SetTimer (hwnd, ID_TIMER, 200000, NULL) ;
return 0 ; case WM_TIMER :
MessageBeep (-1) ;
// j++;
InvalidateRect (hwnd, NULL, FALSE) ;
return 0 ;
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
RECT rect;
pen=CreatePen(PS_SOLID,10,RGB(255,0,0));
hb=CreateSolidBrush(RGB(0,255,0));
GetClientRect(hwnd,&rect); //获得客户区的大小
nWidth=rect.right-rect.left;
nHeigh=rect.bottom-rect.top;
for(i=0;i<SEGMENTS;i++)
{
po[i].x=(i*nWidth)/SEGMENTS;
po[i].y=(int)((nHeigh/2)*(1-(sin((2*PI*i)/SEGMENTS))));
} //绘制各个正弦曲线点
SelectObject(hdc,pen);
Polyline(hdc,po,SEGMENTS); //将各个孤立点连接起来
// while(j<SEGMENTS)
// {
for(i=0;i<SEGMENTS;i++)
{
SetROP2(hdc,R2_XORPEN);//使用XORPEN在上次的位置重新画一次就是擦掉
SelectObject(hdc,hb);
Ellipse(hdc,po[i].x-50,po[i].y-50,po[i].x+50,po[i].y+50);
}
// }
EndPaint (hwnd, &ps) ;
DeleteObject (pen) ;
DeleteObject (hb) ;
break;
case WM_DESTROY:
KillTimer (hwnd, ID_TIMER) ;
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,message,wparam,lparam);
}
return 0;
}
#include<stdio.h>
#include<Wingdi.h>
#include<math.h>
#define SEGMENTS 500
#define PI 3.1415926
#define ID_TIMER 1int g_i=0;LRESULT CALLBACK WinProc(HWND hwnd,UINT message,WPARAM wparam,LPARAM lparam);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInst,LPSTR lpszCmdLine,int nCmdShow)
{
WNDCLASS wndclass;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclass.hInstance=hInstance;
wndclass.lpfnWndProc=WinProc;
wndclass.lpszClassName="第四章";
wndclass.lpszMenuName=NULL;
wndclass.style=CS_HREDRAW|CS_VREDRAW;
if(!RegisterClass(&wndclass))
{
MessageBeep(0xffffffff);
return FALSE;
}
HWND hwnd;
hwnd=CreateWindow(
"第四章",
"习题4—6",
WS_OVERLAPPEDWINDOW,
100,
100,
400,
500,
NULL,
NULL,
hInstance,
NULL
);
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);
MSG msg;
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK WinProc(HWND hwnd,UINT message,WPARAM wparam,LPARAM lparam)
{
HDC hdc;
PAINTSTRUCT ps;
HBRUSH hb;
HPEN pen;
POINT po[SEGMENTS];
int nWidth,nHeigh,i;
static j=0;
switch(message)
{
case WM_CREATE:
SetTimer (hwnd, ID_TIMER, 50, NULL) ;
return 0 ;
case WM_TIMER :
//MessageBeep (-1) ;
// j++;
InvalidateRect (hwnd,0,1) ; return 0 ;
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
RECT rect;
pen=CreatePen(PS_SOLID,10,RGB(255,0,0));
hb=CreateSolidBrush(RGB(0,255,0));
GetClientRect(hwnd,&rect); //获得客户区的大小
nWidth=rect.right-rect.left;
nHeigh=rect.bottom-rect.top;
for(i=0;i<SEGMENTS;i++)
{
po[i].x=(i*nWidth)/SEGMENTS;
po[i].y=(int)((nHeigh/2)*(1-(sin((2*PI*i)/SEGMENTS))));
} //绘制各个正弦曲线点 SelectObject(hdc,pen);
Polyline(hdc,po,SEGMENTS); //将各个孤立点连接起来
// while(j<SEGMENTS)
// {
// for(i=0;i<SEGMENTS;i++)
// {
// SetROP2(hdc,R2_XORPEN);//使用XORPEN在上次的位置重新画一次就是擦掉
SelectObject(hdc,hb);
Ellipse(hdc,po[g_i].x-50,po[g_i].y-50,po[g_i].x+50,po[g_i].y+50);
// }
// }
g_i++;
if (g_i>=SEGMENTS)
{
g_i = 0;
}
EndPaint (hwnd, &ps) ;
DeleteObject (pen) ;
DeleteObject (hb) ;
break;
case WM_DESTROY:
KillTimer (hwnd, ID_TIMER) ;
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,message,wparam,lparam);
}
return 0;
}
楼主,用你的代码改的,可以看到移动的了,不过擦除是会闪的,学一下用双缓冲或有选择性的擦除吧.