|
There is no problem having includes within includes, and they really should be there if the file won't compile without them.
You do not need to make CTimer a friend of CAnimatedSprite just to make it a member variable. You only need a friend class when it needs to access protected/private members of another class.
Dave
http://www.cloudsofheaven.org
|
|
|
|
|
You should always minimize inclusion of headers in other headers, especially on larger projects as you get unnecessary compiles on the slightest change. Read "Large Scale C++ Design" (I think that is the title) for a very informative and in depth discussion of the many problems here.
Try not to make CTimer a member, but instead use CTimer* then you can forward declare CTimer (eg. class CTimer;) and hide its implimentation from the AnimatedSprite.h file. ie. It only needs to be visible in AnimatedSprite.cpp Read about PIMPL and look at Boost Smart Pointers www.boost.org[^]
Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com
|
|
|
|
|
Cheers, Thanks and Superb to both of you.
I'm not quite sure what you mean wrt CTimer* (Newbie Alert)
// AnimatedSpriteClass.h
// Doesn't the statement
CTimer* pSpriteTimer;
// require the TimerClass header to create a pointer to one ?
// No: because it is not initialised ?
// AnimatedSpriteClass.cpp
// Then when I define the InitSprite(int x, int y, int CurrentAnimSequence);
// do I initialize the Ctimer pointer to an instance of the CTimer ?
pSpriteTimer = new CTimer;
// will that do the trick ?
// Cheers,
// Wodger
|
|
|
|
|
Anonymous wrote:
Cheers, Thanks and Superb to both of you.
It is a pleasant change to get a thankyou - thanks for that.
Anonymous wrote:
CTimer* pSpriteTimer;
No is correct. You would include:
class CTimer;
in the .h before the class definition. You need to ensure that you don't define any functions in this .h that call CTimer functions, otherwise you are back to needing CTimer.h In other words write this functions in the .cpp. If you need inline functions for speed then put them in a .inl.
Anonymous wrote:
pSpriteTimer = new CTimer;
Yes. But I'd suggest doing this in the AnimatedSpriteClass constructor and the delete pSpriteTimer; in the destructor. Better still using either an STL auto_ptr or Boost scoped_ptr. eg. In the .h
boost::scoped_ptr<CTimer> pSpriteTimer;
and in the constructor:
pSpriteTimer.reset( new CTimer );
Then you don't need to delete pSpriteTimer and can rest assured that it will be cleaned up if an exception occures etc.
Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com
|
|
|
|
|
Hi,
I'm learning C++ and have the MS Developer Studio C++ V4.2 installed.
Can anybody tell me how to define a project with the demo files I downloaded from this site to produce an executable program? What are the settings/options when I create a project workspace? How to incorporate the downloaded files?
Thanks in advance,
Ulrich
|
|
|
|
|
Have you tried double-clicking on the .dsp file (the project file), which should open devstudio.
It should also ask you if you want to create a workspace for the project.
|
|
|
|
|
double-clicking on the .dsp file opens devstudio and opens the .dsp file in the editor, that's all
|
|
|
|
|
Vc++ is being used for automating winword report generation using ole automation. The reports are based on predefined templates. How can we convert the same report to other languages using ole automation in vc++. Ex: English reports to French.
Thanks in advance.
|
|
|
|
|
Hi, is there anyway to prevent the ALT F4? so my window can't be shutdown like that?
If not, is there anyway to "hide" my window from the list of windows which pops op when won presses ALT-TAB.
Thanks for any help.
|
|
|
|
|
Intercept the WM_CLOSE message and return false. If you are using MFC, goto classwizard and add WM_CLOSE message handler to that particular window and remove the CDialog::OnClose() statement.
Harsha
----------------------------------
http://www.ece.arizona.edu/~hpg
----------------------------------
|
|
|
|
|
That's right, Make more programs that require a hard reset to get out of.
MS finally makes a reasonably stable OS (XP) and then you go and disable essential escape funtionality. Try disabling Alt-Tab and Ctrl-Alt-Del as well (I don't think you will, but would be a good challenge)
Alt F4 is there for a reason!
Head retracted now (I'm sure you have a legit reason for doing this)!
|
|
|
|
|
Anonymous wrote:
I'm sure you have a legit reason for doing this
There are plenty of reasons. I wrote a little app a while ago for a church for controlling a LCD projector (turning it on/off etc.). It was an appbar that ran at startup and was permanently set at the top of the screen, and they didn't want people to be able to close it, because then they couldn't control the projector. So I had to do this. I did it in a slightly different way, though.
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
If you must let people interact with your app, then you should think about setting a system wide keyboard hook in order to avoid all the "strange" keypresses (Ctrl + shift + esc...) and also to implement a gina dll in order to avoid Ctrl+alt+del... you can say then that you control the PC and that you can be sure that people won't touch things that shouldn't...
hope this helps.
|
|
|
|
|
Joan Murt wrote:
hope this helps.
I never asked a question!
All I had to do was prevent one app from being closed. Task Manager was disabled by system policies, so all I had to do was prevent Alt+F4 and Escape (it was a dialog app). Setting a system-wide keyboard hook would have been massive overkill.
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
I was under the impression (according to my programming book) that a left shift on a byte caused the bits on the left to "fall off" and zeros inserted to the right:
eg. 0x1F << 2 = 0xC0
but it equals 0x7C0
Why is this?
My reason for asking this question is that I am trying to find a four byte sequence within a file (MPEG-1) that doesn't seem to byte aligned. I wrote a little function to do a "bit by bit" search but since the above statement is not true it fails, here is my code (I feed it 64 bits at a time):
int FindSequenceHeader(unsigned char *str)
{
char ch[4];
DWORD dwValue;
for (int x = 0; x < 4; x++)
{
for (int i = 0; i < 8; i++)
{
ch[0] = ( (str[x + 0] << (0 + i)) | (str[x + 1] >> (8 - i)) );
ch[1] = ( (str[x + 1] << (0 + i)) | (str[x + 2] >> (8 - i)) );
ch[2] = ( (str[x + 2] << (0 + i)) | (str[x + 3] >> (8 - i)) );
ch[3] = ( (str[x + 3] << (0 + i)) | (str[x + 4] >> (8 - i)) );
dwValue = ( ch[0] | (ch[1] << 8) | (ch[2] << 16) | (ch[3] << 24) );
switch (dwValue)
{
case 0x000001b3:
cout << "Video Sequence Header Found" << endl;
return 0;
break;
default:
break;
}
}
}
return 1;
}
which then leads me to ask why this standard routine i've seen in many sample codes works:
DWORD MakeDword(unsigned char *str)
{
return ( str[0] | (str[1] << 8) | (str[2] << 16) | (str[3] << 24) );
}
any thoughts?
|
|
|
|
|
georgiek50 wrote:
eg. 0x1F << 2 = 0xC0
but it equals 0x7C0
georgiek50 wrote:
Why is this?
Because it is the right answer.
0x1F = 0001 1111
shift it left a coupla times and put zeros in on the right
0111 1100 = 0x7C
0000 = 0
0001 = 1
0010 = 2
0011 = 3
0100 = 4
0101 = 5
0110 = 6
0111 = 7
1000 = 8
1001 = 9
1010 = A
1011 = B
1100 = C
1101 = D
1110 = E
1111 = F
cheers!!
Adam.
My world tour
What I do now..
"I spent a lot of my money on booze, birds and fast cars. The rest I just squandered"
George Best.
|
|
|
|
|
georgiek50 wrote:
I was under the impression (according to my programming book) that a left shift on a byte caused the bits on the left to "fall off" and zeros inserted to the right:
eg. 0x1F << 2 = 0xC0
but it equals 0x7C0
That's not the right answer. 0x1F << 2 = 0x7C.But in any case to ensure that you receive only the last 8 bits you can AND a byte with 0x0FF. For example:
char[ 0 ] = 0x1F;
DWORD dwVar = char[ 0 ];
dwVar = (dwVar << 2) & 0x0FF
georgiek50 wrote:
dwValue = ( ch[0] | (ch[1] << 8) | (ch[2] << 16) | (ch[3] << 24) );
The compiler will get each character in ch and store it into a register because that's the only place where shift operations can be performed. For example if you would see the above code written in machine language it would look like this:
mov eax, ch[0];
mov edx, ch[1];
shl edx, 8;
or eax, edx;
mov edx, ch[2];
shl edx, 16;
or eax, edx;
and so on....
The final result in eax will be moved to a dword ptr memory location that corresponds to dwValue. All the registers are 4 bytes long (32 bits) and a DWORD data type is a 32 bit unsigned integer. That's why this works.
// Afterall I realized that even my comment lines have bugs
|
|
|
|
|
Sorry, what I meant to write was 0x1f << 6 (instead of 2)= 0x7c0 where I was expecting just 0xc0 according to this logic:
<br />
0x1F = 00011111<br />
0x1F << 6 = 11000000 or 0xC0<br />
I think my understanding of shifting is very off!
|
|
|
|
|
The compiler assumes it as a 16-bit number. So,
0x1F = 0000000000011111
0x1F << 6 = 0000011111000000 = 0x7C0.
So, for 8 - bit operation may be u can write as
unsigned long a = 0x1F;
a=LOBYTE(a<<6);
It gives the desired result....You can fit it into your program...
Harsha
----------------------------------
http://www.ece.arizona.edu/~hpg
----------------------------------
|
|
|
|
|
Thanks...and you clarified for me what hi and lo - byte means, I was wondering about that for some time!
|
|
|
|
|
Be aware that:
a) Bytes get int-expanded when shifting things around
b) char, int etc. are signed - which makes the shift "arithmetic", i.e. the highest order bit remains set.
So a) use unsigned char, and b) cast th shift result back to unsigned char.
"Der Geist des Kriegers ist erwacht / Ich hab die Macht" StS
sighist | Agile Programming | doxygen
|
|
|
|
|
Hello,
where can i get "tom.h". I have visual studio 6.0 enterprice eddition and sp5. but there is no such file.
Thanks in Advance to solve this problem.
Thank you
Asad Rasheed
|
|
|
|
|
Download the Platform SDK.
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
Hi , I wanted to know what is the function that detect a radio button is detected
example : in A Wizard the next button is disabled
what'is the function that enable the next button if a radio is checked.
Please Help,
Thanks
Bye
|
|
|
|
|
If you are using MFC then using classwizard, assign a member variable to the first radio button in the group.
Then, handle the BN_CLICKED message for each radio button in your group. Check the state of the member variable (having called UpdateData()). If it the right value then enable your Next button.
hope this helps
Adam.
My world tour
What I do now..
"I spent a lot of my money on booze, birds and fast cars. The rest I just squandered"
George Best.
|
|
|
|