Click here to Skip to main content
16,004,969 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Array Lengths? Pin
David Crow9-Oct-07 16:43
David Crow9-Oct-07 16:43 
GeneralRe: Array Lengths? Pin
Michael1019-Oct-07 16:55
Michael1019-Oct-07 16:55 
AnswerRe: Array Lengths? Pin
jhwurmbach9-Oct-07 23:02
jhwurmbach9-Oct-07 23:02 
QuestionListView, tile mode & multiple lines - how??? Pin
Vlasta_9-Oct-07 12:25
Vlasta_9-Oct-07 12:25 
AnswerRe: ListView, tile mode & multiple lines - how??? Pin
Roger Broomfield9-Oct-07 20:13
Roger Broomfield9-Oct-07 20:13 
GeneralRe: ListView, tile mode & multiple lines - how??? Pin
Vlasta_9-Oct-07 22:45
Vlasta_9-Oct-07 22:45 
QuestionOverlapping queuing times - best method? Pin
Iain Clarke, Warrior Programmer9-Oct-07 10:02
Iain Clarke, Warrior Programmer9-Oct-07 10:02 
AnswerRe: Overlapping queuing times - best method? Pin
Leslie Sanford9-Oct-07 14:39
Leslie Sanford9-Oct-07 14:39 
Iain Clarke wrote:
I have a problem I need to solve - preferably elegantly!

I have a series of inputs to my software.

Imagine... If Input A - turn an output on in 5 seconds for 2 second.
If Input B, turn an output on in 3 seconds for 2.5 seconds.


How many outputs are involved? Do Input A and B control the same output?

You could have a queue of inputs, each with an ON time span. First, remove an input from the queue and turn the output on for the specified duration (you'll have to decide when it's appropriate to check the queue for inputs). Set a timer to notify you when that duration has expired. When you get a timer notification notifying you that the current input has expired, get the next input and do the same thing again. This assumes that only one output can be turned on at any one time.

If each input controls its own output, then I would approach it differently. I'd set up a timer to tick periodically, say every 100ms. I'd have a queue for the inputs, just as before. I'd check the queue for inputs in response to timer ticks. If there are any inputs in the queue, I'd remove the first one, turn on an output, and place the input into a second queue. The second queue would be a priority queue with the inputs sorted by their duration.

When an input is placed into the priority queue and the queue was previously empty. I'd reset an accumulator variable to zero. Now in response to each timer tick, I'd add the elapsed time to the accumulator (probably use an unsigned long for this). On subsequent timer ticks, if the priority queue is not empty, I subtract the accumulator from the first item's duration. If the result is less than or equal to zero, I remove the item from the queue and turn off its output. I repeat this action until the priority queue is either empty or the duration of the first item in the priority queue is greater than my accumulator.

So in response to each timer tick, I'd process any inputs in the input queue, update my accumulator, and process any items in the priority queue that have expired. Actually, I'd probably do that in reverse order. Process the priority queue first, then the input queue.
GeneralRe: Overlapping queuing times - best method? Pin
Iain Clarke, Warrior Programmer11-Oct-07 6:05
Iain Clarke, Warrior Programmer11-Oct-07 6:05 
GeneralRe: Overlapping queuing times - best method? Pin
El Corazon11-Oct-07 6:35
El Corazon11-Oct-07 6:35 
AnswerRe: Overlapping queuing times - best method? Pin
El Corazon9-Oct-07 15:04
El Corazon9-Oct-07 15:04 
GeneralRe: Overlapping queuing times - best method? Pin
Iain Clarke, Warrior Programmer11-Oct-07 6:06
Iain Clarke, Warrior Programmer11-Oct-07 6:06 
QuestionHow to get pointer to client area in CDialog in SDI app?? Pin
zarraza9-Oct-07 9:22
zarraza9-Oct-07 9:22 
AnswerRe: How to get pointer to client area in CDialog in SDI app?? Pin
Iain Clarke, Warrior Programmer9-Oct-07 10:07
Iain Clarke, Warrior Programmer9-Oct-07 10:07 
GeneralRe: How to get pointer to client area in CDialog in SDI app?? Pin
zarraza9-Oct-07 10:37
zarraza9-Oct-07 10:37 
GeneralRe: How to get pointer to client area in CDialog in SDI app?? Pin
Iain Clarke, Warrior Programmer9-Oct-07 11:05
Iain Clarke, Warrior Programmer9-Oct-07 11:05 
GeneralRe: How to get pointer to client area in CDialog in SDI app?? Pin
zarraza9-Oct-07 11:25
zarraza9-Oct-07 11:25 
GeneralRe: How to get pointer to client area in CDialog in SDI app?? Pin
Iain Clarke, Warrior Programmer9-Oct-07 11:30
Iain Clarke, Warrior Programmer9-Oct-07 11:30 
GeneralRe: How to get pointer to client area in CDialog in SDI app?? Pin
zarraza9-Oct-07 11:50
zarraza9-Oct-07 11:50 
GeneralRe: How to get pointer to client area in CDialog in SDI app?? Pin
Roger Broomfield9-Oct-07 15:29
Roger Broomfield9-Oct-07 15:29 
GeneralRe: How to get pointer to client area in CDialog in SDI app?? Pin
zarraza10-Oct-07 11:41
zarraza10-Oct-07 11:41 
Questionvc++code for designing a scientific calculator Pin
AvishekBanerjee9-Oct-07 5:24
AvishekBanerjee9-Oct-07 5:24 
AnswerRe: vc++code for designing a scientific calculator Pin
David Crow9-Oct-07 5:42
David Crow9-Oct-07 5:42 
AnswerRe: vc++code for designing a scientific calculator Pin
toxcct9-Oct-07 5:44
toxcct9-Oct-07 5:44 
AnswerRe: vc++code for designing a scientific calculator Pin
Maximilien9-Oct-07 6:45
Maximilien9-Oct-07 6:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.