Cin without console

Hi all!

I'm using DevC++ to develop my program and I started my project as a Console Application. Then I changed in the project Options the type to Win32 GUI ,in order to hide the console (or FreeConsole() that does the same).

But when I use a cin in the program, nothing happens. I mean, I know as the console is hidden I can't work with cin (which needs the console to work), so: wich method should I use to get a keyboard input?

Thank you in advance,
You cannot get console input without a console.

If you are developing a GUI application, you need to listen for key events. How you do that is wholly dependant on your GUI toolkit.

What TK are you using to create your program? Windows API? FLTK? Qt? wxWidgets?
I'm not really sure, i just have the simple " int main( int argc, char** argv )" program, you know, a basic console application :S

But I think I can use windows api because is a simple win32 GUI, how should I do it?
you could use the GetAsyncKeyState() function... to make the console scan the keys the user is pressing. Example: the user presses "comp"-> you program opens My Computer for him.
second example... the user presses "show"-> you show the console.. or "hide" to hide it. That ca be done :) I'm not sure though that that's what you need
+1 to what Duoas said.

GetAsyncKeyState is only if you need the realtime state of a specific key (read: 99% of the time this is not really what you need)

But I think I can use windows api because is a simple win32 GUI, how should I do it?


How did you create this GUI? Surely you must have done something to create a window somewhere?

WinAPI programs typically have WinMain() instead of main(), but I don't think it's a requirement.

If you're using WinAPI, your window must have a callback procedure to handle messages. Just catch the WM_KEYDOWN or WM_CHAR messages and process them.
I think that people use GetAsyncKeyState() far more than is right. It is not a well-behaved function, especially as there are almost always better ways to get input.

Do as Disch suggested, and catch the WM_KEYDOWN or WM_CHAR events in your window proc.

Do you need help with this?
Topic archived. No new replies allowed.