An API for getch()...

Does Windows have an API as an equivalent for the C getch()? I am trying to iterate through a data file having over a hundred records. The application works but only the last record is shown on the corresponding text boxes. I need to stop as each record is read and then the next one read and printed on a key being pressed. Have done it in C using getch() but I cant seem to find the requisite API for Visual C++. Any help will be appreciated.

Comments

Well, I hesitated all day because my thoughts weren't quite along the getch() line, but no one else has weighed in and you did say any help...:-)

The first thing that comes to mind is a MessageBox(), but that would stick an object in your viewing field, unless you made the MessageBox your vehicle for the information itself. This doesn't seem feasible for more than a small amount of data.

Next would be to build your own version of getch() with an infinite loop that includes a break statement based on an event. But that would be very inefficient in a windows program.

That leaves the thought of simply building a routine that steps through the records based on an event, such as a keystroke, etc. Maybe something like:

[code] case IDC_NEXT: DisplayRec[rec]; rec++; break;[/code]

As a final thought, perhaps you could display the data fields in a dialog which upon return gathers the next record and reinvokes itself.

Hope this was of some help, maybe even in sparking a totally separate idea...

: Well, I hesitated all day because my thoughts weren't quite along : the getch() line, but no one else has weighed in and you did say : any help...:-): : The first thing that comes to mind is a MessageBox(), but that would : stick an object in your viewing field, unless you made the : MessageBox your vehicle for the information itself. This doesn't : seem feasible for more than a small amount of data.: : Next would be to build your own version of getch() with an infinite : loop that includes a break statement based on an event. But that : would be very inefficient in a windows program.: : That leaves the thought of simply building a routine that steps : through the records based on an event, such as a keystroke, etc. : Maybe something like:: : [code]: : case IDC_NEXT:: DisplayRec[rec];: rec++;: break;: [/code]: : : As a final thought, perhaps you could display the data fields in a : dialog which upon return gathers the next record and reinvokes : itself.: : Hope this was of some help, maybe even in sparking a totally : separate idea...: : Take Care,: Ed: :This is my code for the routine:

: You might want to check out ReadConsoleInput():: : http://msdn.microsoft.com/en-us/library/ms684961(VS.85).aspx: : (I tried to make the above an active link, but PH didn't link it : correctly, at least not in preview. Sorry, you'll have to cut and : paste.): : ReadConsoleInput() appears to allow for things like key events etc.: : Sorry I couldn't be of more help.: : Take Care,: Ed: :Couldn't be of help?? You don't know what you did for me right now with that link. I was checking it out when I stumbled upon all the API's equivalent to C run time functions. It is amazing. In case you are interested here is the link for it.

Great list! According to what I see, the function I suggested should work for _getch, but isn't recommended for getch. I wonder what the difference is. Also, in looking down the list, I see _kbhit, which I thought for moment might be along the line of what you wanted, but the PeekConsoleInput returns immediately, while the ReadConsoleInput waits:

"The function does not return until at least one input record has been read."

I might play with this myself a little later...

BTW, the only trouble with your link is the extraneous period at the end. Perhaps the link won't work correctly until the post is submitted.

The three above links should all go to the same page. In preview the first one is correct, but the second one wants to bring me back to this message, while the third one also points to the correct page.

For clarity of what I used above, the first is the link=http method in the Style Guide. The second is the link method without the = and the third is just the url.

If the above links alter from the preview description, I will make note here:

:Thanks a pile for the info Lundin but I think I did not make my problem clear in my previous post. I read the first record from my file and then want the application to halt till a key is pressed and then the second record to be read and displayed in the Dialog Box. And so on. The actual key pressed is not material. It is the event that matters. Very much like what the _getch() function does. Hope you can come across with some idea as to how this can be done. I don't plan to move on till I have crossed this problem from my list.