Click here to Skip to main content
Click here to Skip to main content

CStarWarsCtrl - Star Wars Credits Control

By , 17 Jul 2002
 

Sample Image

Description

This is an attempt to create a control which looks like the credits of the Star Wars movies. Only a few simple GDI functions are used to establish this effect: Ellipse for the stars in the background and StretchBlt for scrolling text. The control is derived from CStatic.

Usage

To use the class in your application you need to do the following:

  1. Insert the .h and .cpp files into your project.
  2. Add a static control into your dialog resource.
  3. Add a member variable for that static control.
  4. Initialize the eventsink
  5. Modify the variable declaration.

  6. Change this:
    CStatic m_StarWarsCtrl; 
    To this:
    CStarWarsCtrl m_StarWarsCtrl; 
  7. In your InitDialog message handler set the speed and add some text. Use these member functions:
  8. m_StarWarsCtrl.SetStarSpeed(30);
    m_StarWarsCtrl.SetScrollSpeed(2);
    m_StarWarsCtrl.AddTextLine("A long time ago");
    m_StarWarsCtrl.AddTextLine("");
    m_StarWarsCtrl.AddTextLine("in a galaxy far far away");
    m_StarWarsCtrl.AddTextLine("");
    m_StarWarsCtrl.AddTextLine("this application was programmed by");
    m_StarWarsCtrl.AddTextLine("");
    m_StarWarsCtrl.AddTextLine("Pablo van der Meer");
    m_StarWarsCtrl.AddTextLine("");

Contacting the Author

Please send any comments or bug reports to me via email. For any updates to this article, check my site here.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Pablo van der Meer
Web Developer
Netherlands Netherlands
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralGreat !!!member4you17 Feb '05 - 1:11 
Sniff | :^) 3Q for your great job.
GeneralA bug report and modify waymemberZhaolei13 Jan '05 - 14:14 
Thanks this good code.
I use it in my aboutbox : )
 
But sometimes text stop scrolling on start time.
I find on my computer it is caused by this code:
>>DWORD t1 = GetTickCount();
>>InvalidateCtrl();
>>DWORD t2 = GetTickCount();
>>t2 -= t1; // = 50 on my system
>>m_nScrollSpeed = (m_nScrollSpeed * t2)/50;
 
After remark "nScrollSpeed = (m_nScrollSpeed * t2)/50;", every thing is ok.
may be sometimes t2 == 0.
 
Regards
zl@nanjing-fnst.com : )
 

GeneralRe: A bug report and modify waymembery_yy200820 Dec '08 - 17:48 
Thanks very much,
I also met such a bug....
you fix works very well!
GeneralKillTimermemberAlex Evans8 Jul '04 - 22:14 
Hello
 
I included an instance of this (nice class) into my dialog, but I have no idea if the timer is destroyed , and tried KillTimer() but it seems NOT working
 
Anyone has an idea?
 
Cheers
Alex
Generalbetter fade out without space bendingmemberbotsjeh21 Aug '03 - 23:47 
If you change the last for-loop in the DoScrollText function with the following the text does a bette fade-out. The value 1.5 affects the angle of the text scroll:
 
//-------------------
double yDest = nHeight-1;
 
// shrink text from bottom to top to create Star Wars effect
for (int y = nHeight-1; y >= 0; --y)
{
double nScale = (double)y/(double)nHeight;
int nOffset = (int)(nWidth - nWidth*nScale)/2;
yDest -= __min(1, nScale * 1.5);
m_MainDC.StretchBlt(nOffset, (int) yDest, (int)(nWidth*nScale), 1, &memDC, 0, y, nWidth, 1, SRCPAINT);
}
//------------------
GeneralStalling bug detectedmemberEmcee Lam18 Oct '02 - 10:06 
I downloaded the source, compiled and ran. Everything looked good when it started. Then after five minutes, it stalled. If I closed a large app like visual C++, the program would kinda start again. Then stall again. Sometimes, it would even crash. Often the point of stalling would be proceeded by some intermittent hard disk activity.
 
I then looked through the code and I found what looked like the bug
 
void CStarWarsCtrl::DoScrollText(CDC *pDC)
{
...
memDC.SelectObject(&memBitmap);
...
}
 
The problem is that there is no call to SelectObject() to switch back to the original bitmap. From what I learned from Joseph M. Newcomer, I would conclude that this bug exhausted my GDI heap.
 
Here's the fix. We only need to add code to switch back to the original bitmap
 
void CStarWarsCtrl::DoScrollText(CDC *pDC)
{
...
pOldBitmap = memDC.SelectObject(&memBitmap);
...
memDC.SelectObject(pOldBitmap);
}
 
I noticed that no one else had flagged this bug on the message board. I'm thinking that everybody else was using WinNT/XP/2000 which has a larger GDI heap than the very limited GDI heap of Win98, my OS. Yes, I know I should I junk my AMD K6-233, and get a real machine with XP. However, I would boast that there are some bugs that my computer can flag that current computers can't.
GeneralRe: Stalling bug detectedmembersanghyun yi18 May '03 - 15:15 
Thanks!!!!Big Grin | :-D
GeneralRe: Stalling bug detectedmemberAdam Wimsatt28 Oct '03 - 11:18 
Good call.
 
My code isn't buggy. Those are all fleatures.
GeneralGREAT!sussAnonymous30 Jul '02 - 1:00 
Eek! | :eek: bravo! -- SAB = Simple and Beautiful Wink | ;)
GeneralWould be better in OpenGLmembera.r.f.28 Jul '02 - 17:58 
This would look really good with the text texture mapped onto a quad moving off into the distance while fading.
 
If only I had the time...
 



"If lobsters looked more like puppies, people wouldn't put them in boiling water while they're still alive." - George Carlin

GeneralRe: Would be better in OpenGLmembervsoft11 Aug '02 - 12:31 
Yes, i've tried it few months ago, and it worked (no texture but extruded font letters). It was MUCH faster than this one (btw this one is really slow Sleepy | :zzz: even on P3/550).
 
And I think not using OpenGL is good idea, because one can think the best part of an application is aboutbox Poke tongue | ;-P )
 
Vasek
QuestionAny port to C#?memberLuis Alonso Ramos28 Jul '02 - 9:53 
If not, as soon as I have some free time I will port it to C# and share it here.
 
Great job!!
 
-- LuisR
 
──────────────
  Luis Alonso Ramos
  Chihuahua, Mexico
  www.luisalonsoramos.com
 
"Do not worry about your difficulties in mathematics, I assure you that mine are greater." -- Albert Einstein
AnswerRe: Any port to C#?memberFilus18 Sep '07 - 4:32 
I write here: http://blog.beyondsolutions.it/?p=108 a little c# porting.
 
I hope that it's useful.
 
Thank's Pablo !
GeneralAnother suggestionmemberBin26 Jul '02 - 22:25 
While nice, the "fading" effect is not enough IMO. It'd be so much cooler if you make font sizes and line distance for those "faraway" text lines smaller and smaller, so that they look really like slowly moving into the "galaxy far far away" instead of being abruptly enveloped by "the dark side".
 
I'm not sure if that's easy to implement, though, just a thought.
GeneralProgrammed like a real Jedi Master!!memberWREY21 Jul '02 - 23:11 

We know who the successor to Yoda will be.
 
Cool | :cool:
 
William
GeneralSuggestionmemberRavi Bhavnani19 Jul '02 - 17:18 
First of all, great job! A small suggestion: remove "#include stars.h" from StarWarsCtrl.h so it can be used in other apps without editing.
 
Thanks,
 
/ravi
 
Let's put "civil" back into "civilization"
http://www.ravib.com
ravib@ravib.com
GeneralYou are so right: Always code the important things first :-)memberDaniel Lohmann19 Jul '02 - 2:46 
Hey Pablo,
 
One could really get the feeling that you are writing apps that consists of nothing than an About box... Laugh | :laugh:
 
BTW: Really cool controls, man! Cool | :cool:
 
--
 
Daniel Lohmann
 
http://www.losoft.de
GeneralI like itmemberbenjymous19 Jul '02 - 1:13 
The only problem is that the text doesn't really shrink properly (it shrinks horizontally but not vertically, giving the effect that the text is on a curved surface)
 
--
Help me! I'm turning into a grapefruit!
GeneralRe: I like itmemberColin Davies19 Jul '02 - 20:50 
Maybe Speilburg and Lucas got it wrong and space is actually curved, thus this could be construed as a correction.
Smile | :)
 
Regardz
Colin J Davies


Sonork ID 100.9197:Colin

 
I am sick of fighting with Martin, I think I will ignore his posts from here on in, and spend the time working on articles instead.
 
Christian Graus


GeneralRe: I like itmemberWREY21 Jul '02 - 23:40 

That's right!! Space IS curved.
 
Einstein proved it with his famous prediction of the light from a distant star appearing closer to the sun than it actually was, due to the bend it sustained from the gravity of the sun (as it passed by the sun) on its way to the earth, as observed by us.
 
This happened during a solar eclipse when the moon was between the earth and the sun, such that only the corona of the sun could be seen.
 
Cool | :cool:
 
William
GeneralRe: I like itmemberLuis Alonso Ramos28 Jul '02 - 9:47 
WREY wrote:
due to the bend it sustained from the gravity of the sun
 
As far as I know (not very far), there is a theory of duality of light, that says something to the effect that light can be both matter or energy. So, being the former, it would be attracted by gravity. But not because the space is curved.
 
I saw that long long time ago and I never really care a lot, so I don't remember very well.
 
-- LuisR
 
──────────────
  Luis Alonso Ramos
  Chihuahua, Mexico
  www.luisalonsoramos.com
 
"Do not worry about your difficulties in mathematics, I assure you that mine are greater." -- Albert Einstein
GeneralRe: I like itmemberWREY28 Jul '02 - 20:12 

The "Theory of Duality" is not about light. It's about the electron and its orbit around the nucleus of the atom.
 
It states (in part) that the electron is BOTH "matter" and a "wave" at the SAME TIME!! Indeed, that it CANNOT exist separately at any single moment; it HAS to be BOTH. However, (and this is where you have to get the concept right) it can ONLY be viewed or determined as ONE at any one time. This means, even though the electron possesses both characteristics, you can ONLY work or study it as ONE, at any one time (NOT BOTH at the same time).
 
That is why you can ONLY tell one of these two things with it: As "matter" you can tell where the electron is (i.e., its "position"), OR as a "wave", how fast it is moving, but not both things AT THE SAME TIME.
 
This was the postulate of the German physicist, Werner Karl Heisenberg, based on the postulates of the Danish physicist, Niels Bohr, that
 
First Postulate (on stationary states): In the atom there are orbits in which an orbiting electron does not radiate.
 
Second Postulate (on quantum jumps): Radiation only occurs when an electron jumps from one stationary orbit to another.
 
Heisenberg tried to explain the Bohr's postulate by stating that the motion of the atomic electron cannot be pictured as the motion of a small ball along a trajectory. One simply cannot follow its motion as closely as one would follow the motion of a billard ball, and to do so, one would be seeking answers from asking the wrong questions which would yield WRONG answers.
 
Heisenberg contended that to obtain the correct answers to those questions, we must ask the sort of questions that "describe motion in the atom." This means, formulate an equation that mathematically asks the question.
 
Up until that time, everyone had been using the equations of electrodynamics to find the hypothetical trajectory x(t) of an electron in the atom, a trajectory that would have a continuous dependency on time, and could be expressed as the series of numbers x1, x2, x3, ... -- the positions of the electron at t1, t2, t3, ..., respectively.
 
Heisenberg held that there was no such trajectory in the atom, and that instead of a continuous curve x(t) there was a set of discrete numbers x(nk), where n and k are the numbers of the initial and final states of the electron, hence, a matrix.
 
These are the stuff of Quantum Mechanics.
 
Cool | :cool:
 
William
GeneralRe: I like itmemberNGS 54967229 Jul '02 - 7:10 
Damn...imagine the responses for something more complex than scrolling text...
GeneralRe: I like itmemberG. Steudtel21 Aug '03 - 1:15 
The "theory of duality" IS about light.
E=mc² says that energy has matter.
 
G. Steudtel
GeneralRe: I like itmemberWREY21 Aug '03 - 8:37 
Quoting the famous equation does not put the subject in the proper context of "duality" because there is no duality there; energy IS matter, and matter IS energy. The equation does not speak of duality. It speaks of "sameness".
 
Duality speaks of the two states of the electron in the atom: either its speed can be noted, OR its position can be noted (meaning, which orbit it occupies), but NOT BOTH at the SAME time. This being ironic since the electron inherently possesses BOTH characteristics. That is "duality" (the same element but with a kind of dual personality, of which only one can be noted at a time, but NOT BOTH at the same time).

 
William
 
Fortes in fide et opere!
GeneralRe: I like itmemberZerox77713 Sep '03 - 11:29 
".......there; energy IS matter, and matter IS energy. The equation...."
-The 'energy IS matter' statement can never be correct since
   in the 3rd dimension energy comes from heat, but in the 4th
   dimension energy is all. So energy isn't always matter
   because you can't see a magnetic wave or sound wave, those are
   also part of energy or electricity.
 
HELLO!
 
And BTW, your label control is brilliant!
 

GeneralRe: I like itmemberWREY14 Sep '03 - 14:11 
I don't know which dimension you're in, but if it's the '3rd', let's begin with:
 
E = mc²
 
Energy is equal to matter times the speed of light squared. If you think the equation is right, then clearly you can see that matter is an integral part of Energy. IOW, you cannot have Energy without matter as you cannot have matter without Energy.
 
If you think the equation is wrong, then let's see the correct one, and let's hear why you think Einstein and the thousands of other physicists (like him) who have subjected the equation to all sorts of rigorous test, are wrong!! Show us what you know for a fact is the correct one.
 
For you to say that, "energy isn't always matter," sounds like you're saying that, "sometimes Energy is matter, and at other times Energy isn't matter." That sounds to me like you're saying, "energy is a variable" (that sometimes it's one thing, but at other times it's something else). If that's the case, then Einstein's equation is wrong, because at one time:
 
E = mc²
 
would be right, and at other times, the equation would be:
 
Ev = mc²
 
would be right (showing Energy as a variable), which means we'd have two distinct 'Energies' (one for when it's matter, and the other for when it's NOT matter). Now all of a sudden, the Universe is comprised of two different kinds of 'Energies'.
 
So let me ask you, "Which one of these is the one that produces heat?"
 
"And where does that energy (the one that produces heat) gets its energy to produce heat?"
 
Would that be from itself? Like the sun?
 
That couldn't be right, because the sun is made up of gravitational matter so dense, you would not be able to move or pick up a piece of it the size of a button!!
 
So which would be coming from the sun? Heat? or Energy?
 
That would have to be energy, because (according to you) heat is what comes from energy, and now we are left with energy coming from heavy gravitational matter. WOW!!!
 
Are you sure you're living in the 3rd dimension? HELLO!!!
 
Suspicious | :suss:

 
William
 
Fortes in fide et opere!
GeneralRe: I like itmemberdoublej13 Feb '04 - 3:59 
Equation E=mc² does not say energy is or has matter and vice versa. It says only that some amount of energy can be transformed to some amount of matter and vice versa. This has been prooven in both directions.
 
Somebody mentioned here that duality means you can measure speed or position but not both, this is however called principle of uncertainty and has nothing to do with duality of light. Even more it is not about speed and about light at all.
 
Duality of light was about treating light sometimes like beam of photon particles and sometimes like electromagnetic waves, but since days of theory of quantum electrodynamics, which describes exactly all properties and interactions of light and matter except nuclear decay, this principle of duality is no more valid.
 
Einstein says, and until now he is still according all known facts correct, that no object in our universe which is composed from matter can travel at speed of light. This implies directly that LIGHT HAS NO MATTER therefore it cannot be affected by gravitational force and that finally means THE SPACE IS CURVED.
 
This is how it works in our 4-dimensional timespace. May be there are other dimensions we cannot see and general relativity can be even more generalized, but that is out of scope of this discussion.
 
I apologize for bad English, my native language is Czech.
GeneralRe: I like itmemberRiceking16 Jun '05 - 10:25 
lol wow, i enjoyed reading all of these Smile | :) they wasted some time at work and I LEARNED SOMETHING Smile | :) i can't wait till i can quote that the electron is both energy and a wave. should be good to make me look like one of those people who have too much free time and would actually know something like that... anyway good code anyway since we have gotten a bit off topic Smile | :)
 
Bill
GeneralRe: I like itmemberAdam Wimsatt28 Oct '03 - 11:15 
5... for being such a geek. You rock.
 
My code isn't buggy. Those are all fleatures.
GeneralRe: I like itmemberColin Leitner29 Jul '02 - 7:28 
In this case the sun would have to be right behind the viewers eyes and weigh many many many many ... many many many tons Big Grin | :-D .
GeneralVery nicememberMichael P Butler18 Jul '02 - 23:15 
I've been wanting to write one of these for a few year now. You've saved me a job. Good work and thanks.
 

 
Michael Smile | :)
 

Look, try and use your intelligence, man, even if you are a politician. - The Doctor
GeneralYeah...memberStefan Spenz18 Jul '02 - 23:12 
cool, cool, you're a creative guy... Smile | :)
 
Regards
 
Stefan
 
When I was young my mother told me to clean up my room, I told her -1!
GeneralA Real BeautymemberSantosh Rao18 Jul '02 - 18:25 
This is a Real Beauty
 
Great Man
GeneralExcellent!memberRavi Bhavnani18 Jul '02 - 17:51 
Great stuff!!! I rated this article 5 because it won't let me rate it any higher - this is very cool! Thanks for sharing!
 
/ravi
 
Let's put "civil" back into "civilization"
http://www.ravib.com
ravib@ravib.com
GeneralThis is so cool!memberJason Henderson18 Jul '02 - 17:49 
Good idea, I love it!
 

Jason Henderson
quasi-homepage
articles
"Like it or not, I'm right!"


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

Permalink | Advertise | Privacy | Mobile
Web04 | 2.6.130516.1 | Last Updated 18 Jul 2002
Article Copyright 2002 by Pablo van der Meer
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid