當前位置:編程學習大全網 - 源碼下載 - c窗口源代碼

c窗口源代碼

最簡單的模擬定時器:

# include & ltstdio.h & gt

# include & ltconio.h & gt

# include & ltwindows.h & gt

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

//以下是五個自制的函數。

void csh();?//初始化接口

void yinc(int x,int y);?//函數來隱藏光標(y值設置為0來隱藏它)

void吉時();?//計時器運行(每100毫秒改變壹次)

void顏色(短x,短y);?//設置顏色的函數(y設置為0,表示黑色背景)

void gtxy (int x,int y);?//控制光標位置的函數

int main(?)?//主函數

{?csh();

getch();

while(1)

{ Jishi();

?睡眠(100);?//時間間隔100毫秒

?if(kb hit())break;?//按壹個鍵退出循環。

}

返回0;

}

void csh()?//初始化接口

{Color(14,0);//設置淺黃色字符,黑色背景。

printf("\n\n\t?定時器”);

顏色(10,0);?//設置淺綠色文字,黑色背景。

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

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

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

gtxy(10,4);?//光標輸出在屏幕第10列第4行。

顏色(7,0);?//恢復白色字符和黑色背景

printf(" 00:00:00 ");

yinc(1,0);?//隱藏光標(yinc代表隱藏)

返回;

}

void吉時()?//計時器正在運行

{ ms+= 1;

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

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

gtxy(10,4);

顏色(9,0);?//設置淺藍色文字,黑色背景。

如果(m & gt9) printf(" %d:",m);

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

顏色(14,0);?//設置淺黃色字符,黑色背景。

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

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

顏色(12,0);//設置淺紅色字符,黑色背景。

printf("0%d ",毫秒);

}

void gtxy (int x,int y)?//控制光標位置的函數

{坐標位置;

位置。X = x?

位置。Y = y?

SetConsoleCursorPosition(GetStdHandle(STD _ OUTPUT _ HANDLE),pos);

}

空顏色(短前景色= 7,短背景色= 0)?//設置顏色的功能

{手柄?HANDLE = GetStdHandle(STD _ OUTPUT _ HANDLE);

SetConsoleTextAttribute ( handle,ForeColor+background color * 0x 10);

}

void yinc(int x,int y)?//隱藏光標設置(gb代表光標)

{控制臺_光標_信息?gb={x,y };?//x為1-100,Y為0隱藏光標。

SetConsoleCursorInfo(GetStdHandle(STD _ OUTPUT _ HANDLE),& ampGB);

}

  • 上一篇:象棋java遊戲源代碼
  • 下一篇:齊齊哈爾源碼建設站
  • copyright 2024編程學習大全網