查看: 1765|回复: 24
|
关于Visual Studio C++内常用到的DOS指令...
[复制链接]
|
|
发表于 9-3-2006 10:08 PM
|
显示全部楼层
|
|
|
|
|
|
|
发表于 9-3-2006 11:16 PM
|
显示全部楼层
|
|
|
|
|
|
|
发表于 9-3-2006 11:51 PM
|
显示全部楼层
|
|
|
|
|
|
|
发表于 10-3-2006 09:12 AM
|
显示全部楼层
|
|
|
|
|
|
|
发表于 10-3-2006 09:25 AM
|
显示全部楼层
|
|
|
|
|
|
|
发表于 10-3-2006 10:46 AM
|
显示全部楼层
原帖由 AdventChildren 于 9-3-2006 06:15 PM 发表
一般上在windows用C++写简单的DOS程式时:),往往都会一些DOS的指令在程式码里:o。
有一个用来clear screen的程式码为system("cls");
用来pause program的程式码为system("pause");
用来 ...
如果我没记错,在DOS的C/C++可以用clrscr()来clear screen,getch()或getche()来pause screen。
至于visual studio的C++,我就没有找到clrscr()。不过getch()还可以用,library是conio.h。
至于clear screen,我找到的方法的是:
1,CreateFile来控制console,library是windows.h。
HANDLE mycon;
mycon=CreateFile("CONOUT$",GENERIC_READ | GENERIC_WRITE ,FILE_SHARE_WRITE,NULL,OPEN_EXISTING ,0,NULL);
WriteFile(mycon,"test",4,NULL,NULL);
如果有错的话,请帮我更正,谢谢
2,GetStdHandle(STD_OUTPUT_HANDLE)和FillConsoleOutputCharacter,制作一个clear screen的function,library是windows.h和iostream。
http://www.adrianxw.dk/SoftwareSite/Consoles/Consoles2.html |
|
|
|
|
|
|
|
发表于 10-3-2006 11:03 AM
|
显示全部楼层
这里有:
http://support.microsoft.com/kb/q99261/
- /* Standard error macro for reporting API errors */
- #define PERR(bSuccess, api){if(!(bSuccess)) printf("%s:Error %d from %s \
- on line %d\n", __FILE__, GetLastError(), api, __LINE__);}
- void cls( HANDLE hConsole )
- {
- COORD coordScreen = { 0, 0 }; /* here's where we'll home the
- cursor */
- BOOL bSuccess;
- DWORD cCharsWritten;
- CONSOLE_SCREEN_BUFFER_INFO csbi; /* to get buffer info */
- DWORD dwConSize; /* number of character cells in
- the current buffer */
- /* get the number of character cells in the current buffer */
- bSuccess = GetConsoleScreenBufferInfo( hConsole, &csbi );
- PERR( bSuccess, "GetConsoleScreenBufferInfo" );
- dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
- /* fill the entire screen with blanks */
- bSuccess = FillConsoleOutputCharacter( hConsole, (TCHAR) ' ',
- dwConSize, coordScreen, &cCharsWritten );
- PERR( bSuccess, "FillConsoleOutputCharacter" );
- /* get the current text attribute */
- bSuccess = GetConsoleScreenBufferInfo( hConsole, &csbi );
- PERR( bSuccess, "ConsoleScreenBufferInfo" );
- /* now set the buffer's attributes accordingly */
- bSuccess = FillConsoleOutputAttribute( hConsole, csbi.wAttributes,
- dwConSize, coordScreen, &cCharsWritten );
- PERR( bSuccess, "FillConsoleOutputAttribute" );
- /* put the cursor at (0, 0) */
- bSuccess = SetConsoleCursorPosition( hConsole, coordScreen );
- PERR( bSuccess, "SetConsoleCursorPosition" );
- return;
- }
复制代码 |
|
|
|
|
|
|
|
发表于 10-3-2006 11:05 AM
|
显示全部楼层
或是
http://www.sunlightd.com/Windows/FAQ.html#ConsoleClearScreen
- #include <windows.h>
- void clrscr()
- {
- COORD coordScreen = { 0, 0 };
- DWORD cCharsWritten;
- CONSOLE_SCREEN_BUFFER_INFO csbi;
- DWORD dwConSize;
- HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
-
- GetConsoleScreenBufferInfo(hConsole, &csbi);
- dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
- FillConsoleOutputCharacter(hConsole, TEXT(' '), dwConSize,
- coordScreen, &cCharsWritten);
- GetConsoleScreenBufferInfo(hConsole, &csbi);
- FillConsoleOutputAttribute(hConsole, csbi.wAttributes, dwConSize,
- coordScreen, &cCharsWritten);
- SetConsoleCursorPosition(hConsole, coordScreen);
- }
复制代码 |
|
|
|
|
|
|
|

楼主 |
发表于 10-3-2006 03:23 PM
|
显示全部楼层
|
|
|
|
|
|
|

楼主 |
发表于 10-3-2006 03:27 PM
|
显示全部楼层
|
|
|
|
|
|
|

楼主 |
发表于 10-3-2006 03:30 PM
|
显示全部楼层
|
|
|
|
|
|
|
发表于 10-3-2006 05:05 PM
|
显示全部楼层
|
|
|
|
|
|
|
发表于 10-3-2006 10:48 PM
|
显示全部楼层
原帖由 馬拉棧 于 10-3-2006 05:05 PM 发表
听看来好象是Program hardware ...
忘了有ASM的那 Keyword 吧?
__asm
{
push es;
mov ax,0xb800;
mov es,ax;
mov di,0;
mov cx,25*80;
mov ax,0x0720;
rep ... [/quote]
把rep stos 改成rep stosw |
|
|
|
|
|
|
|
发表于 10-3-2006 11:06 PM
|
显示全部楼层
原帖由 馬拉棧 于 10-3-2006 05:05 PM 发表
忘了有ASM的那 Keyword 吧?
__asm
{
push es;
mov ax,0xb800;
mov es,ax;
mov di,0;
mov cx,25*80;
mov ax,0x0720;
rep stos;
pop es;
}
我還沒試過的。回家試了再讓你知道可不可以.
應該是 rep stosw
忘了有 32 bit 的 register 吧 ? 
mov cx, 25 * 80 / 2
mov EAX, 0x07200720
66 D8 20 07 20 07 或者 db 66, mov ax, 0x0720, db 20, db 07
rep STOSD
66 F3 AB 或者 db 66, rep stosw
[ 本帖最后由 flashang 于 10-3-2006 11:13 PM 编辑 ] |
|
|
|
|
|
|
|
发表于 10-3-2006 11:12 PM
|
显示全部楼层
|
|
|
|
|
|
|
发表于 11-3-2006 08:27 AM
|
显示全部楼层
原帖由 flashang 于 10-3-2006 11:06 PM 发表
應該是 rep stosw
忘了有 32 bit 的 register 吧 ? 
mov cx, 25 * 80 / 2
mov EAX, 0x07200720
66 D8 20 07 20 07 或者 db 66, mov ax, 0x0720, db 20, db 07
rep STOSD
66 F3 AB 或 ...
但這就只能夠在 Virtual X86 Mode 執行了。X86 Real Mode 不能夠執行的。 |
|
|
|
|
|
|
|
发表于 11-3-2006 04:37 PM
|
显示全部楼层
原帖由 馬拉棧 于 11-3-2006 08:27 AM 发表
但這就只能夠在 Virtual X86 Mode 執行了。X86 Real Mode 不能夠執行的。
前幾天有個朋友要把一個 dos 的軟件 upgrade 到 win xp 可以使用,
找了整天都找不到 win98 的電腦來測試, 連那個 dos 軟件 '長甚麼樣' 都沒看到...
現在要找 x86 real mode 的電腦 ( os ) 有點困難... 
[ 本帖最后由 flashang 于 11-3-2006 04:39 PM 编辑 ] |
|
|
|
|
|
|
|
发表于 11-3-2006 07:43 PM
|
显示全部楼层
|
|
|
|
|
|
|

楼主 |
发表于 21-3-2006 01:30 AM
|
显示全部楼层
|
|
|
|
|
|
| |
本周最热论坛帖子
|