erbi_lucifer吧 关注:406贴子:3,325

【C语言】【控制台】【小程序】--一些写着玩的东东……

只看楼主收藏回复


一楼度娘……

过完暑假,我又回来了……



1楼2012-09-01 21:44回复

    【C语言】【控制台】【小程序】
    之前闲着没事写的东东,都控制在50行代码之内……
    有很简单的直接printf,也有使用windows API编程的,SAPI的,GDI+的等等……
    


    2楼2012-09-01 21:48
    回复
      【001】【printf.c】
      直接使用printf打印……最简单的

      


      3楼2012-09-01 21:59
      回复
        【代码】:
        #include <stdio.h>
        int main()
        {
        system("color 0C");
        printf(" \n\n");
        printf("    / \\./ \\/\\_   I Hand You \n");
        printf("  __{^\\_ _}_  ) }/^\\    A Rose...\n");
        printf(" / /\\_/^\\._}_/ // / \n");
        printf(" ( (__{(@)}\\__}.//_/__A___A______A_______A______A____\n");
        printf(" \\__/{/(_)\\_} )\\\\ \\\\---v----V-----V--Y----v---Y----- \n");
        printf("  (  (__)_)_/ )\\ \\> \n");
        printf("   \\__/   \\__/\\/\\/ \n");
        printf("    \\__,--\'  \n");
        getchar();
        return 0;
        }
        //搜狗输入法有很多这种图像,可以试试其他的……
        


        4楼2012-09-01 22:01
        回复

          【002】【SetCurrent.c】移动光标
          截图:无
          【源代码】
          #include<windows.h>
          #include<stdio.h>
          int main(){
          int i=0;
          printf("正在移动您的鼠标光标……");
          for(;i<1000;i++)
          {
          SetCursorPos(i,200);
          Sleep(10);
          }
          printf("移动完成。");
          getchar();
          return 0;
          }
          


          5楼2012-09-01 22:07
          回复

            【003】【打字效果.c】逐个字符输出,文件名必须是打字效果.c
            截图:无
            【源代码】
            #include<stdio.h>
            #include<Windows.h> int main(void)
            {
            FILE *p;char mg; p=fopen("打字效果.c","r");
            if (p == NULL)
            {
            perror ("File open error!\n");
            return 0;
            }
            while ((mg=fgetc (p)) != EOF)
            {
            Sleep(100);
            putchar(mg);
            }
            fclose(p);
            getchar();
            return 0;
            }
            


            6楼2012-09-01 22:11
            回复

              【004】【更换桌面壁纸.c】如题
              截图:无
              【源代码】
              #include <stdio.h>
              #include <windows.h>
              int main()
              {
              char input[MAX_PATH];
              printf("\n\n\t\t\t【更换桌面壁纸】\n\n");
              printf("\n\n请输入图片的全路径:");
              gets(input);
              if(SystemParametersInfoA(SPI_SETDESKWALLPAPER, 0,input,SPIF_UPDATEINIFILE+SPIF_SENDWININICHANGE ))
              printf("\n\n更换壁纸完成,回车退出");
              else
              printf("\n\n更换失败,请确定图片全路径没有错误。");
              getchar();
              }
              


              7楼2012-09-01 22:13
              回复

                【005】【计算机名和用户名.c】获取信息
                截图:这个不打算给……
                【源代码】
                #include <stdio.h>
                #include <windows.h>
                int main()
                {
                char Jisuanjiname[MAX_COMPUTERNAME_LENGTH+1];
                char susername[30];
                DWORD jisuanjiname=MAX_COMPUTERNAME_LENGTH+1;
                DWORD username=30; GetComputerNameA(Jisuanjiname,&jisuanjiname);
                printf("\t\t计算机名:%s\n",Jisuanjiname);
                GetUserNameA(susername,&username);
                printf("\t\t当前用户名:%s\n",susername);
                getchar();
                return 0;
                }
                


                8楼2012-09-01 22:17
                回复

                  【006】【练习dos命令.c】如题
                  截图:无
                  【源代码】
                  #include <stdio.h>
                  #include <windows.h>
                  #include<string.h>
                  /*
                  练习dos命令,可以试试以下命令:清屏:cls
                  连接诊断:ping www.baidu.com
                  查IP:ipconfig
                  颜色:color 0A
                  */
                  int main()
                  {
                  char input[MAX_PATH];
                  while(1){
                  printf("\n\n请输入指令 :");
                  gets(input);
                  if(strcmp(input,"quit")==0)return;
                  else system(input);
                  }
                  }

                  


                  9楼2012-09-01 22:19
                  回复

                    【007】【列目录.c】利用tree.exe
                    截图:无
                    【源代码】
                    #include<stdio.h>
                    #include<Windows.h>
                    /*利用cmd命令,也就是带参数执行 system32下的tree.exe*/
                    int main()
                    {
                    char path[MAX_PATH]={0},info[MAX_PATH+10]={0};
                    int type;
                    printf("\n\n\t\t【目录树形图】\n\n\n");
                    printf("请输入路径名:");
                    gets(path);
                    printf("请选择:\n\n1.列目录\n2.列目录与文件\n\n选择:");
                    scanf("%d",&type);
                    if(type==1){
                    sprintf(info,"tree %s >tree_info.txt",path);
                    }
                    else{
                    sprintf(info,"tree %s /f >tree_info.txt",path);
                    }
                    printf("正在处理,请稍等:");
                    system(info);
                    system("tree_info.txt");
                    printf("完成!");
                    getchar();
                    return 0;
                    }

                    


                    10楼2012-09-01 22:22
                    回复

                      【008】【枚举系统所有字体.c】
                      截图:无
                      【源代码】
                      #include<Windows.h>
                      #include<stdio.h>
                      #include<tchar.h>
                      char *fontname;
                      int CALLBACK EnumFontFaProc(LPENUMLOGFONT lpelf,LPNEWTEXTMETRIC lpntm,DWORD nFontType,long lparam){
                      fontname=(char*)malloc(sizeof(char)*32);
                      WideCharToMultiByte(0,0,lpelf->elfLogFont.lfFaceName,32,fontname,32,0,0);
                      printf("%s\n",fontname);
                      free(fontname);
                      return 1;
                      }
                      int main()
                      {
                      LOGFONT lf;
                      lf.lfCharSet=DEFAULT_CHARSET;//初始化
                      _tcscpy(lf.lfFaceName,L"");
                      printf("\n\n*******************枚举系统所有字体******************\n\n");
                      EnumFontFamiliesEx(GetDC(NULL),&lf,(FONTENUMPROCW)EnumFontFaProc,0,0);
                      printf("\n\n*******************系统所有字体枚举完成******************\n\n");
                      getchar();
                      return 0;
                      }
                      


                      11楼2012-09-01 22:24
                      回复

                        【009】【内存监控.c】动态监控
                        截图:

                        


                        13楼2012-09-01 22:28
                        回复

                          【源代码】
                          #include <stdio.h>
                          #include <windows.h>
                          int Goon=1;
                          DWORD WINAPI ThreadFunc( LPVOID lpParam ) //线程函数
                          {
                          char szBuff[128];
                          MEMORYSTATUS ms;
                          char m_szText[300];
                          while(Goon==1){
                          // 取得内存状态信息
                          GlobalMemoryStatus(&ms);
                          system("cls");
                          m_szText[0] = '\0';
                          sprintf(szBuff, "\n 物理内存总量: %-5d MB", ms.dwTotalPhys/(1024*1024));
                          strcat(m_szText, szBuff);
                          sprintf(szBuff, "\n 可用物理内存: %-5d MB", ms.dwAvailPhys/(1024*1024));
                          strcat(m_szText, szBuff);
                          sprintf(szBuff, "\n\n 虚拟内存总量: %-5d MB", ms.dwTotalVirtual/(1024*1024));
                          strcat(m_szText, szBuff);
                          sprintf(szBuff, "\n 可用虚拟内存: %-5d MB", ms.dwAvailVirtual/(1024*1024));
                          strcat(m_szText, szBuff);
                          sprintf(szBuff, "\n\n 内存使用率: %d%%", ms.dwMemoryLoad);
                          strcat(m_szText, szBuff); printf("%s",m_szText);
                          Sleep(500);
                          }
                          return 0;
                          }
                          int main(int argc, char* argv[])
                          {
                          DWORD dwThreadId, dwThrdParam = 1;
                          CloseHandle(CreateThread( NULL,0,ThreadFunc,&dwThrdParam, 0,&dwThreadId));//创建并关闭线程
                          getchar();
                          Goon=0;
                          return 0;
                          }
                          


                          14楼2012-09-01 22:28
                          回复

                            【010】【系统时间.c】动态显示系统时间
                            截图:

                            


                            15楼2012-09-01 22:30
                            回复

                              【源代码】
                              #include <stdio.h>
                              #include <windows.h>
                              int main()
                              {
                              SYSTEMTIME time1;
                              while(1){
                              GetLocalTime(&time1);
                              printf("\t\t**********************************************");
                              printf("\n\n\n\t\t\t当前时间:%d 时 %d 分 %d 秒\n\n\n",time1.wHour,time1.wMinute,time1.wSecond);
                              printf("\t\t**********************************************");
                              Sleep(1000);
                              system("cls");
                              }
                              getchar();
                              return 0;
                              }
                              


                              16楼2012-09-01 22:30
                              回复