• Advertisement
Sign in to follow this  

[Win32] Input message boxes

This topic is 4346 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Sign in to follow this  

  • Advertisement