当前位置:首页 » 操作系统 » c项目开发源码

c项目开发源码

发布时间: 2023-09-10 06:32:35

A. 求几个比较有趣,简单的C语言源代码 小白自己敲着练一下手感

最简单的模拟计时器:

#include<stdio.h>

#include<conio.h>

#include<windows.h>

int m=0,s=0,ms=0; //m是分 s是秒 ms是毫秒

//以下是5个自编函数

void csh( ); //初始化界面

void yinc(int x,int y); //隐藏光标的函数(y值设为0就会隐藏)

void jishi( ); //计时器运行(每100毫秒变化一次)

void Color (short x, short y); //设定颜色的函数(y设为0就是黑底)

void gtxy (int x, int y); //控制光标位置的函数

int main( ) //主函数

{ csh( );

getch( );

while(1)

{ jishi( );

Sleep(100); //间隔100毫秒

if( kbhit( ) )break; //有键按下就退出循环

}

return 0;

}

void csh( ) //初始化界面

{Color(14,0); //设定淡黄字配黑底

printf(“ 计时器”);

Color(10,0); //设定淡绿字配黑底

printf(" ┌───────────┐");

printf(" │ │");

printf(" └───────────┘");

gtxy(10,4); //光标到屏幕第10列4行处输出

Color(7,0); //恢复白字黑底

printf(" 00:00:00 ");

yinc(1,0 ); //隐藏光标(yinc代表隐藏)

return;

}

void jishi( ) //计时器运行

{ms+=1;

if(ms==10){s+=1;ms=0;}

if(s==60){m+=1;s=0;}

gtxy(10,4);

Color(9,0); //设定淡蓝字配黑底

if(m>9) printf(" %d:",m);

else printf(" 0%d:",m);

Color(14,0); //设定淡黄字配黑底

if(s>9) printf("%d:",s);

else printf("0%d:",s);

Color(12,0); //设定淡红字配黑底

printf("0%d",ms);

}

void gtxy (int x, int y) //控制光标位置的函数

{ COORD pos;

pos.X = x;

pos.Y = y;

SetConsoleCursorPosition ( GetStdHandle (STD_OUTPUT_HANDLE), pos );

}

void Color (short ForeColor= 7, short BackGroundColor= 0) //设定颜色的函数

{ HANDLE handle = GetStdHandle ( STD_OUTPUT_HANDLE );

SetConsoleTextAttribute ( handle, ForeColor + BackGroundColor * 0x10 );

}

void yinc(int x,int y) //隐藏光标的设置(gb代表光标)

{ CONSOLE_CURSOR_INFO gb={x,y}; //x为1-100,y为0就隐藏光标

SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &gb);

}

B. 求C语言小程序源代码,300行左右

黑白棋游戏
#include "graphics.h" /*图形系统头文件*/
#define LEFT 0x4b00 /*光标左键值*/
#define RIGHT 0x4d00 /*光标右键值*/
#define DOWN 0x5000 /*光标下键值*/
#define UP 0x4800 /*光标上键值*/
#define ESC 0x011b /* ESC键值*/
#define ENTER 0x1c0d /* 回车键值*/
int a[8][8]={0},key,score1,score2;/*具体分数以及按键与存放棋子的变量*/
char playone[3],playtwo[3];/*两个人的得分转换成字符串输出*/
void playtoplay(void);/*人人对战函数*/
void DrawQp(void);/*画棋盘函数*/
void SetPlayColor(int x);/*设置棋子第一次的颜色*/
void MoveColor(int x,int y);/*恢复原来棋盘状态*/
int QpChange(int x,int y,int z);/*判断棋盘的变化*/
void DoScore(void);/*处理分数*/
void PrintScore(int n);/*输出成绩*/
void playWin(void);/*输出胜利者信息*/
/******主函数*********/
void main(void)
{
int gd=DETECT,gr;
initgraph(&gd,&gr,"c:\\tc"); /*初始化图形系统*/
DrawQp();/*画棋盘*/
playtoplay();/*人人对战*/
getch();
closegraph();/*关闭图形系统*/
}
void DrawQp()/*画棋盘*/
{
int i,j;
score1=score2=0;/*棋手一开始得分都为0*/
setbkcolor(BLUE);
for(i=100;i<=420;i+=40)
{
line(100,i,420,i);/*画水平线*/
line(i,100,i,420); /*画垂直线*/
}
setcolor(0);/*取消圆周围的一圈东西*/
setfillstyle(SOLID_FILL,15);/*白色实体填凳颤充模式*/
fillellipse(500,200,15,15); /*在显示得分的位置画棋*/
setfillstyle(SOLID_FILL,8); /*黑色实体填充模式*/
fillellipse(500,300,15,15);
a[3][3]=a[4][4]=1;/*初始两个黑棋*/
a[3][4]=a[4][3]=2;/*初始两个白棋*/
setfillstyle(SOLID_FILL,WHITE);
fillellipse(120+3*40,120+3*40,15,15);
fillellipse(120+4*40,120+4*40,15,15);
setfillstyle(SOLID_FILL,8);
fillellipse(120+3*40,120+4*40,15,15);
fillellipse(120+4*40,120+3*40,15,15);
score1=score2=2; /*有棋后改变分数*/
DoScore();/*输出开始分数*/
}
void playtoplay()/*人人对战*/
{
int x,y,t=1,i,j,cc=0;
while(1)/*换棋好悄手走棋*/
{
x=120,y=80;/*每次棋子一开始出来的坐标,x为行坐标,y为列坐标*/
while(1) /*具体一个棋手走棋的过程*/
{
PrintScore(1);/*输出棋手1的成绩*/
PrintScore(2);/*输出棋手2的成绩*/
SetPlayColor(t);/*t变量是友粗渣用来判断棋手所执棋子的颜色*/
fillellipse(x,y,15,15);
key=bioskey(0);/*接收按键*/
if(key==ESC)/*跳出游戏*/
break;
else
if(key==ENTER)/*如果按键确定就可以跳出循环*/
{
if(y!=80&&a[(x-120)/40][(y-120)/40]!=1
&&a[(x-120)/40][(y-120)/40]!=2)/*如果落子位置没有棋子*/
{
if(t%2==1)/*如果是棋手1移动*/
a[(x-120)/40][(y-120)/40]=1;
else/*否则棋手2移动*/
a[(x-120)/40][(y-120)/40]=2;
if(!QpChange(x,y,t))/*落子后判断棋盘的变化*/
{
a[(x-120)/40][(y-120)/40]=0;/*恢复空格状态*/
cc++;/*开始统计尝试次数*/
if(cc>=64-score1-score2) /*如果尝试超过空格数则停步*/
{
MoveColor(x,y);
fillellipse(x,y,15,15);
break;
}
else
continue;/*如果按键无效*/
}
DoScore();/*分数的改变*/
break;/*棋盘变化了,则轮对方走棋*/
}
else/*已经有棋子就继续按键*/
continue;
}
else /*四个方向按键的判断*/
if(key==LEFT&&x>120)/*左方向键*/
{
MoveColor(x,y);
fillellipse(x,y,15,15);
SetPlayColor(t);
x-=40;
fillellipse(x,y,15,15);
}
else
if(key==RIGHT&&x<400&&y>80)/*右方向键*/
{
MoveColor(x,y);
fillellipse(x,y,15,15);
SetPlayColor(t);
x+=40;
fillellipse(x,y,15,15);
}
else
if(key==UP&&y>120)/*上方向键*/
{
MoveColor(x,y);
fillellipse(x,y,15,15);
SetPlayColor(t);
y-=40;
fillellipse(x,y,15,15);
}
else
if(key==DOWN&&y<400)/*下方向键*/
{
MoveColor(x,y);
fillellipse(x,y,15,15);
SetPlayColor(t);
y+=40;
fillellipse(x,y,15,15);
}
}
if(key==ESC)/*结束游戏*/
break;
if((score1+score2)==64||score1==0||score2==0)/*格子已经占满或一方棋子为0判断胜负*/
{
playWin();/*输出最后结果*/
break;
}
t=t%2+1; /*一方走后,改变棋子颜色即轮对方走*/
cc=0; /*计数值恢复为0*/
} /*endwhile*/
}
void SetPlayColor(int t)/*设置棋子颜色*/
{
if(t%2==1)
setfillstyle(SOLID_FILL,15);/*白色*/
else
setfillstyle(SOLID_FILL,8);/*灰色*/
}
void MoveColor(int x,int y)/*走了一步后恢复原来格子的状态*/
{
if(y<100)/*如果是从起点出发就恢复蓝色*/
setfillstyle(SOLID_FILL,BLUE);
else/*其他情况如果是1就恢复白色棋子,2恢复黑色棋子,或恢复蓝色棋盘*/
switch(a[(x-120)/40][(y-120)/40])
{
case 1:
setfillstyle(SOLID_FILL,15);break; /*白色*/
case 2:
setfillstyle(SOLID_FILL,8);break; /*黑色*/
default:
setfillstyle(SOLID_FILL,BLUE); /*蓝色*/
}
}
int QpChange(int x,int y,int t)/*判断棋盘的变化*/
{
int i,j,k,kk,ii,jj,yes;
yes=0;
i=(x-120)/40; /*计算数组元素的行下标*/
j=(y-120)/40; /*计算数组元素的列下标*/
SetPlayColor(t);/*设置棋子变化的颜色*/
/*开始往8个方向判断变化*/
if(j<6)/*往右边*/
{
for(k=j+1;k<8;k++)
if(a[i][k]==a[i][j]||a[i][k]==0)/*遇到自己的棋子或空格结束*/
break;
if(a[i][k]!=0&&k<8)
{
for(kk=j+1;kk<k&&k<8;kk++)/*判断右边*/
{
a[i][kk]=a[i][j]; /*改变棋子颜色*/
fillellipse(120+i*40,120+kk*40,15,15);
}
if(kk!=j+1) /*条件成立则有棋子改变过颜色*/
yes=1;
}
}
if(j>1)/*判断左边*/
{
for(k=j-1;k>=0;k--)
if(a[i][k]==a[i][j]||!a[i][k])
break;
if(a[i][k]!=0&&k>=0)
{
for(kk=j-1;kk>k&&k>=0;kk--)
{
a[i][kk]=a[i][j];
fillellipse(120+i*40,120+kk*40,15,15);
}
if(kk!=j-1)
yes=1;
}
}
if(i<6)/*判断下边*/
{
for(k=i+1;k<8;k++)
if(a[k][j]==a[i][j]||!a[k][j])
break;
if(a[k][j]!=0&&k<8)
{
for(kk=i+1;kk<k&&k<8;kk++)
{
a[kk][j]=a[i][j];
fillellipse(120+kk*40,120+j*40,15,15);
}
if(kk!=i+1)
yes=1;
}
}
if(i>1)/*判断上边*/
{
for(k=i-1;k>=0;k--)
if(a[k][j]==a[i][j]||!a[k][j])
break;
if(a[k][j]!=0&&k>=0)
{
for(kk=i-1;kk>k&&k>=0;kk--)
{
a[kk][j]=a[i][j];
fillellipse(120+kk*40,120+j*40,15,15);
}
if(kk!=i-1)
yes=1;
}
}
if(i>1&&j<6)/*右上*/
{
for(k=i-1,kk=j+1;k>=0&&kk<8;k--,kk++)
if(a[k][kk]==a[i][j]||!a[k][kk])
break;
if(a[k][kk]&&k>=0&&kk<8)
{
for(ii=i-1,jj=j+1;ii>k&&k>=0;ii--,jj++)
{
a[ii][jj]=a[i][j];
fillellipse(120+ii*40,120+jj*40,15,15);
}
if(ii!=i-1)
yes=1;
}
}
if(i<6&&j>1)/*左下*/
{
for(k=i+1,kk=j-1;k<8&&kk>=0;k++,kk--)
if(a[k][kk]==a[i][j]||!a[k][kk])
break;
if(a[k][kk]!=0&&k<8&&kk>=0)
{
for(ii=i+1,jj=j-1;ii<k&&k<8;ii++,jj--)
{
a[ii][jj]=a[i][j];
fillellipse(120+ii*40,120+jj*40,15,15);
}
if(ii!=i+1)
yes=1;
}
}
if(i>1&&j>1)/*左上*/
{
for(k=i-1,kk=j-1;k>=0&&kk>=0;k--,kk--)
if(a[k][kk]==a[i][j]||!a[k][kk])
break;
if(a[k][kk]!=0&&k>=0&&kk>=0)
{
for(ii=i-1,jj=j-1;ii>k&&k>=0;ii--,jj--)
{
a[ii][jj]=a[i][j];
fillellipse(120+ii*40,120+jj*40,15,15);
}
if(ii!=i-1)
yes=1;
}
}
if(i<6&&j<6)/* 右下*/
{
for(k=i+1,kk=j+1;kk<8&&kk<8;k++,kk++)
if(a[k][kk]==a[i][j]||!a[k][kk])
break;
if(a[k][kk]!=0&&kk<8&&k<8)
{
for(ii=i+1,jj=j+1;ii<k&&k<8;ii++,jj++)
{
a[ii][jj]=a[i][j];
fillellipse(120+ii*40,120+jj*40,15,15);
}
if(ii!=i+1)
yes=1;
}
}
return yes;/*返回是否改变过棋子颜色的标记*/
}
void DoScore()/*处理分数*/
{
int i,j;
score1=score2=0;/*重新开始计分数*/
for(i=0;i<8;i++)
for(j=0;j<8;j++)
if(a[i][j]==1)/*分别统计两个人的分数*/
score1++;
else
if(a[i][j]==2)
score2++;
}
void PrintScore(int playnum)/*输出成绩*/
{
if(playnum==1)/*清除以前的成绩*/
{
setfillstyle(SOLID_FILL,BLUE);
bar(550,100,640,400);
}
setcolor(RED);
settextstyle(0,0,4);/*设置文本输出样式*/
if(playnum==1)/*判断输出哪个棋手的分,在不同的位置输出*/
{
sprintf(playone,"%d",score1);
outtextxy(550,200,playone);
}
else
{
sprintf(playtwo,"%d",score2);
outtextxy(550,300,playtwo);
}
setcolor(0);
}
void playWin()/*输出最后的胜利者结果*/
{
settextstyle(0,0,4);
setcolor(12);
if(score2>score1)/*开始判断最后的结果*/
outtextxy(100,50,"black win!");
else
if(score2<score1)
outtextxy(100,50,"white win!");
else
outtextxy(60,50,"you all win!");
}

五子棋游戏
/*五子棋*/
#include<stdio.h>
#include<stdlib.h>
#include<graphics.h>
#include<bios.h>
#include<conio.h>

#define LEFT 0x4b00
#define RIGHT 0x4d00
#define DOWN 0x5000
#define UP 0x4800
#define ESC 0x011b
#define SPACE 0x3920

#define BILI 20
#define JZ 4
#define JS 3
#define N 19

int box[N][N];
int step_x,step_y ;
int key ;
int flag=1 ;

void draw_box();
void draw_cicle(int x,int y,int color);
void change();
void judgewho(int x,int y);
void judgekey();
int judgeresult(int x,int y);
void attentoin();

void attention()
{
char ch ;
window(1,1,80,25);
textbackground(LIGHTBLUE);
textcolor(YELLOW);
clrscr();
gotoxy(15,2);
printf("游戏操作规则:");
gotoxy(15,4);
printf("Play Rules:");
gotoxy(15,6);
printf("1、按左右上下方向键移动棋子");
gotoxy(15,8);
printf("1. Press Left,Right,Up,Down Key to move Piece");
gotoxy(15,10);
printf("2、按空格确定落棋子");
gotoxy(15,12);
printf("2. Press Space to place the Piece");
gotoxy(15,14);
printf("3、禁止在棋盘外按空格");
gotoxy(15,16);
printf("3. DO NOT press Space outside of the chessboard");
gotoxy(15,18);
printf("你是否接受上述的游戏规则(Y/N)");
gotoxy(15,20);
printf("Do you accept the above Playing Rules? [Y/N]:");
while(1)
{
gotoxy(60,20);
ch=getche();
if(ch=='Y'||ch=='y')
break ;
else if(ch=='N'||ch=='n')
{
window(1,1,80,25);
textbackground(BLACK);
textcolor(LIGHTGRAY);
clrscr();
exit(0);
}
gotoxy(51,12);
printf(" ");
}
}
void draw_box()
{
int x1,x2,y1,y2 ;
setbkcolor(LIGHTBLUE);
setcolor(YELLOW);
gotoxy(7,2);
printf("Left, Right, Up, Down KEY to move, Space to put, ESC-quit.");
for(x1=1,y1=1,y2=18;x1<=18;x1++)
line((x1+JZ)*BILI,(y1+JS)*BILI,(x1+JZ)*BILI,(y2+JS)*BILI);
for(x1=1,y1=1,x2=18;y1<=18;y1++)
line((x1+JZ)*BILI,(y1+JS)*BILI,(x2+JZ)*BILI,(y1+JS)*BILI);
for(x1=1;x1<=18;x1++)
for(y1=1;y1<=18;y1++)
box[x1][y1]=0 ;
}

void draw_circle(int x,int y,int color)
{
setcolor(color);
setlinestyle(SOLID_LINE,0,1);
x=(x+JZ)*BILI ;
y=(y+JS)*BILI ;
circle(x,y,8);
}

void judgekey()
{
int i ;
int j ;
switch(key)
{
case LEFT :

if(step_x-1<0)
break ;
else
{
for(i=step_x-1,j=step_y;i>=1;i--)
if(box[i][j]==0)
{
draw_circle(step_x,step_y,LIGHTBLUE);
break ;
}
if(i<1)break ;
step_x=i ;
judgewho(step_x,step_y);
break ;
}
case RIGHT :

if(step_x+1>18)
break ;
else
{
for(i=step_x+1,j=step_y;i<=18;i++)
if(box[i][j]==0)
{
draw_circle(step_x,step_y,LIGHTBLUE);
break ;
}
if(i>18)break ;
step_x=i ;
judgewho(step_x,step_y);
break ;
}
case DOWN :

if((step_y+1)>18)
break ;
else
{
for(i=step_x,j=step_y+1;j<=18;j++)
if(box[i][j]==0)
{
draw_circle(step_x,step_y,LIGHTBLUE);
break ;
}
if(j>18)break ;
step_y=j ;
judgewho(step_x,step_y);
break ;
}
case UP :

if((step_y-1)<0)
break ;
else
{
for(i=step_x,j=step_y-1;j>=1;j--)
if(box[i][j]==0)
{
draw_circle(step_x,step_y,LIGHTBLUE);
break ;
}
if(j<1)break ;
step_y=j ;
judgewho(step_x,step_y);
break ;
}
case ESC :
break ;

case SPACE :
if(step_x>=1&&step_x<=18&&step_y>=1&&step_y<=18)
{
if(box[step_x][step_y]==0)
{
box[step_x][step_y]=flag ;
if(judgeresult(step_x,step_y)==1)
{
sound(1000);
delay(1000);
nosound();
gotoxy(30,4);
if(flag==1)
{
setbkcolor(BLUE);
cleardevice();
setviewport(100,100,540,380,1);
/*定义一个图形窗口*/
setfillstyle(1,2);
/*绿色以实填充*/
setcolor(YELLOW);
rectangle(0,0,439,279);
floodfill(50,50,14);
setcolor(12);
settextstyle(1,0,5);
/*三重笔划字体, 水平放?5倍*/
outtextxy(20,20,"The White Win !");
setcolor(15);
settextstyle(3,0,5);
/*无衬笔划字体, 水平放大5倍*/
outtextxy(120,120,"The White Win !");
setcolor(14);
settextstyle(2,0,8);
getch();
closegraph();
exit(0);
}
if(flag==2)
{
setbkcolor(BLUE);
cleardevice();
setviewport(100,100,540,380,1);
/*定义一个图形窗口*/
setfillstyle(1,2);
/*绿色以实填充*/
setcolor(YELLOW);
rectangle(0,0,439,279);
floodfill(50,50,14);
setcolor(12);
settextstyle(1,0,8);
/*三重笔划字体, 水平放大8倍*/
outtextxy(20,20,"The Red Win !");
setcolor(15);
settextstyle(3,0,5);
/*无衬笔划字体, 水平放大5倍*/
outtextxy(120,120,"The Red Win !");
setcolor(14);
settextstyle(2,0,8);
getch();
closegraph();
exit(0);
}
}
change();
break ;
}
}
else
break ;
}
}

void change()
{
if(flag==1)
flag=2 ;
else
flag=1 ;
}

void judgewho(int x,int y)
{
if(flag==1)
draw_circle(x,y,15);
if(flag==2)
draw_circle(x,y,4);
}

int judgeresult(int x,int y)
{
int j,k,n1,n2 ;
while(1)
{
n1=0 ;
n2=0 ;
/*水平向左数*/
for(j=x,k=y;j>=1;j--)
{
if(box[j][k]==flag)
n1++;
else
break ;
}
/*水平向右数*/
for(j=x,k=y;j<=18;j++)
{
if(box[j][k]==flag)
n2++;
else
break ;
}
if(n1+n2-1>=5)
{
return(1);
break ;
}

/*垂直向上数*/
n1=0 ;
n2=0 ;
for(j=x,k=y;k>=1;k--)
{
if(box[j][k]==flag)
n1++;
else
break ;
}
/*垂直向下数*/
for(j=x,k=y;k<=18;k++)
{
if(box[j][k]==flag)
n2++;
else
break ;
}
if(n1+n2-1>=5)
{
return(1);
break ;
}

/*向左上方数*/
n1=0 ;
n2=0 ;
for(j=x,k=y;j>=1,k>=1;j--,k--)
{
if(box[j][k]==flag)
n1++;
else
break ;
}
/*向右下方数*/
for(j=x,k=y;j<=18,k<=18;j++,k++)
{
if(box[j][k]==flag)
n2++;
else
break ;
}
if(n1+n2-1>=5)
{
return(1);
break ;
}

/*向右上方数*/
n1=0 ;
n2=0 ;
for(j=x,k=y;j<=18,k>=1;j++,k--)
{
if(box[j][k]==flag)
n1++;
else
break ;
}
/*向左下方数*/
for(j=x,k=y;j>=1,k<=18;j--,k++)
{
if(box[j][k]==flag)
n2++;
else
break ;
}
if(n1+n2-1>=5)
{
return(1);
break ;
}
return(0);
break ;
}
}

void main()
{
int gdriver=VGA,gmode=VGAHI;
clrscr();
attention();
initgraph(&gdriver,&gmode,"c:\\tc");
/* setwritemode(XOR_PUT);*/
flag=1 ;
draw_box();
do
{
step_x=0 ;
step_y=0 ;
/*draw_circle(step_x,step_y,8); */
judgewho(step_x-1,step_y-1);
do
{
while(bioskey(1)==0);
key=bioskey(0);
judgekey();
}
while(key!=SPACE&&key!=ESC);
}
while(key!=ESC);
closegraph();
}

C. 求C程序源代码

用for
语句和getch(
);putchar
(‘*’);来实现的,而getch
不分区另ENTER和BACKSPACE等特殊键,不好控制它的结束。因此只有避过问题强行规定密码必须是8位的,但在输入密码时仍然不允许用户输入ENTER和BACKSPACE等特殊键。
以下程序功能:
接受所有打印字符。
不接受控制字符,如Ctrl+
,Alt,F1等。
可使用退格键删除以输入字符。
回车键为密码输入完毕
可定义最大字符数。当输入字符数等于最大字符个数时,视为密码结束。
#include
<stdio.h>
#include
<conio.h>
#define
TRUE
1
#define
FALSE
0
#define
MIN_INPUT
0x20
#define
MAX_INPUT
0x7e
/*
*
所有功能有此函数实现:
*
pszPw

保存密码的缓冲
*
iMaxSize
:最大的密码长度,该长度必须小于缓冲区大小。
*
返回值为TRUE为成功获取密码。总是返回TRUE
*/
int
GetPassword(unsigned
char*
pszPw,int
iMaxSize)
{
unsigned
char
ch;
int
i=0;
int
bIsEcho=TRUE;
//while(
!
kbhit()
&&
i<iMaxSize
)
while(
(
ch
=
(unsigned
char)getch()
)
&&
i
<
iMaxSize
)
{
//ch
=
(unsigned
char)getch();
bIsEcho=TRUE;
if
(
ch
==
13)
{
pszPw[i++]=0;
break;
}
else
if
(
ch
>=
MIN_INPUT
&&
ch
<=
MAX_INPUT)
/*所有可打印字符*/
{
pszPw[i++]=ch;
}
else
if
(
ch
==
8
&&
i>
0
)
/*退格键*/
{
pszPw[i--]
=
0;
bIsEcho
=
FALSE;
putchar(
ch
);
putchar(
'
'
);
putchar(
ch
);
}
else
bIsEcho
=
FALSE;
if(bIsEcho)
putchar('*');
}
pszPw[i]=0;
return
TRUE;
}
int
main(void)
{
int
iMaxSize=80;
unsigned
char
pw[99];
if
(
GetPassword(pw,iMaxSize)
==
TRUE
){
printf("\npassword=%s",pw);
}
else{
printf("\nCan
not
get
the
password!");
}
}

D. c程序源代码

#include<stdio.h>
main()
{
int a[3];
int i,pass,hoad;
printf("shu ru san ge shuzi:");
scanf("%2d%2d%2d",&a[0],&a[1],&a[2]);
for(i=0;i<=2;i++)
printf("%4d",a[i]);
printf("\n");
for(pass=1;pass<=2;pass++)
for(i=0;i<=1;i++)
if(a[i]>a[i+1]){
hoad=a[i];
a[i]=a[i+1];
a[i+1]=hoad; }
for(i=0;i<=2;i++)
printf("%4d",a[i]);
printf("\n");
getch();
}

E. 求个用c/c++编写windows程序源代码

下面是完整程序,MS VC++ 6.0 编译器。
主要用途,用鼠标点击调节 RGB 数值,椭圆里显示 对应的颜色。
程序里有多余的码,你可以删去。(一个多余是试验鼠标移动时连续显示坐标数值,还有一个多余部分是调用Vfw32.lib播放一个avi视频。)

// cl show_color.cpp
#include <Afxwin.h>
#include <math.h>
// #include <Vfw.h>
// #pragma comment (lib, "Vfw32.lib")
#define DEBUG 1
HWND hWndMain;
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
BOOL InitWindowsClass(HINSTANCE hInstance);
BOOL InitWindows(HINSTANCE hInstance,int nCmdShow);
char one_line[80];
int len,NN;
LPTSTR argv;
RECT RectR, RectG, RectB, RectX;
int RectDy,RectW,RectH;
int x_r=495,x_g=495,x_b=495,x_shift=100;
long int v_r,v_g,v_b;

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInst,LPSTR lpszCmdLine,int nCmdShow)
{
MSG Msg;
int i;
RectDy = 50; RectW = 400; RectH = 30;
RectR.left = 0; RectR.right=RectW; RectR.bottom=200; RectR.top = RectR.bottom + RectH;
RectG.left = 0; RectB.left = 0;
RectG.right=RectW; RectB.right=RectW;
RectG.bottom=RectR.bottom + RectDy; RectB.bottom=RectG.bottom + RectDy;
RectG.top = RectG.bottom + RectH;
RectB.top = RectB.bottom + RectH;
v_r = (x_r - x_shift) * 255 / RectW;
v_g = (x_g - x_shift) * 255 / RectW;
v_b = (x_b - x_shift) * 255 / RectW;

if(!InitWindowsClass(hInstance))
return FALSE;
if(!InitWindows(hInstance,nCmdShow))
return FALSE;
ShowWindow(hWndMain,nCmdShow);
UpdateWindow(hWndMain);
while(GetMessage(&Msg,NULL,0,0))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
static long nXChar,nYChar,xInc,yInc;
static int xClient, yClient; // width height of client area
static int xClientMax; // maximum width of client area
static int xChar, yChar; // horizontal vertical scrolling unit
static int xPos,yPos; // current horizontal vertical scrolling position
static int xMax,yMax; // maximum horizontal scrolling position
SCROLLINFO si;
HDC hdc;
short x;
TEXTMETRIC tm;
PAINTSTRUCT ps;
COLORREF color;
HFONT font;
HPEN hP1; // pen
HBRUSH hBr,hBrR,hBrG,hBrB;
CPoint aP,mousePos;
HWND h_wnd2;

int i;
char szlocation[100]; //temp
CPoint pt,pt2; // temp
RECT rect,rect2;
switch(message)
{
case WM_LBUTTONDOWN: case WM_LBUTTONUP:
mousePos.x = LOWORD( lParam );
mousePos.y = HIWORD( lParam );
if (mousePos.x >= RectR.left+x_shift && mousePos.x <= RectR.right+x_shift){
if (mousePos.y > RectR.bottom && mousePos.y < RectR.top) x_r = mousePos.x;
if (mousePos.y > RectG.bottom && mousePos.y < RectG.top) x_g = mousePos.x;
if (mousePos.y > RectB.bottom && mousePos.y < RectB.top) x_b = mousePos.x;
v_r = (x_r - x_shift) * 255 / RectW;
v_g = (x_g - x_shift) * 255 / RectW;
v_b = (x_b - x_shift) * 255 / RectW;
ShowWindow(hwnd, SW_HIDE);
ShowWindow(hwnd, SW_SHOW);
UpdateWindow(hwnd);
};
return 0;
case WM_CREATE:
hdc=GetDC(hwnd);
GetTextMetrics(hdc,&tm);
nXChar=tm.tmAveCharWidth;
nYChar=tm.tmHeight;
xInc=1;yInc=1; xChar=nXChar; yChar=nYChar; // for scroll window
ReleaseDC(hwnd,hdc);
xClientMax = 800;
// h_wnd2 = MCIWndCreate(hwnd,NULL,0,"sylvtwt.avi"); //Play
// MCIWndPlay(h_wnd2); // Play
return 0;
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps); // begin paint
SetGraphicsMode(hdc,GM_ADVANCED);
SetWindowExtEx(hdc,700,400,NULL); // cx=700,cy=400 logical unit
SetViewportExtEx(hdc,600,400,NULL);
SetViewportOrgEx(hdc,x_shift,10,NULL);
SetMapMode(hdc,MM_ANISOTROPIC);

color=RGB(0,128,128);
hP1=CreatePen(PS_SOLID,0,color);
SelectObject(hdc,hP1);

hBrR = CreateSolidBrush( RGB(255,0,0));
hBrG = CreateSolidBrush( RGB(0,255,0));
hBrB = CreateSolidBrush( RGB(0,0,255));
hBr = CreateSolidBrush( RGB(200,200,200));
SelectObject(hdc,hBrR);
FillRect(hdc, &RectR, hBrR);
RectX=RectR; RectX.left=x_r-x_shift; SelectObject(hdc,hBr); FillRect(hdc, &RectX, hBr);
SelectObject(hdc,hBrG);
FillRect(hdc, &RectG, hBrG);
RectX=RectG; RectX.left=x_g-x_shift; SelectObject(hdc,hBr); FillRect(hdc, &RectX, hBr);
SelectObject(hdc,hBrB);
FillRect(hdc, &RectB, hBrB);
RectX=RectB; RectX.left=x_b-x_shift; SelectObject(hdc,hBr); FillRect(hdc, &RectX, hBr);

font=CreateFont(
24,10,0,0, FW_NORMAL,0,0,0, ANSI_CHARSET,OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,NULL,"myfont"
);
SelectObject(hdc,font);
GetTextMetrics(hdc,&tm);
nYChar=tm.tmHeight;
color=RGB(0,0,0);
sprintf(one_line,"R=%3d",v_r);
TextOut(hdc,RectR.right+10,RectR.bottom,one_line,strlen(one_line));
sprintf(one_line,"G=%3d",v_g);
TextOut(hdc,RectG.right+10,RectG.bottom,one_line,strlen(one_line));
sprintf(one_line,"B=%3d",v_b);
TextOut(hdc,RectB.right+10,RectB.bottom,one_line,strlen(one_line));
color = RGB(v_r,v_g,v_b);
hBr = CreateSolidBrush(color);
SelectObject(hdc,hBr);
Ellipse(hdc, 100, 30, 326, 144);

EndPaint(hwnd,&ps); // end paint
return 0L;

case WM_SIZE:
yClient = HIWORD (lParam);
xClient = LOWORD (lParam);
yMax = max (0, 600 - yClient/yChar); // need to calculate
yPos = min (yPos, yMax); // current position not exceed the maximum
si.cbSize = sizeof(si);
si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS;
si.nMin = 0; si.nMax = yMax; si.nPage = yClient / yChar;
si.nPos = yPos;
SetScrollInfo(hwnd, SB_VERT, &si, TRUE);
xMax = max (0, 2 + (1600 - xClient)/xChar);
xPos = min (xPos, xMax);
si.cbSize = sizeof(si);
si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS;
si.nMin = 0;
si.nMax = xMax;
si.nPage = xClient / xChar;
si.nPos = xPos;
SetScrollInfo(hwnd, SB_HORZ, &si, TRUE);
UpdateWindow (hwnd);
return 0;
case WM_VSCROLL:
switch(LOWORD (wParam))
{
case SB_PAGEUP: // User clicked shaft left of the scroll box.
yInc = -4; break;
case SB_PAGEDOWN: // User clicked shaft right of the scroll box.
yInc = 4; break;
case SB_LINEUP: // User clicked the left arrow.
yInc = -1; break;
case SB_LINEDOWN: // User clicked the right arrow.
yInc = 1; break;
case SB_THUMBTRACK: // User dragged the scroll box.
yInc = HIWORD(wParam) - yPos; break;
default:
yInc = 0; break;
}
if (yInc = max(-yPos, min(yInc, yMax - yPos)))
{
yPos += yInc;
ScrollWindowEx(hwnd, 0, -yChar * yInc,
(CONST RECT *) NULL, (CONST RECT *) NULL,
(HRGN) NULL, (LPRECT) NULL, SW_INVALIDATE);
si.cbSize = sizeof(si);
si.fMask = SIF_POS;
si.nPos = yPos;
SetScrollInfo(hwnd, SB_VERT, &si, TRUE);
UpdateWindow (hwnd);
};
return 0;

case WM_HSCROLL:
switch(LOWORD (wParam))
{
case SB_PAGEUP: // User clicked shaft left of the scroll box.
xInc = -4; break;
case SB_PAGEDOWN: // User clicked shaft right of the scroll box.
xInc = 4; break;
case SB_LINEUP: // User clicked the left arrow.
xInc = -1; break;
case SB_LINEDOWN: // User clicked the right arrow.
xInc = 1; break;
case SB_THUMBTRACK: // User dragged the scroll box.
xInc = HIWORD(wParam) - xPos; break;
default:
xInc = 0; break;
}
if (xInc = max(-xPos, min(xInc, xMax - xPos)))
{
xPos += xInc;
ScrollWindowEx(hwnd, -xChar * xInc, 0,
(CONST RECT *) NULL, (CONST RECT *) NULL,
(HRGN) NULL, (LPRECT) NULL, SW_INVALIDATE);
si.cbSize = sizeof(si);
si.fMask = SIF_POS;
si.nPos = xPos;
SetScrollInfo(hwnd, SB_HORZ, &si, TRUE);
UpdateWindow (hwnd);
};
return 0;

case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hwnd,message,wParam,lParam);

}
}
BOOL InitWindowsClass(HINSTANCE hInstance)
{
WNDCLASS wndclass;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hIcon=LoadIcon(NULL,"END");
wndclass.hInstance=hInstance;
wndclass.lpfnWndProc=WndProc;
wndclass.lpszClassName="Windows Fill";
wndclass.lpszMenuName=NULL;
wndclass.style=CS_HREDRAW|CS_VREDRAW;
return(RegisterClass(&wndclass));
}

BOOL InitWindows(HINSTANCE hInstance,int nCmdShow)
{
HWND hWnd;
hWnd=CreateWindow(
"Windows Fill",
"Show_color",
WS_OVERLAPPEDWINDOW | WS_SYSMENU | WS_BORDER | WS_HSCROLL | WS_VSCROLL,
100,100,800,400,
NULL,
NULL,
hInstance,
NULL
);
if(!hWnd)
return FALSE;
hWndMain=hWnd;
ShowWindow(hWnd,nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}

热点内容
梵蒂冈顶级时装ftp 发布:2025-01-28 03:03:36 浏览:694
手游脚本有前途吗 发布:2025-01-28 02:46:55 浏览:378
抓包编程 发布:2025-01-28 02:42:41 浏览:929
安卓平板上怎么设置热点 发布:2025-01-28 02:36:33 浏览:717
如何在手机上压缩图片 发布:2025-01-28 02:34:09 浏览:989
服务器ip挂上公网 发布:2025-01-28 02:31:15 浏览:978
吃鸡配置需要什么条件 发布:2025-01-28 02:26:15 浏览:9
58怎么上传简历 发布:2025-01-28 02:17:45 浏览:38
限制访问的ip 发布:2025-01-28 02:16:16 浏览:238
火车上车厢密码是多少 发布:2025-01-28 02:16:13 浏览:210