Solved

Blinking Button?

Posted on 2004-08-03
15
340 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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
 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
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.

627 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