|
I read it in a book called "Data Structures and Algorithms in C++, 4th Edition by Adam Drozdek" it was in chapter 3 "Linked Lists" at the beginning of page 110 . It made me had the feeling of this when read it, and after searching and find nothing I become like this ;P;P (i.e., psycho). Thanks by the way for reply
|
|
|
|
|
Looks like a typo, to me.
|
|
|
|
|
I have wrote a method that load and rescale a CBitmap:
CBitmap* CMyDlg::LoadPicture(CString strFile)
{
int m_nPictureSize = 170;
CBitmap* pBitmap = NULL;
HBITMAP hBitmap = (HBITMAP)::LoadImage(NULL, strFile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
if(NULL != hBitmap)
{
CBitmap Bitmap, MemBitmap;
Bitmap.Attach((HBITMAP)hBitmap);
CBitmap* pFinalBitmap = MemDC.SelectObject(pOldBitmap);
SourceDC.SelectObject(pOldBmp);
pBitmap = new CBitmap;
pBitmap->Attach((HBITMAP)pFinalBitmap->GetSafeHandle());
BITMAP bm3;
pBitmap->GetBitmap(&bm3);
TRACE("Width and height INSIDE if condition: %d|%d\n", bm3.bmWidth, bm3.bmHeight);
}
BITMAP bm4;
pBitmap->GetBitmap(&bm4);
TRACE("Width and height OUTSIDE if condition: %d|%d\n", bm4.bmWidth, bm4.bmHeight);
return pBitmap;
}
I want to use this method in order to add this created CBitmap pointer to add them into CTypedCBitmapList:
CBitmap* pImage = LoadPicture(strPath);
if(NULL == pImage->GetSafeHandle())
return 0;
m_PtrArrayBitmap.Add(pImage);
Ok, but the strange thing is that pBitmap from inside of LoadPicture method has correct size inside of 'if' condition, and wrong size outside of 'if' condition:
Width and height INSIDE if condition: 170|170
Width and height OUTSIDE if condition: -858993460|-858993460
Why ? It is not the same pBitmap object ? Could you help me ? Kindly thank for any further help !
|
|
|
|
|
It appears that the bitmap you are pointing to is a temporary object whose scope is only within the if block. In the following block of code where do pOldBitmap and pOldBmp come from?
CBitmap* pFinalBitmap = MemDC.SelectObject(pOldBitmap);
SourceDC.SelectObject(pOldBmp);
pBitmap = new CBitmap;
pBitmap->Attach((HBITMAP)pFinalBitmap->GetSafeHandle());
|
|
|
|
|
I think I figure out why it doesn't work ... pOldBitmap and pOldBmp are decalred inside of 'if' statement:
if(NULL != hBitmap)
{
CBitmap* pOldBitmap = MemDC.SelectObject(&MemBitmap);
CDC SourceDC;
SourceDC.CreateCompatibleDC(&cdc);
CBitmap* pOldBmp = SourceDC.SelectObject(&Bitmap);
CBitmap* pFinalBitmap = MemDC.SelectObject(pOldBitmap);
SourceDC.SelectObject(pOldBmp);
pBitmap = new CBitmap;
pBitmap->Attach((HBITMAP)pFinalBitmap->GetSafeHandle());
BITMAP bm3;
pBitmap->GetBitmap(&bm3);
TRACE("Width and height INSIDE if condition: %d|%d\n", bm3.bmWidth, bm3.bmHeight);
}
BITMAP bm4;
pBitmap->GetBitmap(&bm4);
TRACE("Width and height OUTSIDE if condition: %d|%d\n", bm4.bmWidth, bm4.bmHeight);
return pBitmap;
|
|
|
|
|
Well, that is quite different from the code in your original question.
|
|
|
|
|
If a, b and c are variable of type int. without changing the types write a program to display
C = 1.5 if a is 3 and b is 2
|
|
|
|
|
We don't do your homework.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
sorry...didnt mean to be rude its just a test i saw somewhere and i dont know how to do it...all i want is for you guys to tell me what its under or explain what im supposed to do not to write the program. I'm a beginner in C++...Pls guys
|
|
|
|
|
#include <stdio.h>
int main()
{
int a,b,c;
if (a==3 && b==2) printf("C=1.5\n");
return 0;
}
|
|
|
|
|
For a precision of one-tenth:
printf("C = %d.%d\n", a / b, abs(((10 * a) / b) % 10));
|
|
|
|
|
I guess the question is hinting type casting[^].
«_Superman_»
I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++) (October 2009 - September 2013) Polymorphism in C
|
|
|
|
|
I use FillRect(...) for the screen but I can't get it to work for a printer. App is pretty much ordinary MFC with Doc/View arch. A little unusual is that I use worker threads for printing and painting. The threads use GDI resources instead of CDC.
Did I hear you ask why? I use an image printer to print straight to jpg files. I want a dark background in some of the jpgs. Then I use Windows Movie Maker to add the jpgs and a soundtrack. Walla, out pops an MP4. Loads of fun.
|
|
|
|
|
If you use a proper device context it should work just the same: WYSIWYG.
|
|
|
|
|
I figured it out, Richard. You have to do a FillRect(...) on the pristine CRect rcl = pInfo->m_rectDraw (in OnPrint()). That should happen before the printer thread is started.
Thanks.
|
|
|
|
|
My first program in VC6 (ever) is a wrapper so the the DLLs provided by our Scanner vendor can be used in our VB6 application. (They won't provide compatible DLLs)
I did some experimental programs and successfully wrapped the librarys in a vc6 program and created a test dialog to access the function. Good to go.
Then I followed this COM/ATL example:
http://www.codeproject.com/Articles/96/Beginner-s-Tutorial-COM-ATL-Simple-Project
I Created a COM project just like the example, added my includes for the provided vendor DLLs and abstracted access to the library calls.
Wonderfully, magically the library shows up the the VB6 reference list. I include it just like in the example program and when I try to access the simplest function (Is the scanner connected?) the call to the function CRASHES VB6 with an access violation!
I'm at the end of ideas here. I did run depends.exe against the 4 library DLLs that our vendor provided and there are a number of DLL dependencies missing on my machine. Could my problem be those missing dependencies alone? (They reference IE dlls that I don't believe are applicable to anything I'm asking the library to do.)
Thanks for your time.
|
|
|
|
|
Quite possibly yes, but it is impossible to be sure. You would need to collect some decent debug information in order to be certain why the crash occurs.
|
|
|
|
|
hi all,
i am planning to implement a tool which can capture screen only when there is display event from Operating system (for e.g window 7) level. i have idea how to capture a screen at regular interval of time but that's not what i am planning to implement.
the idea is tool will run be running in the background and it must capture the screen only when the screen is updated. i have no idea where to start. i am open for technology (c++ or c# or any other technology)
i request to give me some suggestions/ideas what could be better start.
Thanks
Vijay.
|
|
|
|
|
Vijjuuu. wrote: (c++ or c# or any other technology)
0. those are not technologies, they are languages.
1.Capturing the screen is easy
http://blogs.msdn.com/b/dsui_team/archive/2013/03/25/ways-to-capture-the-screen.aspx[^]
http://stackoverflow.com/questions/5069104/fastest-method-of-screen-capturing[^]
There are other ways, just google for "win32 api capture screen"
2. when screen is updated - this is pretty much close to impossible to find out - at least I don't know of a way to do it. The way you can do it is to simply have a timer, capture when the timer is triggered - and if you wish, compare with former screen (bitmap).
3. I'm not sure what you're trying to achieve, since there may be other ways to find out "when screen is updated" depending on your actual needs - perhaps you might be only interested in a specific window(s)? It would be a smart choice to minimize the area you're capturing, since that can indeed take a while and it's not really a good idea to to it too fast (not to mention - what if the user has a few monitors, and/or high resolution ones)
4. If you're just trying to learn programming, I suggest you take an easier task.
Best,
John
-- LogWizard Meet the Log Viewer that makes monitoring log files a joy!
|
|
|
|
|
Greetings,
I am looking for this book 'Data Structures Through C in Depth by S. K. Srivastava, Deepali Srivastava' as a soft copy and I cannot find it if anyone have it as a soft copy if he can upload it for me I will be too much grateful for him. Best regards!.
|
|
|
|
|
Have you tried here?
"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
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Yeah but I cannot buy it as it costs too much form me 1 Dollar = 8 EGP that is why I asked for it if someone had a soft-copy of it.
|
|
|
|
|
Just out of curiosity, if someone gave or sold you their copy, how would you verify that they got rid of their copy? I'm thinking that one copy of a book "owned" by more than one person is in violation of that book's copyright. Yes?
"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
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
You are right about the copyright stuff. However, with complete respect to you and your opinion, not all people can get what they want especially if the thing related with payment(s) because they may have no money or it will cost them lots of money for me for example to buy this book for me will cost 2080 EGP so if for example, has a need for 10 books I will pay like 20800 EGP and that is lots of money for me + shipping fees, sorry for talking to much but I am trying to explain why I was asking for help from someone who may have it. Also I could have a book I do not need it or use it and a friend want it and was about buying and I give him mine so do you think it is violation in such situation?!!!. Wishing you good day
|
|
|
|
|
Hi, Im doing this small breakout clone for school, I've looked at heaps of people's takes on Breakout and tried to combine bits and pieces that I liked. Only problem that I'm having is getting the game to end when the ball hits the bottom window edge + sounds.. You should be able to copy/paste the code into a project, only issues being with the sound and text. Thanks a lot
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/Audio.hpp>
#include <iostream>
using namespace std;
using namespace sf;
int x = 5;
constexpr int windowWidth ( 800 ), windowHeight( 600 );
constexpr float ballRadius( 10.f ), ballVelocity( 6.f );
constexpr float paddleWidth( 100.f ), paddleHeight( 20.f ), paddleVelocity( 8.f );
constexpr float blockWidth( 60.f ), blockHeight( 20.f );
constexpr int countBlocksX( 11 ), countBlocksY( 6 );
constexpr int countBlocks2X(11), countBlocks2Y(3);
bool isPlaying = true;
struct Ball
{
CircleShape shape;
Vector2f velocity{ -ballVelocity, -ballVelocity };
Ball(float mX, float mY)
{
shape.setPosition(mX, mY);
shape.setRadius(ballRadius);
shape.setFillColor(Color::Yellow);
shape.setOrigin(ballRadius, ballRadius);
}
void update()
{
shape.move(velocity);
if (left() < 0)
velocity.x = ballVelocity;
else if (right() > windowWidth)
velocity.x = -ballVelocity;
if (top() < 0)
velocity.y = ballVelocity;
else if (bottom() > windowHeight)
velocity.y = -ballVelocity;
}
float x() { return shape.getPosition().x; }
float y() { return shape.getPosition().y; }
float left() { return x() - shape.getRadius(); }
float right() { return x() + shape.getRadius(); }
float top() { return y() - shape.getRadius(); }
float bottom() { return y() + shape.getRadius(); }
};
struct Rectangle
{
RectangleShape shape;
float x() { return shape.getPosition().x; }
float y() { return shape.getPosition().y; }
float left() { return x() - shape.getSize().x / 2.f; }
float right() { return x() + shape.getSize().x / 2.f; }
float top() { return y() - shape.getSize().y / 2.f; }
float bottom() { return y() + shape.getSize().y / 2.f; }
};
struct Paddle : public Rectangle
{
Vector2f velocity;
Paddle(float mX, float mY)
{
shape.setPosition(mX, mY);
shape.setSize({ paddleWidth, paddleHeight });
shape.setFillColor(Color::Red);
shape.setOrigin(paddleWidth / 2.f, paddleHeight / 2.f);
}
void update()
{
shape.move(velocity);
if (Keyboard::isKeyPressed(Keyboard::Key::Left) && left() > 0)
velocity.x = -paddleVelocity;
else if (Keyboard::isKeyPressed(Keyboard::Key::Right) && right() < windowWidth)
velocity.x = paddleVelocity;
else
velocity.x = 0;
}
};
struct Brick : public Rectangle
{
bool destroyed{ false };
Brick(float mX, float mY)
{
shape.setPosition(mX, mY);
shape.setSize({ blockWidth, blockHeight });
shape.setFillColor(Color::Black);
shape.setOrigin(blockWidth / 2.f, blockHeight / 2.f);
}
};
template <class T1, class T2>
bool isIntersecting(T1& mA, T2& mB)
{
return mA.right() >= mB.left() && mA.left() <= mB.right() &&
mA.bottom() >= mB.top() && mA.top() <= mB.bottom();
}
void collisionTest(Paddle& mPaddle, Ball& mBall)
{
if (!isIntersecting(mPaddle, mBall)) return;
mBall.velocity.y = -ballVelocity;
if (mBall.x() < mPaddle.x())
mBall.velocity.x = -ballVelocity;
else
mBall.velocity.x = ballVelocity;
}
void collisionTest(Brick& mBrick, Ball& mBall)
{
if (!isIntersecting(mBrick, mBall)) return;
mBrick.destroyed = true;
float overlapLeft{ mBall.right() - mBrick.left() };
float overlapRight{ mBrick.right() - mBall.left() };
float overlapTop{ mBall.bottom() - mBrick.top() };
float overlapBottom{ mBrick.bottom() - mBall.top() };
bool ballFromLeft(abs(overlapLeft) < abs(overlapRight));
bool ballFromTop(abs(overlapTop) < abs(overlapBottom));
float minOverlapX{ ballFromLeft ? overlapLeft : overlapRight };
float minOverlapY{ ballFromTop ? overlapTop : overlapBottom };
if (abs(minOverlapX) < abs(minOverlapY))
mBall.velocity.x = ballFromLeft ? -ballVelocity : ballVelocity;
else
mBall.velocity.y = ballFromTop ? -ballVelocity : ballVelocity;
}
int main()
{
RenderWindow window(VideoMode(windowWidth, windowHeight ), "Breakout Game" );
window.setFramerateLimit(60);
Paddle paddle{ windowWidth / 2, windowHeight - 50 };
int x = 5;
restart:
Ball ball{ windowWidth / 2, windowHeight / 2 };
vector<Brick> bricks;
for (int iX{ 0 }; iX < countBlocksX; ++iX)
for (int iY{ 0 }; iY < countBlocksY; ++iY)
bricks.emplace_back(
(iX + 1) * (blockWidth + 3) + 22, (iY + 2) * (blockHeight + 3));
sf::Font font;
if (!font.loadFromFile("arial.ttf"))
return EXIT_FAILURE;
sf::Text loseGame;
loseGame.setFont(font);
loseGame.setCharacterSize(40);
loseGame.setPosition(80.f, 150.f);
loseGame.setColor(sf::Color::White);
loseGame.setString("You lost, press 'Space' to play again.");
sf::SoundBuffer ballSoundBuffer;
if (!ballSoundBuffer.loadFromFile("loseSound.wav"))
return EXIT_FAILURE;
sf::Sound loseGameSound(ballSoundBuffer);
while (true)
{
window.clear(Color::Color(49, 79, 79));
if (Keyboard::isKeyPressed(Keyboard::Key::Space))
goto restart;
if (Keyboard::isKeyPressed(Keyboard::Key::Escape))
break;
ball.update();
paddle.update();
collisionTest(paddle, ball);
for (auto& brick : bricks) collisionTest(brick, ball);
bricks.erase(remove_if(begin(bricks), end(bricks),
[](const Brick& mBrick)
{
return mBrick.destroyed;
}),
end(bricks));
if (isPlaying)
{
window.draw(ball.shape);
window.draw(paddle.shape);
for (auto& brick : bricks) window.draw(brick.shape);
}
else
{
window.clear(Color::Black);
loseGameSound.play();
window.draw(loseGame);
if (Keyboard::isKeyPressed(Keyboard::Key::Space))
goto restart;
}
window.display();
}
return 0;
}
|
|
|
|