Message Queues, Keystroke and Timer issues in a Console Application - Programmer

This is a discussion on Message Queues, Keystroke and Timer issues in a Console Application - Programmer ; I'm writing a console application that uses a timer, and have found that timers can be used without a window by using a GetMessage loop. This is fine, but I also need to be processing user keystrokes at the same ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: Message Queues, Keystroke and Timer issues in a Console Application

  1. Message Queues, Keystroke and Timer issues in a Console Application

    I'm writing a console application that uses a timer, and have found
    that timers can be used without a window by using a GetMessage loop.
    This is fine, but I also need to be processing user keystrokes at the
    same time. I don't want to have to poll for user input and timer
    messages, so I'm wondering if there's a way to use a timer in Windows
    without the GetMessage loop. According to the documentation, even if
    you use a callback function with a timer, the function won't be run
    without a GetMessage and DispatchMessage loop.

    Alternately, is there a way to get a console program to pass
    keystrokes as windows messages instead of through the traditional
    console input functions? That way, I'd be able to get keystrokes
    along with timer messages in the GetMessage loop.

    Or, I could always create a thread to perform the timer cycle. But
    I'd rather avoid multithreading so that I don't have to write the
    whole program with critical section protection.

    Thanks,
    Matt

  2. Re: Message Queues, Keystroke and Timer issues in a Console Application


    "Matthew Hogg" wrote in message
    news:9353ea8e.0404071042.5af14b89@posting.google.c om...
    > I'm writing a console application that uses a timer, and have found
    > that timers can be used without a window by using a GetMessage loop.
    > This is fine, but I also need to be processing user keystrokes at the
    > same time. I don't want to have to poll for user input and timer
    > messages, so I'm wondering if there's a way to use a timer in Windows
    > without the GetMessage loop. According to the documentation, even if
    > you use a callback function with a timer, the function won't be run
    > without a GetMessage and DispatchMessage loop.
    >
    > Alternately, is there a way to get a console program to pass
    > keystrokes as windows messages instead of through the traditional
    > console input functions? That way, I'd be able to get keystrokes
    > along with timer messages in the GetMessage loop.
    >
    > Or, I could always create a thread to perform the timer cycle. But
    > I'd rather avoid multithreading so that I don't have to write the
    > whole program with critical section protection.


    Well... if multitasking (with the message loop peeker setting
    an event which the main thread notices) then, if you target
    WinNT + OS variants then you have the option of using
    Waitable Timers.

    Another option would be to poll and check for a specific
    GetTimerTick() value...

    Also, what's wrong with the TimerProc variant of SetTimer() use?

    - Sten




+ Reply to Thread