Sign in to follow this  
Trillian

[Win32] Input message boxes

Recommended Posts

Hello! I'd like to know if the win32 api has a function to pop a message box with text and an input field, a bit like javascript's windows.prompt() . I'm looking for a simple way of getting input from the user. cin does not seem to work with a console created with AllocConsole(). Thank you!

Share this post


Link to post
Share on other sites
Unfortunately, there is no API function for this as part of Windows.

If you'd like to read input from a console that you've opened with AllocConsole(), have a look at the ReadConsole function.

Aside from that, the easiest way to do it is probably to build a simple dialog resource with the input controls you want, and write some wrapper code to display that on demand.

Share this post


Link to post
Share on other sites
Thanks a lot!

I think I'll try the ReadConsole way, msdn defines it like this :
BOOL ReadConsole(
HANDLE hConsoleInput,
LPVOID lpBuffer,
DWORD nNumberOfCharsToRead,
LPDWORD lpNumberOfCharsRead,
LPVOID lpReserved
);


May I ask you how I can get the handle "hConsoleInput" of the console I created with AllocConsole?
EDIT : Would it be GetStdHandle(STD_INPUT_HANDLE) ?

Share this post


Link to post
Share on other sites
Just a small post to tell you I found an easier way of doing it :

AllocConsole();
freopen( "CONOUT$", "w", stdout );
freopen( "CONIN$" , "r", stdin );
std::ios::sync_with_stdio();


That's it! Thanks again

Share this post


Link to post
Share on other sites
If you still want a custom message box though, you could use SetWindowsHookEx.

[Edited by - raz0r on April 1, 2006 9:59:25 PM]

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