如题 ,最好举个例子
先谢谢各位前辈了。

解决方案 »

  1.   

    这个GDI里有一很多API的,可以先画好正弦线,然后以正弦线的坐标为圆心画圆就行了的啊,要实现运动的效果,最好加个定时器,就是过多久画下一下圆,同是擦掉上一次画的!
      

  2.   

    使用XORPEN在上次的位置重新画一次就是擦掉
      

  3.   

    能具体点吗   能把函数原型 写下吗  为什么我在MSDN里找不到这个函数
      

  4.   


    能帮忙改改吗#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;
    }
      

  5.   

    #include "StdAfx.h"#include<windows.h>
    #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;
    }
    楼主,用你的代码改的,可以看到移动的了,不过擦除是会闪的,学一下用双缓冲或有选择性的擦除吧.
      

  6.   

    呵呵,DEMO出来后,慢慢地改,改好看一些,就多学一些的了.