鱼C论坛

 找回密码
 立即注册
查看: 5167|回复: 8

c语言画图问题------高手进

 关闭 [复制链接]
发表于 2011-8-4 15:02:06 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
源代码如下:
#include <stdio.h>
#include <conio.h>
main()
{
char * str = "彩色文本";
clrscr();
window(5,1,20,4);
textcolor(YELLOW);
clrscr();
cprintf("'\n%s\n",str);
window(25,1,40,4);
textbackground(BLUE);
clrscr();
cprintf("\n%s\n",str);
window(45,1,60,4);
textattr(BLACK +(WHITE<<4));
clrscr();
cprintf("\n%s\n",str);
getch();
}

错误问题是:编译器说上述用的函数没有定义,我查看了一下include 下面有这个头文件。错误信息如下:


--------------------Configuration: 彩色文本 - Win32 Debug--------------------
Compiling...
彩色文本.cpp
d:\backup\我的文档\陈硕编程\c语言程序设计书上例子\彩色文本.cpp(6) : error C2065: 'clrscr' : undeclared identifier
d:\backup\我的文档\陈硕编程\c语言程序设计书上例子\彩色文本.cpp(7) : error C2065: 'window' : undeclared identifier
d:\backup\我的文档\陈硕编程\c语言程序设计书上例子\彩色文本.cpp(8) : error C2065: 'textcolor' : undeclared identifier
d:\backup\我的文档\陈硕编程\c语言程序设计书上例子\彩色文本.cpp(8) : error C2065: 'YELLOW' : undeclared identifier
d:\backup\我的文档\陈硕编程\c语言程序设计书上例子\彩色文本.cpp(12) : error C2065: 'textbackground' : undeclared identifier
d:\backup\我的文档\陈硕编程\c语言程序设计书上例子\彩色文本.cpp(12) : error C2065: 'BLUE' : undeclared identifier
d:\backup\我的文档\陈硕编程\c语言程序设计书上例子\彩色文本.cpp(16) : error C2065: 'textattr' : undeclared identifier
d:\backup\我的文档\陈硕编程\c语言程序设计书上例子\彩色文本.cpp(16) : error C2065: 'BLACK' : undeclared identifier
d:\backup\我的文档\陈硕编程\c语言程序设计书上例子\彩色文本.cpp(16) : error C2065: 'WHITE' : undeclared identifier
d:\backup\我的文档\陈硕编程\c语言程序设计书上例子\彩色文本.cpp(20) : warning C4508: 'main' : function should return a value; 'void' return type assumed
执行 cl.exe 时出错.
彩色文本.obj - 1 error(s), 0 warning(s)

小甲鱼最新课程 -> https://ilovefishc.com
发表于 2011-8-4 15:39:46 | 显示全部楼层
本帖最后由 soldier 于 2011-8-4 15:41 编辑

vc6.0不支持conio.h, 被抛弃了。tc中用的

system("CLS");它的头文件是#include<windows.h>。
替换clrscr() 其他的可以查一下msdn
小甲鱼最新课程 -> https://ilovefishc.com
 楼主| 发表于 2011-8-4 15:51:34 | 显示全部楼层
谢谢, 不过vc中没有相应的函数来取代上述那个头文件吗,我没用过tbc,能不换编译器尽量不换编译器的,忘高手在指点
小甲鱼最新课程 -> https://ilovefishc.com
 楼主| 发表于 2011-8-4 16:07:06 | 显示全部楼层

谢谢, 不过vc中没有相应的函数来取代上述那个头文件吗,我没用过tbc,能不换编译器尽量不换编译器的,忘高手在指点一下
小甲鱼最新课程 -> https://ilovefishc.com
发表于 2011-8-4 16:35:23 | 显示全部楼层
VC中没有相应的函数来取代上述那个头文件,你的图形处理是基于DOS的图形处理方式,已经被windows抛弃了,只有支持16位的C编译器(如turbo C)还支持这种方式.
小甲鱼最新课程 -> https://ilovefishc.com
 楼主| 发表于 2011-8-4 17:20:54 | 显示全部楼层
仰望天上的光 发表于 2011-8-4 16:35
VC中没有相应的函数来取代上述那个头文件,你的图形处理是基于DOS的图形处理方式,已经被windows抛弃了,只 ...

版主你好,很感激你的回答啊,我还想请教一下如何想用c语言研究函数,曲线,弧线相交情况,应该怎么办,需要用vc的控制台嘛,c语言怎样才能实现向java那样可以建一个窗口,绘图呢?迷茫中
小甲鱼最新课程 -> https://ilovefishc.com
发表于 2011-8-4 20:26:27 | 显示全部楼层
      如果在windows操作系统下绘图,要使用windows专门提供的一些绘图API函数(其实就是一些C语言的函数,只是之前我们没有学过而已),使用这些C函数编写的程序我们称为(WIN32编程呵呵,这个说法很不准确,但大概这样理解下也没什么问题)。WIN32编程比控制台编程难很多。
      如果你哪天不用windows转到linux操作系统下面,那你用win32 api写的程序就不能编译了,这个是C/C++与java比的缺点,它们的优点是速度快。
小甲鱼最新课程 -> https://ilovefishc.com
发表于 2011-8-4 20:29:17 | 显示全部楼层
给你个代码参考,在VC6下建立工程的时候要建立win32工程,不要建立console的工程
  1. /*--------------------------------------------------
  2.    CLOVER.C -- Clover Drawing Program Using Regions
  3.                (c) Charles Petzold, 1998
  4.   --------------------------------------------------*/

  5. #include <windows.h>
  6. #include <math.h>

  7. #define TWO_PI (2.0 * 3.14159)

  8. LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;

  9. int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
  10.                     PSTR szCmdLine, int iCmdShow)
  11. {
  12.      static TCHAR szAppName[] = TEXT ("Clover") ;
  13.      HWND         hwnd ;
  14.      MSG          msg ;
  15.      WNDCLASS     wndclass ;
  16.      
  17.      wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
  18.      wndclass.lpfnWndProc   = WndProc ;
  19.      wndclass.cbClsExtra    = 0 ;
  20.      wndclass.cbWndExtra    = 0 ;
  21.      wndclass.hInstance     = hInstance ;
  22.      wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION) ;
  23.      wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
  24.      wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
  25.      wndclass.lpszMenuName  = NULL ;
  26.      wndclass.lpszClassName = szAppName ;
  27.      
  28.      if (!RegisterClass (&wndclass))
  29.      {
  30.           MessageBox (NULL, TEXT ("This program requires Windows NT!"),
  31.                       szAppName, MB_ICONERROR) ;
  32.           return 0 ;
  33.      }
  34.      
  35.      hwnd = CreateWindow (szAppName, TEXT ("Draw a Clover"),
  36.                           WS_OVERLAPPEDWINDOW,
  37.                           CW_USEDEFAULT, CW_USEDEFAULT,
  38.                           CW_USEDEFAULT, CW_USEDEFAULT,
  39.                           NULL, NULL, hInstance, NULL) ;
  40.      
  41.      ShowWindow (hwnd, iCmdShow) ;
  42.      UpdateWindow (hwnd) ;
  43.      
  44.      while (GetMessage (&msg, NULL, 0, 0))
  45.      {
  46.           TranslateMessage (&msg) ;
  47.           DispatchMessage (&msg) ;
  48.      }
  49.      return msg.wParam ;
  50. }

  51. LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
  52. {
  53.      static HRGN hRgnClip ;
  54.      static int  cxClient, cyClient ;
  55.      double      fAngle, fRadius ;
  56.      HCURSOR     hCursor ;
  57.      HDC         hdc ;
  58.      HRGN        hRgnTemp[6] ;
  59.      int         i ;
  60.      PAINTSTRUCT ps ;
  61.      
  62.      switch (iMsg)
  63.      {
  64.      case WM_SIZE:
  65.           cxClient = LOWORD (lParam) ;
  66.           cyClient = HIWORD (lParam) ;
  67.          
  68.           hCursor = SetCursor (LoadCursor (NULL, IDC_WAIT)) ;
  69.           ShowCursor (TRUE) ;
  70.          
  71.           if (hRgnClip)
  72.                DeleteObject (hRgnClip) ;
  73.          
  74.           hRgnTemp[0] = CreateEllipticRgn (0, cyClient / 3,
  75.                                            cxClient / 2, 2 * cyClient / 3) ;
  76.           hRgnTemp[1] = CreateEllipticRgn (cxClient / 2, cyClient / 3,
  77.                                            cxClient, 2 * cyClient / 3) ;
  78.           hRgnTemp[2] = CreateEllipticRgn (cxClient / 3, 0,
  79.                                            2 * cxClient / 3, cyClient / 2) ;
  80.           hRgnTemp[3] = CreateEllipticRgn (cxClient / 3, cyClient / 2,
  81.                                            2 * cxClient / 3, cyClient) ;
  82.           hRgnTemp[4] = CreateRectRgn (0, 0, 1, 1) ;
  83.           hRgnTemp[5] = CreateRectRgn (0, 0, 1, 1) ;
  84.           hRgnClip    = CreateRectRgn (0, 0, 1, 1) ;
  85.          
  86.           CombineRgn (hRgnTemp[4], hRgnTemp[0], hRgnTemp[1], RGN_OR) ;
  87.           CombineRgn (hRgnTemp[5], hRgnTemp[2], hRgnTemp[3], RGN_OR) ;
  88.           CombineRgn (hRgnClip,    hRgnTemp[4], hRgnTemp[5], RGN_XOR) ;
  89.          
  90.           for (i = 0 ; i < 6 ; i++)
  91.                DeleteObject (hRgnTemp[i]) ;
  92.          
  93.           SetCursor (hCursor) ;
  94.           ShowCursor (FALSE) ;
  95.           return 0 ;
  96.          
  97.      case WM_PAINT:
  98.           hdc = BeginPaint (hwnd, &ps) ;
  99.          
  100.           SetViewportOrgEx (hdc, cxClient / 2, cyClient / 2, NULL) ;
  101.           SelectClipRgn (hdc, hRgnClip) ;
  102.          
  103.           fRadius = _hypot (cxClient / 2.0, cyClient / 2.0) ;
  104.          
  105.           for (fAngle = 0.0 ; fAngle < TWO_PI ; fAngle += TWO_PI / 360)
  106.           {
  107.                MoveToEx (hdc, 0, 0, NULL) ;
  108.                LineTo (hdc, (int) ( fRadius * cos (fAngle) + 0.5),
  109.                             (int) (-fRadius * sin (fAngle) + 0.5)) ;
  110.           }
  111.           EndPaint (hwnd, &ps) ;
  112.           return 0 ;
  113.          
  114.      case WM_DESTROY:
  115.           DeleteObject (hRgnClip) ;
  116.           PostQuitMessage (0) ;
  117.           return 0 ;
  118.      }
  119.      return DefWindowProc (hwnd, iMsg, wParam, lParam) ;
  120. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
 楼主| 发表于 2011-8-5 20:03:02 | 显示全部楼层
仰望天上的光 发表于 2011-8-4 20:29
给你个代码参考,在VC6下建立工程的时候要建立win32工程,不要建立console的工程

十分感谢 版主的帮助
小甲鱼最新课程 -> https://ilovefishc.com
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-11-7 11:12

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表