⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 123.txt

📁 画圆弧
💻 TXT
字号:
#include   <stdio.h>   
  #include   <windows.h>   
  LRESULT   MainWndProc(HWND,UINT,WPARAM,LPARAM);   
  BOOL   InitApplication(HINSTANCE);   
  void   InitInstance(HINSTANCE,INT);   
  const   char   lpMainClassName[]="MainWnd";   
  HINSTANCE   g_hInstance;   
  long   lngCount;   
  int   APIENTRY   WinMain(HINSTANCE   hInstance,   
    HINSTANCE   hPrevInstance,   
    LPSTR           lpCmdLine,   
    int               nCmdShow)   
  {   
  MSG   message;   
  if   (InitApplication(hInstance))   
  {   
  InitInstance(hInstance,nCmdShow);   
  }   
  while   (GetMessage(&message,NULL,0,0))   
  {   
    
  TranslateMessage(&message);   
  DispatchMessage(&message);   
  }   
  return   message.wParam;   
  }   
    
  BOOL   InitApplication(HINSTANCE   hIns)   
  {   
  WNDCLASSEX   wcx;   
    
  g_hInstance=hIns;   
  lngCount=0;   
  wcx.cbClsExtra=0;   
  wcx.cbSize=sizeof(wcx);   
  wcx.cbWndExtra=0;   
  wcx.hbrBackground=(HBRUSH)::CreateSolidBrush(RGB(100,250,150));   
  wcx.hCursor=LoadCursor(NULL,IDC_ARROW);   
  wcx.hIcon=LoadIcon(hIns,(LPCTSTR)IDI_APPLICATION);   
  wcx.hIconSm=NULL;   
  wcx.hInstance=hIns;   
  wcx.lpfnWndProc=(WNDPROC)MainWndProc;   
  wcx.lpszClassName=lpMainClassName;   
  wcx.lpszMenuName=(LPCTSTR)NULL;   
  wcx.style=CS_HREDRAW|CS_VREDRAW;   
  ::RegisterClassEx(&wcx);   
  return   TRUE;   
  }   
    
  void   InitInstance(HINSTANCE   hIns,int   nCmdShow)   
  {   
  HWND   hWnd;   
  hWnd=CreateWindow(lpMainClassName,"Test   Edit   Window!",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,5,300,400,NULL,NULL,hIns,NULL);   
  if   (IsWindow(hWnd))   
  {   
  ShowWindow(hWnd,nCmdShow);   
  UpdateWindow(hWnd);   
  }   
  }   
    
  //the   Bresenham   algorithm   
  void   lineBres(int   xa,int   ya,int   xb,int   yb,HDC   dc)   
  {   
  int   dx=abs(xa-xb);   
  int   dy=abs(ya-yb);   
  int   p=2*dy-dx;   
  int   twody=2*dy;   
  int   twodydx   =   2*(dy-dx);   
  int   x,y,xend;   
  if(xa>xb)   
  {   
  x=xb;   y=yb;   
  xend=xa;   
    
  }   
  else   
  {   
  x=xa;y=ya;   
  xend=xb;   
  }   
  SetPixel(dc,(x),(y),RGB(255,0,0));   
  while(x<xend)   
  {   
  x++;   
  if(p<0)   
  p+=twody;   
  else   
  {   
  y++;   
  p+=twodydx;   
  }   
  SetPixel(dc,(x),(y),RGB(255,0,0));   
  }   
    
  }   
  //The   DDA   algorithm   
  #define   ROUND(a)   ((int)a+0.5)   
  void   lineDDA(int   xa,   int   ya,int   xb,int   yb,HDC   dc)   
  {   
  int   dx=xb-xa,   dy=yb-ya;   
  int   steps,k;   
  float   xincrement   ,yincrement,x=xa,y=ya;   
  if(abs(dx)>abs(dy))   
  steps=abs(dx);   
  else   
  steps=abs(dy);   
  xincrement=dx/(float)steps;   
  yincrement=dy/(float)steps;   
  SetPixel(dc,ROUND(x),ROUND(y),RGB(255,0,0));   
  for(k=0;k<steps;k++)   
  {   
  x+=xincrement;   
  y+=yincrement;   
  SetPixel(dc,ROUND(x),ROUND(y),RGB(255,0,0));   
  }   
  }   
    
    
  LRESULT   MainWndProc(HWND   hWnd,UINT   msg,WPARAM   wParam,LPARAM   lParam)   
  {   
  switch(msg)   
  {   
  case   WM_PAINT:   
  {   
  PAINTSTRUCT   paint;   
  BeginPaint(hWnd,&paint);   
  LPCTSTR   strmsg="draw   line   by   Bresenham   algorithm   and   DDA   algorithm";   
  TextOut(paint.hdc,10,10,strmsg,strlen(strmsg));   
  lineBres(10,20,190,290,paint.hdc);   
  lineDDA(20,30,200,300,paint.hdc);   
  EndPaint(hWnd,&paint);   
  }   
  break;   
  case   WM_DESTROY:   
  PostQuitMessage(0);   
  break;   
  case   WM_CLOSE:   
  DestroyWindow(hWnd);   
  break;   
  default:   
  return   DefWindowProc(hWnd,msg,wParam,lParam);   
  }   
  return   0;   
  }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -