首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

画图函数为什么不能画图啊 ,帮帮忙,

2012-02-24 
画图函数为什么不能画图啊 ,帮帮忙,在线等啊//Hdb3.cpp#include iostream.h#include string.h#include

画图函数为什么不能画图啊 ,帮帮忙,在线等啊
//Hdb3.cpp
#include <iostream.h>
#include <string.h>
#include "HDB3.h "
#include "windows.h "
int   Select=0;
int   choose=0;
int   x0=20;
int   y0=150;
int   len=0;
char   arg[200]={0};
void   Draw(HDC   hDC,   int   x0,int   y0,int   n,char   signal[]);
void   main(int   argc,char   *   argv[])
{
HWND   hwnd=FindWindow(NULL,   arg);   //找到程序运行窗口的句柄
HDC   hDC=GetDC(hwnd);   //通过窗口句柄得到该窗口的设备场境句柄
HPEN   hPen=CreatePen(PS_SOLID,   1,RGB(255,255,255));//生成绿色画笔
HPEN   hOldPen=(HPEN)SelectObject(hDC,hPen);//把画笔引入设备场境
char   DFileName[100];
cout < < "1.   编码               2.   译码3.退出 " < <endl;
cin> > Select;
switch   (Select)
{
case   1:
Code(signal);
n=strlen(signal);
arg[0]= '\ " ';
strcpy(arg+1,argv[0]);
len=int(strlen(arg));
arg[len]= '\ " ';
cout < <signal < <n < <endl;
Draw(hDC,x0,y0,n,signal);
break;
case   2:
cout < < "Please   input   dfilename! " < <endl;
cin> > DFileName;
cout < < "请输入待译码的类别:\n ";
cout < < "0,1,+,-,v,b构成请输入:1:\t0,1,+,-,构成请输入:0,默认为0.\n ";
cin> > choose;
if(choose==1)
Decode(DFileName);
else  
if(choose==0)
DecodeBase(DFileName);
else
cout < < "输入有误!\n ";
break;
case   3:exit(1);
default:
cout < < "输入错误!请重新输入!\n ";  
break;
}
}
void   Draw(HDC   hDC,   int   x0,int   y0,int   n,char   signal[])
{
int   dx=20;
int   dy=40;

for(int   i=1;i <=n;)
{
if(signal[i]== '1 '||signal[i]== 'v '||signal[i]== 'v ')
{
if(signal[i-1]== '+ ')
{
MoveToEx(hDC,x0,y0,NULL);//设置画线起点
LineTo(hDC,x0,y0-dy);//设置画线终点

MoveToEx(hDC,x0,y0-dy,NULL);
x0=x0+dx/2;
LineTo(hDC,x0,y0-dy);

MoveToEx(hDC,x0,y0-dy,NULL);
LineTo(hDC,x0,y0);

MoveToEx(hDC,x0,y0,NULL);  
x0   =   x0   +   dx/2;
LineTo(hDC,x0,y0);
}
if(signal[i-1]== '- ')
{
MoveToEx(hDC,x0,y0,NULL);//设置画线起点
LineTo(hDC,x0,y0+dy);//设置画线终点

MoveToEx(hDC,x0,y0+dy,NULL);
x0=x0+dx/2;
LineTo(hDC,x0,y0+dy);

MoveToEx(hDC,x0,y0+dy,NULL);
LineTo(hDC,x0,y0);

MoveToEx(hDC,x0,y0,NULL);  
x0   =   x0   +   dx/2;
LineTo(hDC,x0,y0);
}
}
if(signal[i]== '0 ')
{
MoveToEx(hDC,x0,y0,NULL);//设置画线起点
x0=x0+dx;
LineTo(hDC,x0,y0);//设置画线终点
}
if(x0> =600)
{
x0=20;
y0=y0+100;
}

i=i+2;
}
}
//Hdb3.h


#ifndef   HDB3_H
#define   HDB3_H
#include "string.h "
#include "stdlib.h "
#include "fstream.h "
#include "iostream.h "
#define   NO   100
int   count=0;
char   flagone= '- ';
char   flagv= '- ';
int   vfirst=0;
char   code[200];
char   signal[NO];
extern   int   n=0;


ofstream   fout;
void   Code(char   *signal)
{char   ch;
unsigned   int   length=0,i=0;
char   buf[100];
fout.open   ( "PostCode.txt ",ios::out   );
cout < < "请输入基带信号!\n ";
cin> > buf;
length=strlen(buf);
cout < < "信号长度: " < <length < <endl < < "基带信号为: ";
for(i=0;i <length;i++)
{
cout < <buf[i];
}
cout < <endl;
for(i=0;i <length;i++)
{ch=buf[i];
int   temp=0;
switch   (ch)
{
case   '1 ':
count=0;
if(flagone== '+ '   )
{
strcat(code, "-1 ");
flagone= '- ';
}
else
{
strcat(code, "+1 ");
flagone= '+ ';

}
break;
case   '0 ':
if(vfirst==0)
{
if(flagone== '+ ')
flagv= '- ';
else   flagv= '+ ';
vfirst++;
}
count=count+1;
strcat(code, "#0 ");
                  if(count==4)
  {
                          count=0;
  if(flagv== '+ ')
  {
temp=strlen(code);
code[temp-2]= '- ';
code[temp-1]= 'v ';
if(code[temp-10]== '+ ')
{
code[temp-8]= '- ';
code[temp-7]= 'b ';
}
  }
if(flagv== '- '   )
{
temp=strlen(code);
code[temp-2]= '+ ';
code[temp-1]= 'v ';

if(code[temp-10]== '- ')
{
code[temp-8]= '+ ';
code[temp-7]= 'b ';
}
}
if(flagv== '+ ')
flagv= '- ';
else  
flagv= '+ ';
if(flagv== '+ ')
flagone= '+ ';
else  
flagone= '- ';
  }
  break;
default:
cout < < "基带信号有误! " < <endl;
exit(0);
}
}
cout < < "编码结果为: ";
for(i=0;i <   strlen   (code);i++)
{
if(code[i]== '# ')
{
cout < <code[++i];
strcat(signal, "0 ");
fout < <code[i];
}
else
{
cout < <code[i];
if(code[i]== 'v ')
strcat(signal, "v ");
else   if(code[i]== 'b ')
strcat(signal, "b ");
else   if(code[i]== '+ ')
strcat(signal, "+ ");
else   if(code[i]== '- ')
strcat(signal, "- ");
else
strcat(signal, "1 ");
fout < <code[i];
}
}
cout < <endl;
cout < < "Code   Finished!\nResults   have   been   saved   in   PostCode.txt! " < <endl;
fout.close();
}
void   Decode(char   *FileName)
{
ifstream   fin;
char   ch;
fin.open   (FileName,ios::in|ios::nocreate);
if(!fin)
{
cout < < "Error(1): " < <FileName < < "cannot   open!\n ";
exit(1);
}
ch=fin.get();
while(!fin.eof())
{
if(ch== '1 ')
cout < < '1 ';


else
{
if(ch!= '+ '   &&   ch!= '- ')
cout < < '0 ';
}
ch=fin.get();
}
cout < <endl;
fin.close();
}
void   DecodeBase(char   *FileName)
{
ifstream   fin;
char   buf[100]= "   ";
char   code[200]= "   ";
char   ch;
int   i=0;
char   first= '+ ';
char   now= '+ ';
char   next= '- ';
fin.open   (FileName,ios::in|ios::nocreate);
if(!fin)
{
cout < < "Error(1): " < <FileName < < "cannot   open!\n ";
exit(1);
}
ch=fin.get();
while(!fin.eof())
{
buf[i++]=ch;
ch=fin.get();
}
i=strlen   (buf);
int   j=0,k=0;
while(j <i)
{

if(buf[j]== '0 ')
{
code[k]= '0 ';
}
else
{
if(buf[j]!= '1 ')
{
first=now;
now=next;
next=buf[j];
code[k]= '# ';
}
else
{
if(now==next)
{
code[k]= '0 ';
if(first!=next   &&   now==next)
code[k-4]= '0 ';
}
else  
code[k]= '1 ';
}


}
//cout < <code[k] < <endl;
j++;
k++;
}
j=strlen(code);
k=0;
while(k <j)
{
if(code[k]!= '# ')
cout < <code[k];
k++;
}
cout < <endl;
fin.close();
}
#endif   HDB3_H



[解决办法]
给分吧

热点排行