|
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;
}
|
|
|
|
|
|
Matthaeus Jumpertz wrote: You should be able to copy/paste the code into a project, only issues being with the sound and text.
"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
|
|
|
|
|
i create a treeview in a wnd derived from CWindowImpl ( i use atl), and i create a imglistctrl for the treeview,
everything seems ok of the imagelist, and i assign a image index for every node of the trewview, but no icon shows, and a small empty rect keeps at the left of every node's, anyone can help me?
class CJMainForm : public CWindowImpl<CJMainForm>
{
public:
DECLARE_WND_CLASS("JMainFrameClass")
CJMainForm(void);
~CJMainForm(void);
BOOL ShowForm(BOOL bShow = TRUE);
BEGIN_MSG_MAP( CJMainForm )
MESSAGE_HANDLER( WM_PAINT, OnPaint)
MESSAGE_HANDLER(WM_LBUTTONDOWN, OnLButtonDown)
MESSAGE_HANDLER(WM_MOUSEMOVE, OnMouseMove)
MESSAGE_HANDLER(WM_ERASEBKGND, OnEraseBkgnd)
MESSAGE_HANDLER(WM_QUERYENDSESSION, OnQueryEndSession)
END_MSG_MAP()
public:
CXAnalogClock m_wndClock;
CCalenderWnd m_wndCalender;
CWindow m_wndPrjTree;
HBRUSH m_brBackGround;
SIZE m_szbrBackGround;
protected:
LRESULT OnPaint( UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled );
LRESULT OnLButtonDown( UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled );
LRESULT OnMouseMove(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
LRESULT OnEraseBkgnd(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
LRESULT OnQueryEndSession(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
HICON m_icoExit;
HICON m_icoPrevYear;
HICON m_icoNextYear;
HICON m_icoPrevMonth;
HICON m_icoNextMonth;
HICON m_icoToday;
HFONT m_icoTextFont;
int m_CurrentRegion, m_nOldRegion;
HICON m_icoNodeClosed;
HICON m_cioNodeOpen;
HICON m_icoAttrib;
enum EnToolBtnState
{
tbs_normal = 0,
tbs_hover,
tbs_prress_down,
}m_nToolBtnState[6];
RECT m_rcToolBtn[6];
HBRUSH m_brToolBtnHover;
int m_nLastToolBtnHit;
enum SKIN
{
cpbob = 0,
cpnobob,
darkblue,
silver,
gold,
black,
lightblue,
green,
red,
rose,
aqua,
neonblue,
bluestreak,
crystalgreen,
crystalblack,
crystalblue,
crystalred,
crystalyellow,
silverring,
minimal,
white,
};
void SetSkin();
struct SKIN_MENU_DATA
{
UINT nID;
UINT nClockFaceBitmapId;
UINT nDateBitmapId;
TCHAR *pszName;
};
static SKIN_MENU_DATA m_Skins[];
static int m_nSkins;
SKIN m_eSkin;
ATL::CString m_strSkin;
SKIN GetSkinFromName(LPCTSTR lpszSkinName);
private:
void ParseNode(IDispatch* pNode,HTREEITEM hParent);
HTREEITEM CJMainForm::InsertTreeItem(HTREEITEM hItem, LPCTSTR lpszItem, int nImage,
int nSelectedImage, HTREEITEM hParent, HTREEITEM hInsertAfter = TVI_LAST);
BOOL SetTreeItem(HTREEITEM hItem, UINT nMask, LPCTSTR lpszItem, int nImage,
int nSelectedImage, UINT nState, UINT nStateMask, LPARAM lParam);
CXmlDocumentWrapper m_xmlDoc;
HIMAGELIST m_imageListTreeView;
};
extern CJMainForm* g_pMainForm;
BOOL CJMainForm::ShowForm(BOOL bShow)
{
if (!m_hWnd || !IsWindow())
Create(::GetDesktopWindow(), 0, 0, (WS_POPUP | WS_VISIBLE | WS_CLIPCHILDREN) & (~WS_CAPTION), WS_EX_CONTROLPARENT | WS_EX_TOOLWINDOW);
DWORD dw = GetLastError();
if (m_hWnd && bShow && IsWindow())
{
RECT rectWorkArea;
SystemParametersInfo(SPI_GETWORKAREA, 0, (LPVOID)&rectWorkArea, 0);
MoveWindow(&rectWorkArea);
SetWindowPos(HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
}
if (!m_wndCalender.m_hWnd)
{
RECT rc = {0};
rc.left = 64;
rc.right = rc.left + 64 * 7 + 1;
rc.top = 12;
rc.bottom = rc.top + 64 * 6 + 24 + 1;
rc.bottom += 24;
m_wndCalender.Create(m_hWnd, &rc,"", WS_CHILD | WS_VISIBLE);
}
if (!m_wndClock.m_hWnd)
{
RECT rc = {0};
rc.left = 64 + 12;
rc.right = rc.left + 100;
rc.top = 12;
rc.bottom = rc.top + 64 * 6 + 24 + 24 + 1;
rc.top = rc.bottom + 12;
rc.bottom = rc.top + 100;
m_wndClock.Create(m_hWnd, &rc,"", WS_CHILD | WS_VISIBLE);
m_wndClock.SetHourAdjust(0);
if (!m_strSkin.IsEmpty())
{
m_eSkin = GetSkinFromName(m_strSkin);
SetSkin();
}
m_wndClock.Run();
}
if (!m_wndPrjTree.m_hWnd)
{
if (!m_imageListTreeView)
{
m_imageListTreeView = ::ImageList_Create(16, 16,ILC_COLOR24|ILC_MASK,3,1);
m_icoNodeClosed = (HICON)::LoadImage(g_hInstance , MAKEINTRESOURCE(IDI_NODECLOSED), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
m_cioNodeOpen = (HICON)::LoadImage(g_hInstance , MAKEINTRESOURCE(IDI_NODEOPEN), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
m_icoAttrib = (HICON)::LoadImage(g_hInstance , MAKEINTRESOURCE(IDI_ATTRIB), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
ImageList_AddIcon(m_imageListTreeView,m_icoNodeClosed);
ImageList_AddIcon(m_imageListTreeView, m_cioNodeOpen);
ImageList_AddIcon(m_imageListTreeView, m_icoAttrib);
}
RECT rc = {0};
rc.left = 64 * 8 + 12;
rc.right = rc.left + 64 * 4;
rc.top = 12;
rc.bottom = rc.top + 64 * 6 + 24 + 1;
rc.bottom += 24;
m_wndPrjTree.Create(WC_TREEVIEWA,m_hWnd, &rc,"prjview", WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP
| TVS_HASBUTTONS | TVS_HASLINES | TVS_LINESATROOT | TVS_INFOTIP |TVS_TRACKSELECT|TVS_SINGLEEXPAND| TVS_DISABLEDRAGDROP);
::SendMessage(m_wndPrjTree.m_hWnd, TVM_SETIMAGELIST, (WPARAM)TVSIL_NORMAL, (LPARAM)m_imageListTreeView);
::SendMessage(m_wndPrjTree.m_hWnd, TVM_SETBKCOLOR, 0, (LPARAM)RGB(224, 255, 224));
m_xmlDoc.Load("F:\\XmlView\\UpgradeLog.XML");
ParseNode(m_xmlDoc.AsNode(),TVI_ROOT);
}
if (m_hWnd && !bShow && IsWindow())
ShowWindow(SW_HIDE);
return (m_hWnd != NULL);
}
|
|
|
|
|
I have a simple MDI application which will load a browser view in its child frame. For an instance I am loading gmail in the child frame.
I am using CHtmlView class and the funtion CHtmlView::Navigate2 to do the same. I have no issues in opening the link. As per my knowledge, this need IE browser right? What If I want to use chrome and do the same?
|
|
|
|
|
The WebBrowser control is an ActiveX component based on Microsoft libraries. It is independent of whatever browser you actually use.
|
|
|
|
|
Member 12108486 wrote: As per my knowledge, this need IE browser right?
CHtmlView doesn't need a browser, it is the browser.
"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
|
|
|
|
|
I can't open the OpenSCManager Function in C++ & Debug.
The error-code is always 5.
It works, when i don't use Debug with Admin-Rights only.
With VS 2008 it works.
What can i do ?
|
|
|
|
|
The code that attempts to use this function must have admin rights.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
the code shows std::bad_alloc error dont know what to do about it when remove the push_back it dissapears. please help on what to do. this happens only when I am entering a huge string s else it runs perfectly fine. is there another efficient way to find all the possible substring, arrange them lexicographicaly and then concatinate them back into one string????pls help thnx in advance
#include <cmath>
#include <set>
#include <cstdio>
#include <vector>
#include <iostream>
#include<string>
#include <algorithm>
using namespace std;
bool sortByString(string &t1, string &t2)
{
return t1 < t2;
}
int main() {
string s,sub,i,c,q;
int T;
cin>>T;
while(T--){
cin >> s;
int length = s.length();
cin>>q;
vector<string> ss;
for (c = 0; c < length; c++)
{
for (i =length-c;i>=1; i--)
{
ss.push_back(s.substr(c,i));
}
}
s="";
set<string> se(ss.begin(),ss.end());
ss.assign(se.begin(),se.end());
vector<string>::iterator p;
for( p=ss.begin();p!=ss.end();++p)
s.append(*p);
cout<<s[q-1]<<endl;
}
return 0;
}
|
|
|
|
|
I wonder how your code could possibly compile (in fact, it doesn't on my system, using g++ ): you are using the variable c , declared std::string where a int is expected.
|
|
|
|
|
sry c and i are integer types. I was making it look proper. in the begining they were all in different places
|
|
|
|
|
If you want proper help then you have to post the original code.
|
|
|
|
|
q is defined as a string , yet you are using it as a subscript in the following:
cout << s[q-1] << endl;
Please clean up this code if you are really expecting help from us.
"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
|
|
|
|
|
1. Always post the code that you actually use and that shows the described (problematic) behaviour
2. Cleaning up your code can occasionally help, but if you do so, then (a) make sure the clean code still compiles (and runs) to the extent the original code did, and (b) make sure the code still shows the same issue(s)! There really is no point discussing code that doesn't show the behaviour you are describing.
3. Learn to use a debugger, step through your code, and examine the current value of your local variables. Since you already know where you're crashing, it's a good starting point to set a break point before the call to push_back() , and investigate the state of your variables then.
Bonus tip: remove that line using namespace std; It is a crutch and will make it more difficult to spot issues in your code. You'll need to add the prefix std:: in many places, so that requires additional typing, but it really isn't that hard, and it adds to the readability of your code as well as reducing the likelyhood that you're mixing up local and library symbols! The extra effort of always typing std:: pays off very quickly!
If you don't believe me, the warnings are all over the place right in the C++ reference. See for example http://en.cppreference.com/w/cpp/language/namespace#Using-directives[^]:
cppreference.com wrote: Using-directive does not add any names to the declarative region in which it appears (unlike the using-declaration), and thus does not prevent identical names from being declared.
and
cppreference.com wrote: The using-directive using namespace std; at any namespace scope introduces every name from the namespace std into the global namespace (since the global namespace is the nearest namespace that contains both std and any user-declared namespace), which may lead to undesirable name collisions. This, and other using directives are generally considered bad practice at file scope of a header file.
Emphasis mine.
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
|
|
|
|
|
Nice to meet you guys,
It's been a long time since I developed a program.
Now I need to build a simple register program that needs to be a standalone exe running on Windows 7 and above.
Is this possible? if yes where do I start?
I want to use (and learn) Visual C++ in the process.
My best regards,
Rodolfo
|
|
|
|
|
that really depends on what you mean by 'standalone' - I'll assume unless otherwise corrected you mean as in 'not connected to a remote database ie on another machine in a network' .. in which case, yes, very possible - there are versions of MSSQL that are light enough, there's SQLite and plenty of other databases you can deploy with your application for a 'standalone' install - the decider between databases is/are the usual questions concerning databases
how ? make google your friend - read voraciously - trawl CP for example projects - find an example that you 'grok' and use it as a model for your own case - the only way to learn is to do.
When you have specific issues, there are forums here you can post technical issues on
|
|
|
|
|
Garth J Lancaster wrote: the only way to learn is to do. Agreed!
"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
|
|
|
|
|
Member 12129820 wrote: Now I need to build a simple register program...
"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
|
|
|
|
|
|
Thanks guys for the help.
|
|
|
|
|
Would it be possible to code the sound to text software from c++? what should we use for that?
|
|
|
|
|
|