Sign in to follow this  
Felon_pro

old functions of TC++

Recommended Posts

how do i access some old functions of TC++ (like getch(),gotoxy()) using Devcpp? i'm really used to getch() and cannot afford to stop using it (unless there is a better alternative). The devpak i got from devpaks.org for conio2 is not being recognized by my Pack Man.

Share this post


Link to post
Share on other sites
Those functions were provided by (very old and outdated) Turbo C++ libraries. They are no longer in use. If you absolutely must use them, you'll probably have to revert back to Turbo C++. However, I would strongly recommend learning the modern equivalents - especially if you are wanting to learn C++ and not C. C++ has come a very long way since TC++'s heyday.

Share this post


Link to post
Share on other sites
These are the Win32 API calls to read or write to the screen, move the cursor or respond to the keyboard or mouse.

ReadConsoleInput would be the starting point to look at to re-implement getch(), although it is a bit more involved than just using getch(). I don't have the code to hand, but I implemented a WinGetch() once by entering a loop that polled ReadConsoleInput until it got a keyboard event, then returned the AsciiChar member of the KEY_EVENT_RECORD structure.

If you were to use Visual C++ Express 2005, there is a <conio.h> that provides _getch() instead, which works exactly like you are used to.

[EDIT] Found it...


#include <windows.h>

HANDLE hIn;
INPUT_RECORD InRec;
DWORD NumRead;

void WinGetchAcquire()
{
hIn=GetStdHandle(STD_INPUT_HANDLE);
}

int WinGetch()
{
while(true)
{
ReadConsoleInput(hIn,&InRec,1,&NumRead);

if(InRec.EventType==KEY_EVENT)
{
if(InRec.Event.KeyEvent.bKeyDown==0) continue;

return InRec.Event.KeyEvent.uChar.AsciiChar;
}
}

return 0; // supress warning
}



You call WinGetchAcquire() somewhere at the start of your console app, then WinGetch() will wait for a keypress and return the ascii code.

[Edited by - EasilyConfused on September 28, 2006 5:49:02 AM]

Share this post


Link to post
Share on other sites
thanks..but... WOW.
i just could NOT comprehend.
what does
HANDLE hIn;
mean?
is it a macro like #define ?
i am SO NEW to Dev cpp.. (i got it 4 days ago)
any one heard of function "delay(int no_of_milliseconds)". it is used in TC++.
i wanna know which function can delay execution by say sum number of milliseconds.

Share this post


Link to post
Share on other sites
HANDLE is a type defined by the Windows library. Its actual type is not important. The important thing to understand is that Windows manages resources internally and a HANDLE acts like a kind of pointer to a resource that Windows is managing.

I appreciate that the above code may be a bit daunting if you are new to C++ and I posted it more as a "use as is for now" snippet to give you getch() back in a hurry. Perhaps that was unwise [smile].

Your query about delay() has been answered by someone in the other thread you posted. It is a bit frowned upon to double-post questions on these forums.

I see from another post you are now proposing to switch compilers. I'll repeat: If you get the free Visual Studio 2005 Express from Microsoft, you get <conio.h> which provides _getch().

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this