b2c信息网

您现在的位置是:首页 > 今日新闻 > 正文

今日新闻

好看的c语言界面源码(c语言界面设计代码)

hacker2022-06-15 00:16:29今日新闻89
本文目录一览:1、怎样用c语言编写一个界面好看的游戏例如俄罗斯方块

本文目录一览:

怎样用c语言编写一个界面好看的游戏 例如 俄罗斯方块

别说做游戏了,做一个正规的窗口都困难得要死!!!

自己看吧。这就是用C语言做的最最简单的一个窗口:

#include tchar.h

#include windows.h

/* 这个函数由Windows内部函数DispatchMessage()调用 */ 

LRESULT CALLBACK WindowProcedure (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)

{

 HDC hdc;

 PAINTSTRUCT ps;

 RECT rect;

 switch (message)    /* 处理信息 */

 {

  case WM_DESTROY: 

   PostQuitMessage (0);      /* 发送WM_QUIT到消息队列 */

   break;

  case WM_PAINT:

   hdc = BeginPaint (hWnd, ps);

   GetClientRect (hWnd, rect);

   DrawText (hdc, TEXT("Hello, Windows NT!"), -1, rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER);

   EndPaint (hWnd, ps);

   break;

  default:  /* 不处理的消息 */ 

   return DefWindowProc (hWnd, message, wParam, lParam);

 }

 return 0;

}

/* 下面是主函数 */

int WINAPI _tWinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nFunsterStil)

{

 HWND hWnd;   /* 这是窗口的句柄 */

 MSG messages;   /* 应用程序的消息保存在这里 */

 WNDCLASSEX wincl;  /* 窗口类的数据结构 */

 TCHAR szClassName[ ] = TEXT("WindowsApp"); /* 窗口类的类名 */

 /* 窗口结构 */

 wincl.hInstance = hThisInstance;

 wincl.lpszClassName = szClassName;

 wincl.lpfnWndProc = WindowProcedure;/* 这个函数由Windows操作系统调用 */

 wincl.style = CS_DBLCLKS; /* 获取双击指令 */

 wincl.cbSize = sizeof (WNDCLASSEX);

 /* 使用默认图标和鼠标指针 */

 wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);

 wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);

 wincl.hCursor = LoadCursor (NULL, IDC_ARROW);

 wincl.lpszMenuName = NULL; /* 没有菜单 */

 wincl.cbClsExtra = 0;/* 窗口类后面没有多余的字节 */

 wincl.cbWndExtra = 0;/* 结构或者窗口实例 */

 /* 使用窗口的默认颜色作为窗口的背景色 */

 wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;

 /* 注册窗口类。如果注册失败,那么就退出程序 */

 if (!RegisterClassEx (wincl))

  return 0;

 /* 窗口类已被注册。创建它的程序 */

 hWnd = CreateWindowEx (

   0,

   szClassName, /* 类名 */

   TEXT("Windows App"), /* 窗口标题栏的文字 */

   WS_OVERLAPPEDWINDOW, /* 默认窗口 */

   CW_USEDEFAULT, /* 窗口左上角的位置 */

   CW_USEDEFAULT, /* 窗口右下角的位置 */

   544, /* 窗口宽度(以“像素”位单位) */

   375, /* 窗口高度(以“像素”位单位) */

   HWND_DESKTOP, /* 窗口是桌面的子窗口 */

   NULL,/* 该窗口无菜单 */

   hThisInstance, /* 程序实例的句柄 */

   NULL /* 没有窗口创建的数据 */

   );

 /* 显示窗口 */

 ShowWindow (hWnd, nFunsterStil);

 /* 重绘窗口 */

 UpdateWindow(hWnd);

 /* 运行消息循环。循环到GetMessage()函数返回0 */

 while (GetMessage (messages, NULL, 0, 0))

 {

  /* 把虚拟信息翻译成字符信息 */

  TranslateMessage(messages);

  /* 发送信息到窗口过程 */

  DispatchMessage(messages);

 }

 /* 返回PostQuitMessage()函数的返回值 */

 return messages.wParam;

}

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

最简单的模拟计时器:

#includestdio.h

#includeconio.h

#includewindows.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(“\n\n\t    计时器”);

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

printf("\n\t┌───────────┐");

printf("\n\t│           │");

printf("\n\t└───────────┘");

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(m9) printf(" %d:",m);

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

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

if(s9) 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);

}

c语言程序界面源代码

保存源代码的话,可以保存成txt,即新建一个空白的文本文档,再把代码复制进去。还可以直接点vc++的保存或另存为按钮,进到你建好的目录下,再将文件名命名,名字是xxx.cpp,保存即可。

希望可以帮到你!

求助啊,谁有有趣的c语言小程序,并且要有源代码!!

学习“推箱子”C语言编码:

#include stdio.h

#include conio.h

#includestdlib.h

#includewindows.h

int m =0;  //m代表第几关

struct maps{short a[9][11]; };

struct maps map[5]={ 0,0,0,0,0,0,0,0,0,0,0,  //共5关,每关9行

              0,1,1,1,1,1,1,1,0,0,0,

              0,1,0,0,0,0,0,1,1,1,0,

              1,1,4,1,1,1,0,0,0,1,0,  //0空地,1墙

               1,5,0,0,4,0,0,4,0,1,0,  //4是箱子,5是人

              1,0,3,3,1,0,4,0,1,1,0,  //3是目的地

              1,1,3,3,1,0,0,0,1,0,0,  //7是箱子在目的地(4+3)

              0,1,1,1,1,1,1,1,1,0,0,  //8是人在目的地(5+3)

                0,0,0,0,0,0,0,0,0,0,0,

                0,0,0,0,0,0,0,0,0,0,0,

              0,0,1,1,1,1,0,0,0,0,0,

              0,0,1,5,0,1,1,1,0,0,0,

              0,0,1,0,4,0,0,1,0,0,0,

               0,1,1,1,0,1,0,1,1,0,0,

              0,1,3,1,0,1,0,0,1,0,0,

              0,1,3,4,0,0,1,0,1,0,0,

              0,1,3,0,0,0,4,0,1,0,0,

                0,1,1,1,1,1,1,1,1,0,0,

                0,0,0,0,0,0,0,0,0,0,0,

              0,0,0,1,1,1,1,1,1,1,0,

              0,0,1,1,0,0,1,0,5,1,0,

              0,0,1,0,0,0,1,0,0,1,0,

               0,0,1,4,0,4,0,4,0,1,0,

              0,0,1,0,4,1,1,0,0,1,0,

              1,1,1,0,4,0,1,0,1,1,0,

              1,3,3,3,3,3,0,0,1,0,0,

                1,1,1,1,1,1,1,1,1,0,0,

                0,1,1,1,1,1,1,1,1,1,0,

              0,1,0,0,1,1,0,0,0,1,0,

              0,1,0,0,0,4,0,0,0,1,0,

              0,1,4,0,1,1,1,0,4,1,0,

               0,1,0,1,3,3,3,1,0,1,0,

              1,1,0,1,3,3,3,1,0,1,1,

              1,0,4,0,0,4,0,0,4,0,1,

              1,0,0,0,0,0,1,0,5,0,1,

                1,1,1,1,1,1,1,1,1,1,1,

                0,0,0,0,0,0,0,0,0,0,0,

              0,0,0,1,1,1,1,1,1,0,0,

              0,1,1,1,0,0,0,0,1,0,0,

              1,1,3,0,4,1,1,0,1,1,0,

               1,3,3,4,0,4,0,0,5,1,0,

              1,3,3,0,4,0,4,0,1,1,0,

              1,1,1,1,1,1,0,0,1,0,0,

              0,0,0,0,0,1,1,1,1,0,0,

                0,0,0,0,0,0,0,0,0,0,0 };

void DrMap( )  //绘制地图

{ CONSOLE_CURSOR_INFO cursor_info={1,0};   //隐藏光标的设置

SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),cursor_info);

printf("\n\n \t\t\b推箱子");

printf("\n \t");

for (int i = 0; i 9; i++)

{for (int j = 0; j 11; j++)

{switch (map[m].a[i][j])

{case 0:  printf("  "); break;

case 1:  printf("■"); break;

      case 3:  printf("◎");break;

case 4:  printf("□"); break;

case 5:  printf("♀"); break;   //5是人

case 7:  printf("□"); break;  //4 + 3箱子在目的地中

case 8:  printf("♀");break;   // 5 + 3人在目的地中

}

}

printf("\n\t");

}

}

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

{ COORD coord;

coord.X = x;

coord.Y = y;

SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);

}

void start( )  //开始游戏

{ int r, c;    //r,c用于记录人的下标

for (int i = 0; i 9; i++)

{ for (int j = 0; j 11; j++)

     {if (map[m].a[i][j] == 5||map[m].a[i][j]==8) { r = i;  c = j; } } //i j 人的下标

}

char key;

key = getch( );

switch (key)

{case 'W':

case 'w':

case 72:

if (map[m]. a[r - 1][c] == 0|| map[m]. a [r - 1][c] == 3)

{ gtxy(2*c+8,r-1+3); printf("♀");   // gtxy(2*c+8,r-1+3)是到指定位置输出字符

        if(map[m]. a[r ][c] == 5){gtxy(2*c+8,r+3); printf("  "); }

       if(map[m]. a[r ][c] == 8){gtxy(2*c+8,r+3); printf("◎");}

       map[m]. a [r - 1][c] += 5;  map[m]. a [r][c] -= 5; }

else  if (map[m]. a [r - 1][c] == 4 || map[m]. a [r - 1][c] == 7)

       { if (map[m]. a [r - 2][c] == 0 || map[m]. a [r - 2][c] == 3)

{ gtxy(2*c+8,r-2+3); printf("□"); gtxy(2*c+8,r-1+3); printf("♀");

           if(map[m]. a[r ][c] == 5){gtxy(2*c+8,r+3); printf("  "); }

           if(map[m]. a[r ][c] == 8){gtxy(2*c+8,r+3); printf("◎");}

           map[m]. a [r - 2][c] += 4;  map[m]. a [r - 1][c] += 1;

 map[m]. a [r][c] -= 5; }

} break;

case 'S':

case 's':

case 80:

if (map[m]. a [r + 1][c] == 0 || map[m]. a [r + 1][c] == 3)

 { gtxy(2*c+8,r+1+3); printf("♀");

         if(map[m]. a[r ][c] == 5){gtxy(2*c+8,r+3); printf("  "); }

        if(map[m]. a[r ][c] == 8){gtxy(2*c+8,r+3); printf("◎");}

        map[m]. a [r + 1][c] += 5;  map[m]. a [r][c] -= 5; }

     else if (map[m]. a [r + 1][c] == 4 || map[m]. a [r+ 1][c] == 7)

         { if (map[m]. a [r + 2][c] == 0 || map[m]. a [r + 2][c] == 3)

           { gtxy(2*c+8,r+2+3); printf("□"); gtxy(2*c+8,r+1+3); printf("♀");

             if(map[m]. a[r ][c] == 5){gtxy(2*c+8,r+3); printf("  "); }

            if(map[m]. a[r ][c] == 8){gtxy(2*c+8,r+3); printf("◎");}

            map[m]. a [r + 2][c] += 4; map[m]. a [r + 1][c] += 1;

map[m]. a [r][c] -= 5; }

  }break;

case 'A':

case 'a':

case 75:

if (map[m]. a [r ][c - 1] == 0 || map[m]. a [r ][c - 1] == 3)

        { gtxy(2*(c-1)+8,r+3); printf("♀");

         if(map[m]. a[r ][c] == 5){gtxy(2*c+8,r+3); printf("  "); }

        if(map[m]. a[r ][c] == 8){gtxy(2*c+8,r+3); printf("◎");}

         map[m]. a [r ][c - 1] += 5; map[m]. a [r][c] -= 5; }

     else if (map[m]. a [r][c - 1] == 4 || map[m]. a [r][c - 1] == 7)

        {if (map[m]. a [r ][c - 2] == 0 || map[m]. a [r ][c - 2] == 3)

{ gtxy(2*(c-2)+8,r+3); printf("□"); gtxy(2*(c-1)+8,r+3); printf("♀");

            if(map[m]. a[r ][c] == 5){gtxy(2*c+8,r+3); printf("  "); }

            if(map[m]. a[r ][c] == 8){gtxy(2*c+8,r+3); printf("◎");}

            map[m]. a [r ][c - 2] += 4; map[m]. a [r ][c - 1] += 1;

            map[m]. a [r][c] -= 5; }

 }break;

case 'D':

case 'd':

case 77:

if (map[m]. a [r][c + 1] == 0 || map[m]. a [r][c + 1] == 3)

 { gtxy(2*(c+1)+8,r+3); printf("♀");

         if(map[m]. a[r ][c] == 5){gtxy(2*c+8,r+3); printf("  "); }

         if(map[m]. a[r ][c] == 8) {gtxy(2*c+8,r+3); printf("◎");}

        map[m]. a [r][c + 1] += 5;  map[m]. a [r][c] -= 5; }

    else if (map[m]. a [r][c + 1] == 4 || map[m]. a [r][c + 1] == 7)

        { if (map[m]. a [r][c + 2] == 0 || map[m]. a [r][c + 2] == 3)

{ gtxy(2*(c+2)+8,r+3); printf("□"); gtxy(2*(c+1)+8,r+3); printf("♀");

            if(map[m]. a[r ][c] == 5){gtxy(2*c+8,r+3); printf("  "); }

           if(map[m]. a[r ][c] == 8){gtxy(2*c+8,r+3); printf("◎");}

           map[m]. a [r][c + 2] += 4; map[m]. a [r][c + 1] += 1;

           map[m]. a [r][c] -= 5; }

 }break;

  }

}

int ifwan( )  //是否完成(1是0否)

{ if(m==0){if(map[m].a[5][2]==7 map[m].a[5][3]==7

                map[m].a[6][2]==7 map[m].a[6][3]==7) return 1;}

if(m==1){if(map[m].a[5][2]==7 map[m].a[6][2]==7

                map[m].a[7][2]==7) return 1;}

if(m==2){if(map[m].a[7][1]==7 map[m].a[7][2]==7 map[m].a[7][3]==7

               map[m].a[7][4]==7 map[m].a[7][5]==7) return 1;}

if(m==3){if(map[m].a[4][4]==7 map[m].a[4][5]==7 map[m].a[4][6]==7

      map[m].a[5][4]==7 map[m].a[5][5]==7 map[m].a[5][6]==7) return 1;}

if(m==4){if(map[m].a[3][2]==7 map[m].a[4][1]==7 map[m].a[4][2]==7

              map[m].a[5][1]==7 map[m].a[5][2]==7) return 1;}

return 0;

}

int main( )  //主函数

{ while (1)

     { system("cls");

       DrMap( );

       while (1)

           { start( );

             if(ifwan()){printf("\007");break;} //完成后响铃

          }

       m+=1;

    }

  return 0;

}

有没有大神提供一个c语言源代码的模板 能够点一下就能切换一个界面?

#include stdlib.h #include windows.h #include "stdio.h" void main() { int n; printf("欢迎界面");//欢迎界面 Sleep(1000);//延时 system("cls");//清屏 //菜单界面 printf("***********************************************\n"); printf("*************1、 ***********************\n"); printf("*************2、 ***********************\n"); printf("*************3、 ***********************\n"); printf("***********************************************\n"); //菜单选择 scanf("%d",n); if(n==1){} else if(n==2){} else if(n==3){} else {printf("错误!");} } 希望能帮助你,喜欢请采纳,有问题欢迎追问!

急求一个计算器界面的C语言源代码,只要界面,相当急 啊.........

#includestdio.h

#includestdlib.h

#includemath.h

void add(float a,float b);

void sub(float a,float b);

void mul(float a,float b);

void dv(float a,float b);

void p(float a,float b);

void main()

{ float a,b,m;

char ch;

while(1)

{printf("input first number:");

scanf("%f",a);

getchar();

printf("input char:");

scanf("%c",ch);

switch(ch)

{ case '+':printf("input second number:");scanf("%f",b);add(a,b);break;

case '-':printf("input second number:");scanf("%f",b);sub(a,b);break;

case '*':printf("input second number:");scanf("%f",b);mul(a,b);break;

case '/':printf("input second number:");scanf("%f",b);

{if(b==0)

{printf("Divided by zero.\n");break;}

else

{dv(a,b);break;}

}

case 's':m=sqrt(a);printf("result=%f\n",m);break;

case 'x':m=1.0/a;printf("result=%f\n",m);break;

case 'c':a=0;break;

case 'p':printf("input second number:");scanf("%f",b);p(a,b);break;

case 'q':printf("User exit.\n");

return;

default:printf("illegal operator.\n");

}

}

}

void add(float a,float b)

{ float m=0,n;

char ch;

m=a+b;

printf("result=%f\n",m);

getchar();

while(1)

{printf("input char:");

scanf("%c",ch);

switch(ch)

{ case '+':printf("input second number:");scanf("%f",n);add(m,n);break;

case '-':printf("input second number:");scanf("%f",n);sub(m,n);break;

case '*':printf("input second number:");scanf("%f",n);mul(m,n);break;

case '/':printf("input second number:");scanf("%f",n);

{if(n==0)

{printf("Divided by zero.\n");break;}

else

{dv(m,n);break;}

}

case 's':m=sqrt(m);printf("result=%f\n",m);break;

case 'x':m=1.0/m;printf("result=%f\n",m);break;

case 'p':printf("input second number:");scanf("%f",n);p(m,n);break;

case 'c':printf("User return.\n");

return;

case 'q':exit(0);

default:printf("illegal operator.\n");

}

}

}

void sub(float a,float b)

{ float m=0,n;

char ch;

m=a-b;

printf("result=%f\n",m);

getchar();

while(1)

{printf("input char:");

scanf("%c",ch);

switch(ch)

{ case '+':printf("input second number:");scanf("%f",n);add(m,n);break;

case '-':printf("input second number:");scanf("%f",n);sub(m,n);break;

case '*':printf("input second number:");scanf("%f",n);mul(m,n);break;

case '/':printf("input second number:");scanf("%f",n);

{if(n==0)

{printf("Divided by zero.\n");break;}

else

{dv(m,n);break;}

}

case 's':m=sqrt(m);printf("result=%f\n",m);break;

case 'x':m=1.0/m;printf("result=%f\n",m);break;

case 'p':printf("input second number:");scanf("%f",n);p(m,n);break;

case 'c':printf("User return.\n");

return;

case 'q':exit(0);

default:printf("illegal operator.\n");

}

}

}

void mul(float a,float b)

{ float m=0,n;

char ch;

m=a*b;

printf("result=%f\n",m);

getchar();

while(1)

{printf("input char:");

scanf("%c",ch);

switch(ch)

{ case '+':printf("input second number:");scanf("%f",n);add(m,n);break;

case '-':printf("input second number:");scanf("%f",n);sub(m,n);break;

case '*':printf("input second number:");scanf("%f",n);mul(m,n);break;

case '/':printf("input second number:");scanf("%f",n);

{if(n==0)

{printf("Divided by zero.\n");break;}

else

{dv(m,n);break;}

}

case 's':m=sqrt(m);printf("result=%f\n",m);break;

case 'x':m=1.0/m;printf("result=%f\n",m);break;

case 'p':printf("input second number:");scanf("%f",n);p(m,n);break;

case 'c':printf("User return.\n");

return;

case 'q':exit(0);

default:printf("illegal operator.\n");

}

}

}

void dv(float a,float b)

{ float m=0,n;

char ch;

m=a/b;

printf("result=%f\n",m);

getchar();

while(1)

{printf("input char:");

scanf("%c",ch);

switch(ch)

{ case '+':printf("input second number:");scanf("%f",n);add(m,n);break;

case '-':printf("input second number:");scanf("%f",n);sub(m,n);break;

case '*':printf("input second number:");scanf("%f",n);mul(m,n);break;

case '/':printf("input second number:");scanf("%f",n);

{if(n==0)

{printf("Divided by zero.\n");break;}

else

{dv(m,n);break;}

}

case 's':m=sqrt(m);printf("result=%f\n",m);break;

case 'x':m=1.0/m;printf("result=%f\n",m);break;

case 'p':printf("input second number:");scanf("%f",n);p(m,n);break;

case 'c':printf("User return.\n");

return;

case 'q':exit(0);

default:printf("illegal operator.\n");

}

}

}

void p(float a,float b)

{ float m=1,n;

int i;

char ch;

for(i=1;i=b;i++)

{m=m*a;

}

printf("result=%f\n",m);

getchar();

while(1)

{printf("input char:");

scanf("%c",ch);

switch(ch)

{ case '+':printf("input second number:");scanf("%f",n);add(m,n);break;

case '-':printf("input second number:");scanf("%f",n);sub(m,n);break;

case '*':printf("input second number:");scanf("%f",n);mul(m,n);break;

case '/':printf("input second number:");scanf("%f",n);

{if(n==0)

{printf("Divided by zero.\n");break;}

else

{dv(m,n);break;}

}

case 's':m=sqrt(m);printf("result=%f\n",m);break;

case 'x':m=1.0/m;printf("result=%f\n",m);break;

case 'p':printf("input second number:");scanf("%f",n);p(m,n);break;

case 'c':printf("User return.\n");

return;

case 'q':exit(0);

default:printf("illegal operator.\n");

}

}

}

老师修改过的,很准确

发表评论

评论列表

  • 颜于厌味(2022-06-15 07:41:28)回复取消回复

    d main() { int n; printf("欢迎界面");//欢迎界面 Sleep(1000);//延时 system("cls");//清屏 //菜单界面