delphi3000.com - the free delphi knowledge platform
delphi3000.com - the free delphi knowledge platform
Have a look at your member-status

connecting people's knowledge


  - Recent ArticlesRSS feed for Recent Articles on delphi3000.com
  - List of All Articles
  - Top Viewed Articles
  - Articles (+Attachem.)
  - Articles Of Interest
  - Categories
  - Top Uploader
  - Search
  - Index

  - My Home
  - Submit an Article
  - My Articles
  - My Personal Data
  - My Bookmarks
  - Activities
  - Login/Logout

  - Sign Up
  - Why Sign Up
  - Newsletter

  - Press
  - Advertise

  - Contact
  - Feedback



Community
Borland
ClubeDelphi
Dr. Bob
UK-BUG
Delphi Meetings
Planeta Delphi








Share this article with friendsShare this article with friends
Rate this articleRate this article - to keep the quality of delphi3000.com !
Comment this article or read through previous comments (1)


How to use the old (Win)DOS routines in win32 console applicationsFormat this article printer-friendly!Bookmark function is only available for registered users!
console applications
Product:
Delphi all versions
Category:
System
Skill Level:
Scoring:
Last Update:
12/24/2001
Search Keys:
delphi delphi3000 article borland vcl code-snippet dos, keypress, gotoxy
Times Scored:
13
Visits:
6533
Uploader: Periklis Koutsogiannis
Company:
Reference: N/A
 
Question/Problem/Abstract:
Have you ever tried to use the gotoxy or keypress function in your win32 applications ?
Answer:



Unit Win32_Dos;

Interface

{code used to emulate old dos calls}

Function GetKey: char;
Procedure GotoXY (X, Y: integer);
Function WhereX: integer;
Function WhereY: integer;
Procedure ClrScr;
Procedure SelectCursor (CurOn: boolean);
Procedure ClearLine;
Function KeyWaiting: boolean;

Implementation

Uses
    Windows;

Var
    KeyData: integer = -1;

Function KeyWaiting: boolean;
Var
    InputEvents: DWORD;
    InputEventsRead: DWORD;
    KeyBuf: TInputRecord;
Begin
    If KeyData < 0 Then
        Begin
            GetNumberOfConsoleInputEvents (GetStdHandle (STD_INPUT_HANDLE), InputEvents);
            If InputEvents <> 0 Then
                Begin
                    ReadConsoleInput (GetStdHandle (STD_INPUT_HANDLE), KeyBuf, 1, InputEventsRead);
                    If (KeyBuf.EventType = KEY_EVENT) And (KeyBuf.Event.KeyEvent.bKeyDown) Then
                        Begin
                            KeyData := integer (KeyBuf.Event.KeyEvent.AsciiChar);
                        End;
                End;
        End;
    KeyWaiting := KeyData >= 0;
End;

Function GetKey: char;
Begin
    If KeyData < 0 Then
        While Not (KeyWaiting) Do {nop}
            ;
    If KeyData >= 0 Then
        getkey := char (KeyData)
    Else
        getkey := #255;
    KeyData := -1;
End;

Procedure GotoXY (X, Y: integer);
Var
    Cord: tCoord;
Begin
    Cord.X := x;
    Cord.Y := y;
    SetConsoleCursorPosition (GetStdHandle (STD_OUTPUT_HANDLE), Cord);
End;

Function WhereX: integer;
Var
    Cord: tCoord;
    Info: tConsoleScreenBufferInfo;
Begin
    GetConsoleScreenBufferInfo (GetStdHandle (STD_OUTPUT_HANDLE), Info);
    result := Info.dwCursorPosition.X;
End;

Function WhereY: integer;
Var
    Cord: tCoord;
    Info: tConsoleScreenBufferInfo;
Begin
    GetConsoleScreenBufferInfo (GetStdHandle (STD_OUTPUT_HANDLE), Info);
    result := Info.dwCursorPosition.Y;
End;

Procedure ClrScr;
Var
    Cord: tCoord;
    CharactersWritten: Cardinal;
    Info: tConsoleScreenBufferInfo;
    Size: Cardinal;
Begin
    Cord.X := 0;
    Cord.Y := 0;
    GetConsoleScreenBufferInfo (GetStdHandle (STD_OUTPUT_HANDLE), Info);
    Size := succ (Info.dwSize.X) * succ (Info.dwSize.Y);
    FillConsoleOutputCharacter (GetStdHandle (STD_OUTPUT_HANDLE), ' ', Size, Cord, CharactersWritten);
End;

Procedure SelectCursor (CurOn: boolean);
Var
    Info: tConsoleCursorInfo;
Begin
    GetConsoleCursorInfo (GetStdHandle (STD_OUTPUT_HANDLE), Info);
    If CurOn Then
        Info.bVisible := true
    Else
        Info.bVisible := false;
    SetConsoleCursorInfo (GetStdHandle (STD_OUTPUT_HANDLE), Info);
End;

Procedure ClearLine;
Var
    i: integer;
    Info: tConsoleScreenBufferInfo;
Begin
    SelectCursor (FALSE);
    GetConsoleScreenBufferInfo (GetStdHandle (STD_OUTPUT_HANDLE), Info);
    GotoXY (0, WhereY);
    For i := 0 To Info.dwSize.X - 2 Do
        Write (' ');
    GotoXY (0, WhereY);
    SelectCursor (TRUE);
End;

End.





Please rate this article!
Skill level:
BeginnerExpert

Useful:
No!Very!

Overall rating:
PoorExcellent



Comments to this article
Write a new comment
thanks
    Michael Stum (Mar 7 2002 11:44AM)

Thanks, these helped a lot.
Respond














 
Sign up to consume product discounts for Bronze memberships !

read more


   


  Community Ad of
S. Carter
 
   














 







     
  Copyright © 2000 - 2007 delphi3000.com - All rights reserved. Terms of use. || Privacy
delphi3000.com is a service by bluestep.com IT-Services GmbH (Vienna)