Sakura
Thú CƯng :
Số bài viết : 1124 Điểm : 1688 Được cảm ơn : 35 Ngày sinh : 03/11/1990 Tham gia ngày : 16/03/2010 Tuổi : 34 Đến từ : Bình Dương Ngề nghiệp : IT Student
| Tiêu đề: Đoạn code OS Tuần 3 21/3/2011, 22:39 | |
| Ai chưa có thì copy về nha! - Code:
-
#include <stdio.h> #include <stdlib.h> #include <conio.h> #include <Windows.h> #include <iostream>
using namespace std;
void Clrscr(void) { CONSOLE_SCREEN_BUFFER_INFO csbiInfo; HANDLE hConsoleOut; COORD Home = {0,0}; DWORD dummy;
hConsoleOut = GetStdHandle(STD_OUTPUT_HANDLE); GetConsoleScreenBufferInfo(hConsoleOut,&csbiInfo);
FillConsoleOutputCharacter(hConsoleOut,' ',csbiInfo.dwSize.X * csbiInfo.dwSize.Y,Home,&dummy); csbiInfo.dwCursorPosition.X = 0; csbiInfo.dwCursorPosition.Y = 0; SetConsoleCursorPosition(hConsoleOut,csbiInfo.dwCursorPosition); }
void GotoXY(short x,short y) { HANDLE hConsoleOutput; COORD Cursor_an_Pos = { x,y}; hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleCursorPosition(hConsoleOutput , Cursor_an_Pos); }
void SetColor(WORD color) { HANDLE hConsoleOutput; hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO screen_buffer_info; GetConsoleScreenBufferInfo(hConsoleOutput, &screen_buffer_info);
WORD wAttributes = screen_buffer_info.wAttributes; color &= 0x000f; wAttributes &= 0xfff0; wAttributes |= color;
SetConsoleTextAttribute(hConsoleOutput, wAttributes); }
void SetBGColor(WORD color) { HANDLE hConsoleOutput; hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO screen_buffer_info; GetConsoleScreenBufferInfo(hConsoleOutput, &screen_buffer_info);
WORD wAttributes = screen_buffer_info.wAttributes; color &= 0x000f; color <<= 4; wAttributes &= 0xff0f; wAttributes |= color;
SetConsoleTextAttribute(hConsoleOutput, wAttributes); }
int WhereX( void ) { HANDLE hConsoleOutput; hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE); CONSOLE_SCREEN_BUFFER_INFO coninfo; GetConsoleScreenBufferInfo (hConsoleOutput, &coninfo); return coninfo.dwCursorPosition.X; }
int WhereY( void ) { HANDLE hConsoleOutput; hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE); CONSOLE_SCREEN_BUFFER_INFO coninfo; GetConsoleScreenBufferInfo (hConsoleOutput, &coninfo); return coninfo.dwCursorPosition.Y; }
int MaxX() { CONSOLE_SCREEN_BUFFER_INFO csbiInfo; return csbiInfo.dwSize.X; }
int MaxY() { //CONSOLE_SCREEN_BUFFER_INFO csbiInfo; //return csbiInfo.dwSize.Y; return 20; }
int x = -1; int huongx = 0;
void DiChuyenNgang() { if(x < MaxX() - 1 && huongx == 0) { x++; } else { x--; huongx = 1; if(x == 0) huongx = 0; } GotoXY(x, 0); cout<<"X"; Sleep(20); Clrscr(); }
int y = -1; int huongy = 0;
void DiChuyenDoc() { if(y < MaxY() - 1 && huongy == 0) { y++; } else { y--; huongy = 1; if(y == 0) huongy = 0; } GotoXY(0 ,y); cout<<"Y"; Sleep(20); Clrscr(); }
int main() { do { DiChuyenNgang(); DiChuyenDoc(); } while (true); _getch(); } |
|