Jump to content
  • Advertisement
Sign in to follow this  
Ned_K

Associating a Window Procedure with the Console?

This topic is 3427 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

Is it possible to create a peekmessage loop for the console that dispatches console messages to a window procedure? Anyone have some simple code showing this or a link to a discussion elsewhere? Thanks!

Share this post


Link to post
Share on other sites
Advertisement
This is not possible. The console is a special invocation of cmd.exe and you are really limited to what you can do with it.

The closest thing you can do to process console events is setup a console control handler using SetConsoleCtrlHandler. Here's a simply example showing it:


#include <windows.h>
#include <stdio.h>

HANDLE hExitEvent = 0;

BOOL __stdcall ConsoleHandler(DWORD ConsoleEvent)
{
switch(ConsoleEvent)
{
case CTRL_LOGOFF_EVENT:
case CTRL_C_EVENT:
case CTRL_BREAK_EVENT:
case CTRL_CLOSE_EVENT:
case CTRL_SHUTDOWN_EVENT:
{
SetEvent(hExitEvent);
return TRUE;
}
}
return FALSE;
}

int main(int argc, char * argv[])
{
hExitEvent = CreateEvent(0, TRUE, FALSE, 0);
SetConsoleCtrlHandler(ConsoleHandler, TRUE);
WaitForSingleObject(hExitEvent, INFINITE);
SetConsoleCtrlHandler(ConsoleHandler, FALSE);
return 0;
}



Normally, if you did not set the console control handler, you would get a "This application is not responding" dialog when you tried to close it. Since the close event is properly handled now, you can gracefully exit the console in any number of ways (ctrl + c, close the window, on demand).

Share this post


Link to post
Share on other sites
Judging from your recent posts, it sounds like you want to create a "pretty" console window. If so, you might want to look at the source code for similar projects like this one.

Share this post


Link to post
Share on other sites
Quote:
Original post by Drew_Benton
This is not possible.


Of course it's possible and very classic (for timers or other)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!