Solved

Blinking Button?

Posted on 2004-08-03
15
300 Views
Last Modified: 2008-03-06
Ok, I would have expected a search on this to yield all kinds of results but I'm not finding much.  Does c++ support using an animated GIF as a resource type or will I have to code timers and what not to create a flashing button out of two graphics?  I'm using this:

http://www.codeproject.com/buttonctrl/cbuttonst.asp

to create my graphical buttons. I've modified that code to support additional requirements I have (repeat while mouse down, a disabled state BITMAP to name a few) but I'd like to be able to have an "active state" whereby the image is flashing (like an LED) while an operation is being performed.  An animated GIF would be perfect, but I'm guessing that would be too easy :)

What's the most appropriate approach?

thanks
-Paul
0
Comment
Question by:PMH4514
  • 8
  • 6
15 Comments
 
LVL 11

Expert Comment

by:KurtVon
ID: 11704676
Well, there are uncompressed AVI files that can be used for much the same purpose.  For that you would need an AVI control (the same as the one used for the "flying files" animation when you copy a file).  You can put a control on the button I suppose.

Otherwise, yeah, you'd have to handle it like a flashing cursor, with a timer message switching between the two images.  Actually, I think this is the easier of the two methods.

Hope this helps.
0
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 50 total points
ID: 11705452
You can create a timer inside your window or dialog, and change (or simply hide) button bitmap on the fly.
0
 

Author Comment

by:PMH4514
ID: 11719264
so, sorry to follow up on a closed thread, but just to be sure here, I feel like I'm having to create alot of member variables to support this.

1. I need a timer mechanism, so I need a member variable to track the timer ID
2. I need a member variable that flags if this UI element should be blinking in the first place.
3. I need a member variable that tracks if the UI element is currently "on" or "off" so that the next iteration of the timer, I can say "if on then off else on"

4. I need a AddBlinkButtonTimer(), RemoveBlinkButtonTimer() and code in my OnTimer() method to perform the appropriate actions based on the values of those described member variables.

it would then stand to follow, that for each "blinking" UI element (there is one, but I'm just trying to understand) I would need a set of member variables as described for each?
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11719365
>1. I need a timer mechanism, so I need a member variable to track the timer ID
You don't need to store a timer ID if you have only one time, every time OnTimer() is called then you know it is for blinking purposes.
>2. I need a member variable that flags if this UI element should be blinking in the first place.
I don't understand this
>3. I need a member variable that tracks if the UI element is currently "on" or "off" so that the next iteration of the timer, I can say "if on then off else on"
If you need to blink many controls you need only one boolean variable for all, since them must blink at the same time.
>4. I need a AddBlinkButtonTimer(), RemoveBlinkButtonTimer() and code in my OnTimer() method to perform the appropriate actions based on the values of those described member variables.
You can do it all in the OnTimer() code, even more when both functions are almost identical, so it is not convenient to perform the same task in duplicated portions of code, for mantainbility reasons.
0
 

Author Comment

by:PMH4514
ID: 11719676
>>You don't need to store a timer ID if you have only one time, every time OnTimer() is called then you know it is for blinking purposes.

yes, but sooner than later there is going to be an array of blinking LED's (each corresponding to a unique system functional area).. So is it correct to say that each one will require a unique member variable to track its timer ID?

>> I need a member variable that flags if this UI element should be blinking in the first place.
>I don't understand this
Scratch that. A bit more work and I realized I could elliminate this. I have to keep reminding myself that non-visual functional areas have to pass messages to my CPropertySheet derived class for all UI updates, so I was thinking that I had to store "functional state" flags within my visual class, but that was just backward.

>>If you need to blink many controls you need only one boolean variable for all, since them must blink at the same time.
Ok, but if they are all blinking independant then each requires its own boolean?

>>You can do it all in the OnTimer() code, even more when both functions are almost identical
yeah, I can trap the event ID in OnTimer and compare it to each of my stored timer ID's and perform appropriate action. I could even paramterize my "AddTimer()" method to add a timer for a given UI element.

0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11719773
I still can't understand you clearly:
Do do want to blink elements at diferent rates?
If not, why make them blink indepent? It don't looks great, you don't have to create a timer for each element.
Even if different rate, you can create a unique timer which blinks (or not) some controls depending if it is time to blink a particular one.
As a general rule It is not recommended to use many timers in a window, maybe 2 or 3.
0
 

Author Comment

by:PMH4514
ID: 11719952
no, the rate (speed) at which a given element blinks doesn't need to be different from any other, but I need to be able to have elements "start blinking" and "stop blinking" independantly of each other, as they are serving to represent independant functional processes.

so you're saying, all I need is 1 timer for the page which via the WM_TIMER message gets into my OnTimer() method. But within that OnTimer() method, it would seem that I need either a unique timer ID per UI element so that I can determine which UI element() to affect, or a boolean for each UI element so that I can then check the value of it and affect within OnTimer() accordingly.

see what I'm saying? UI widgets that are not related in what they are representing functionally, but they all exist within the same property sheet.
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11720026
1) > I need either a unique timer ID per UI element so that I can determine which UI element() to affect,
2) > or a boolean for each UI element so that I can then check the value of it and affect within OnTimer() accordingly.

The second one is near to the solution, but you can use integer variables with up to 4 states:
BLINKING_ON
BLINKING_OFF
STATIC_ON
STATIC_OFF
Timer will review values of all elements, if BLINKING_ON or BLINKING_OFF, then it will swap values, if any other then does nothing for this element.


0
 

Author Comment

by:PMH4514
ID: 11720064
oh, I see what you're saying. So if I were to define an enum type of possible UI states (as you described) -then I would simply need 1 timer ID, and 1 state variable for every UI widget? sounds good to me, I'll go see if I can make it work P)
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11720091
even you can create more states
STATIC_GREEN
STATIC_RED
STATIC_OFF
BLINKING_RED_ON
BLINKING_RED_OFF
BLINKING_GREEN_ON
BLINKING_GREEN_OFF
etc, etc, etc...

0
 

Author Comment

by:PMH4514
ID: 11720111
yup. gotcha.
0
 

Author Comment

by:PMH4514
ID: 11720186
ah.. this is perfect, thanks! is there a way for me to throw some more points your way since this thread is already closed??
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11720219
Just create another question, indicating a link to this question, notice that you can't grant more than 500 points for a single question.
Thanks,
Jaime.
0
 

Author Comment

by:PMH4514
ID: 11720244
ok I'll do that right now, keep an eye out for it.

0
 

Author Comment

by:PMH4514
ID: 11720300
ok see here
http://www.experts-exchange.com/Programming/Programming_Languages/Cplusplus/Q_21082544.html

thanks again. I've already got it up and running, and it's definitely a MUCH cleaner solution that I had in mind. One integer variable for every widget and one timer. couldn't  be easier!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now