Solved

Blinking Button?

Posted on 2004-08-03
15
325 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
computer science syllabus 3 91
How to print into std::string like sprintf using C++11? 12 86
Embarcadero WebBroker REST server endpoint parameters 2 82
Outlook 13 45
When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

821 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