|
Your assignment looks valid. How did you test that aa does not hold the correct value? If you checked in the debugger, or pass it to cout, please remember that the type is still a character, and the standard representation is as a character. The value 10 is a non-prinitable character, and as such would show no visible output either in the debugger or in a printout, unless you convert aa to int first.
|
|
|
|
|
unsigned char aa = (unsigned char)10;
BTW: when you get build-time messages or run-time errors/exceptions, you should mention them verbatim in your question.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
mathivanaan wrote: unsigned char aa= 10;
The statement is indeed correct. Probably the fault is in the way you check it.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
You are getting a 10 as a binary value with that assignment.
If you use cout<< to print it out, however, you won't see a 10. That's because cout<< called on a char or unsigned char value always treats the value as a character, not a number. What you will see is that the next thing you output will begin on a new line. The 10 translates to a '\n' newline character.
To see the binary value of a char as a unsigned decimal value, use a typecast first.
unsigned char bb = 10;
cout << "** bb looks like [" << bb <<] this." << endl;
cout << "** (unsigned)bb looks like: " << (unsigned)bb << endl;
Which should display:
** bb looks like [
] this.
** (unsigned)bb looks like: 10
I put the unsigned char version in [] brackets so you can see what the effect is on the output.
Cheers,
Mike
|
|
|
|
|
Thanks Mike. i try it your solution.
|
|
|
|
|
how can i pass the values from child dialog window to parent dialog window. (ie) text box value and etc.., (how to use AfxGetApp())
Ex:
1).CTestdlg (parend dlg)
2).CDatadlg (child dlg)
i want to get data from the CDatadlg edit box to CTestdlg member
|
|
|
|
|
One way is to set the parent dialog pointer to the child window, after creating it. Use this pointer to call parent dialog's functions to notify or to directly set the values.
class CTestDlg;
class CDataDlg
{
.......
public:
SetParentDlg(CTestDlg* parent)
{
m_pTestDlg = parent;
}
private:
CTestDlg* m_pTestDlg;
}
From CTestDlg, after creating child dlg, call SetParentDlg(this) on it.
#include "testdlg.h"
......
m_pTestDlg->Function(data);
Also, you may use SetParent() and GetParent() functions on CTestDlg, and cast the returned pointer to CTestDlg* and use.
AfxGetApp() returns the CWinApp pointer, and you can cast this to your MFC application class and use.
|
|
|
|
|
Thanks "Cool_Dev" it works fine.
|
|
|
|
|
lamrinraj wrote: ...it works fine.
It may "work" but why would you want to "link" two dialog boxes together in this fashion? Having such a strong-coupling model is rarely a good idea.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Some people are making such thorough preparation for rainy days that they aren't enjoying today's sunshine." - William Feather
|
|
|
|
|
1. Send a user defined message to GetParent()
2. Cast GetParent() to CTestDlg* and call a method / set a variable
3. Implement the observer pattern.
4. Use a callback function.
Any of those will do if you need to notify the parent dialog while the child dialog is still opened.
|
|
|
|
|
Hi,
I'm creating a brick game and am having trouble merging these two if blocks. They work independantly fine but not together. Any ideas on how to get them to work. They reverse the velocities of the ball when hitting a brick. I'm also having a problem where the ball sometimes goes through a brick, it flickers and slowly makes its way through,kinda glitchy.
if(Ball_List[b]->gameBall->Bounds.IntersectsWith(Brick1->Bounds))
{
if((Ball_List[b]->gameBall->Right >= Brick1->Left || Ball_List[b]->gameBall->Left <= Brick1->Right))
{
Ball_List[b]->xVel = -Ball_List[b]->xVel;
}
if((Ball_List[b]->gameBall->Bottom >= Brick1->Top || Ball_List[b]->gameBall->Top <= Brick1->Bottom))
{
Ball_List[b]->yVel = -Ball_List[b]->yVel;
}
}
|
|
|
|
|
You are using logical OR (|| ) instead of AND (&& ). In the first case if BALL.RIGHT is greater than BRICK.LEFT OR BALL.LEFT is less than BRICK.RIGHT you slow it down. However you need both conditions to be true; for example if BALL.RIGHT is greater than BRICK.LEFT then you change velocity, but the ball is not necessarily less than BRICK.RIGHT at this point. I think the same holds true for the vertical movement.
The best things in life are not things.
|
|
|
|
|
I tried using && instead of || but it messed up the ball physics. The ball would return in the same direction back towards the paddle.
The problem seems to be that Ball.right is is always going to be greater then Ball.left when the ball is colliding with the top or bottom of the brick so the check for horizontal collision will also get executed. I'm not sure how to work around this.
Thanks.
|
|
|
|
|
Cyclone_S wrote: Ball_List[b]->gameBall->Right >= Brick1->Left
Physically, the ball have already passed the bound of the brick, i.e. reversing the speed is not enough: you should update the position accordingly.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
This is as close as I got so far but it makes the ball pause for a moment when it hits the top and bottom of the brick. This code is in the timer event. Any solution to this? Thanks.
if(left == false && Ball_List[b]->gameBall->Bounds.IntersectsWith(Brick1->Bounds))
{
if((Ball_List[b]->gameBall->Right >= Brick1->Left || Ball_List[b]->gameBall->Left <= Brick1->Right))
{
Ball_List[b]->xVel = -Ball_List[b]->xVel; left = true; top = true;
}
}
else {left=false;}
if(top == false && Ball_List[b]->gameBall->Bounds.IntersectsWith(Brick1->Bounds))
{
if((Ball_List[b]->gameBall->Bottom >= Brick1->Top || Ball_List[b]->gameBall->Top <= Brick1->Bottom))
{
Ball_List[b]->yVel = -Ball_List[b]->yVel; top = true;
}
}
else{top=false;}
|
|
|
|
|
Recently I've found a very neat blog that explains how to implement some basic physics of a very similar kind as what you are trying to achieve. Check out Physics engine for dummies for some very useful explanations and code that can get you started. The explanations you can find there on how best to implement collision control are very exhaustive.
Although the code examples do not feature rectangular bricks, I am sure you can adapt them quite easily by stealing the code from the collision control with the outside border. You just need to make sure that you will always have to check all borders, rather than just 1 at a time. However, for a start it may be easier to just use circular bricks and a circular ball.
|
|
|
|
|
Hi!
How to set the Background color and BackGround Image to a CExplorer control in MFC?
modified on Thursday, May 5, 2011 7:42 AM
|
|
|
|
|
What is CExplorer?
http://www.mono-project.com/Main_Page
|
|
|
|
|
|
|
I've added a Html Browser control to a Dialog in MFC. Initially it is displayed with white background. I want ot change to some other color. How to do this?
|
|
|
|
|
Don't you need to do this via HTML ?
Watched code never compiles.
|
|
|
|
|
No. Through C++/MFC code.
|
|
|
|
|
maximilien is right; the window doesn't belong to you, you've given it to the web browser
you can either embed an html resource in your own exe/dll and Navigate2 to it using the res:// namespace (see http://msdn.microsoft.com/en-us/library/aa767740.aspx[^]) or you can dynamically build an HTMLDocument2 and use IPersistStream to get it into the web browser
I'd choose the res protocol - much simpler
|
|
|
|
|
well, if u insist on it, subclass your web browser control. I think the CExplorer class (generated from web browser activeX) would be derived from CWnd. Handle WM_PAINT or ON_WM_ERASEBKGND messages in it. do your background painting there.
hopefully this may work.
DECLARE_MESSAGE_MAP()
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
BEGIN_MESSAGE_MAP(CExplorer, CWnd)
ON_WM_ERASEBKGND()
END_MESSAGE_MAP()
BOOL CExplorer1::OnEraseBkgnd(CDC* pDC)
{
CRect rc;
GetClientRect(&rc);
pDC->FillSolidRect(&rc, RGB(255, 0, 0));
return TRUE;
}
*But this lives only till you load your first web page in browser control.
|
|
|
|