|
|
This[^] handy dandy class should be of help.
/ravi
|
|
|
|
|
|
The problem is as follows: I had to make a program that allows the user to enter some text. Then, I had to allow the user to drag and drop the text over the window. Up to that, everything works. The problem is in changing the color of the text. When the user selects the new color, we can't see it until we move the text. What should I do if I wanted to change the color right away?
This is the part of my code:
CColorDialog colorDlg;
if (colorDlg.DoModal() == IDOK) // The user selected the "OK" button
{
m_crColor = colorDlg.GetColor();
m_bFirstTime = TRUE;
}
and
if (m_bFirstTime == TRUE)
{
pDC->SetTextColor(RGB(GetRValue(m_crColor), GetGValue(m_crColor),
GetBValue(m_crColor)));
}
else
pDC->SetTextColor(m_txtColor);
pDC->TextOut(pDoc->m_pos.x,pDoc->m_pos.y,pDoc->m_text);
Thanks
Alessandra
|
|
|
|
|
I don't think you need the m_bFirstTime flag. Just refreshing/repainting the controls should
do...
CColorDialog colorDlg;
if (colorDlg.DoModal() == IDOK) // The user selected the "OK" button
{
m_crColor = colorDlg.GetColor();
Invalidate(FALSE); // force repaint of child controls
}
|
|
|
|
|
OK, I'll try it.
Thanks a lot
Alessandra
|
|
|
|
|
Thanks again.
I tried it and it works
Can you please help me with one more thing? It's just that when I first open my program, the text should not move immediately, but only when the user clickes on it. But in my case it starts to follow the mouse as soon as the mouse gets on the window (not on the text). Do you know how can I solve it?
Thanks.
Alessandra
|
|
|
|
|
The code is as follows:
CSize ts;<br />
ts = pDC->GetTextExtent(pDoc->m_text);<br />
pDoc->m_textRectangle.left = ts.cy;<br />
pDoc->m_textRectangle.right = (pDoc->m_textRectangle.left + ts.cx);<br />
pDoc->m_textRectangle.bottom = ts.cx;<br />
pDoc->m_textRectangle.top = (pDoc->m_textRectangle.bottom - ts.cy);<br />
pDoc->m_textRectangle.MoveToXY (pDoc->m_pos.x, pDoc->m_pos.y);
and
if((pDoc->m_mouse_captured))<br />
{<br />
pDoc->m_pos = point;
Invalidate();<br />
}
Alessandra
|
|
|
|
|
Ha you beat me to it.
Do you want the user to be able to drag the text by clicking on the text or do you move the text
when the user moves the mouse over it?
When does pDoc->m_mouse_captured get set?
|
|
|
|
|
Ok, I want the user to click on the text and to drag it over the window. When he realeses the left mouse button, the text should stop moving.
Alessandra
|
|
|
|
|
You may be doing something similar already...
This is pseudocode for one way to handle it
Member variables:
CPoint BasePoint;
bool fInCapture;
CRect TextRect;
void CMyWnd::OnLButtonDown(UINT nFlags, CPoint point)
{
if TextRect.PtInRect(point)
{
BasePoint = point;
::SetCapture(*this);
fInCapture = true;
}
}
void CMyWnd::OnMouseMove(UINT nFlags, CPoint point)
{
if (fInCapture)
{
if (point != BasePoint)
{
TextRect.OffsetRect(point.x - BasePoint.x, point.y - BasePoint.y)
Invalidate(TRUE);
UpdateWindow();
BasePoint = point;
}
}
}
void CMyWnd::OnLButtonUp(UINT nFlags, CPoint point)
{
if (fInCapture)
{
fInCapture = false;
::ReleaseCapture();
}
}
|
|
|
|
|
I haven't seen the code Are you moving the text in response to WM_MOUSEMOVE messages?
|
|
|
|
|
And yes, I am moving the text in response to WM_MOUSEMOVE messages
Alessandra
|
|
|
|
|
Hey, I am part of a project which is being coded in Visual C++; however, I am a Java programmer. Thus I need some serious help (A fully written class would be wonderful!) with connecting to a URL via an HTTP connection, and then reading from the URL. The idea is to read from the URL in order to get a PHP script running.
I wrote a bit of code in Java to accomplish this task, but the project is being created in Visual C++.
Here is the java code I wrote:
<br />
public static void main(String[] args) {<br />
String key = "/*insert key here*/";<br />
try {<br />
URL myURL = new URL("http", "/*insert url here*/", "/*script location here*/" + key);
System.out.println(myURL);
URLConnection appendConnect = myURL.openConnection();<br />
BufferedReader in = new BufferedReader( <br />
new InputStreamReader(<br />
appendConnect.getInputStream()));<br />
in.close();
<br />
} catch (MalformedURLException e) {
System.err.println("LOL!");<br />
} catch (IOException e) {<br />
System.err.println("LOL!!");<br />
}<br />
}<br />
The key is just a random string of numbers and characters which is read by the PHP script on the server and compared against the script's key. The key can be combined with the URL if that makes it any simpler.
Help would be really wonderful!
|
|
|
|
|
|
http://www.codeproject.com/internet/amhttputils.asp
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and you
|
|
|
|
|
I have an assignment that requires me to code a petty cash program in C++. I did this assignment a while back when it was required to code it in python. Is there a simple way to convert a python code into C++. I managed to get the menu working. I am trying to get it to do the math needed to adjust the account.
Here is the python code that works:
<br />
class Account:<br />
def __init__(self, initial):<br />
self.balance = initial<br />
<br />
def deposit(self, amt):<br />
self.balance = self.balance + amt<br />
<br />
def withdraw(self, amt):<br />
self.balance = self.balance - amt<br />
if self.balance < 0:<br />
print 'Not enough here'<br />
else:<br />
return self.balance<br />
<br />
def getbalance(self):<br />
return self.balance<br />
<br />
<br />
from datetime import date<br />
now = date.today()<br />
a = Account(0)<br />
print 'Please select a number'<br />
print '1 Deposit'<br />
print '2 Withdraw'<br />
print '3 Inquiry'<br />
number = input('Please choose an option: ')<br />
while True:<br />
if number == 1:<br />
dep = input('Enter amount deposited: $')<br />
a.deposit(dep)<br />
print 'Deposit of $', dep, 'makes account balance $', a.getbalance(), 'as of', now<br />
elif number == 2:<br />
wit = input('Enter amount withdrawn: $')<br />
a.withdraw(wit)<br />
print 'Withdraw of $', wit, 'makes account balance $', a.getbalance(), 'as of', now<br />
elif number == 3:<br />
print 'Account balance is $', a.getbalance(), now<br />
<br />
else:<br />
break<br />
print<br />
number = int(raw_input('Do you want something else? or enter 4 to exit '))<br />
<br />
print 'Goodbye'<br />
this is what I have so far in C++:
<br />
#include <iostream><br />
#include <string><br />
#include <sstream><br />
using namespace std;<br />
<br />
void DisplayMenu();<br />
int GetSelection();<br />
<br />
int main()<br />
{<br />
int selection = 0;<br />
while (selection != 4) {<br />
DisplayMenu();<br />
selection = GetSelection();<br />
switch (selection){<br />
case 1:<br />
cout << "Deposit" << endl;<br />
break;<br />
case 2: <br />
cout << "Withdraw" << endl;<br />
break;<br />
case 3:<br />
cout << "Inquiry" << endl;<br />
break;<br />
case 4:<br />
cout << "Quitting" << endl;<br />
break;<br />
default:<br />
cout << "\aInvalid selection" << endl;<br />
break;<br />
}<br />
} <br />
return 0;<br />
}<br />
void DisplayMenu()<br />
{<br />
cout << " ---Menu---" << endl;<br />
cout << "1=Deposit" << endl;<br />
cout << "2=Withdraw" << endl;<br />
cout << "3=Inquiry" << endl;<br />
cout << "4=Quit" << endl;<br />
}<br />
int GetSelection()<br />
{<br />
int selection;<br />
cout << "Enter selection: ";<br />
cin >> selection;<br />
return selection;<br />
}
I want to make the class Account work in C++. I don't want someone to do the assignment, just give me a clue as to how to go about it. Thanks in advance for any help.
Elaine
|
|
|
|
|
kerthy_29 wrote: I want to make the class Account work in C++.
Ok, so what is an account (object)? What are its properties? What can you tell it (settor methods)? What can it tell you about itself (getter methods). Knowing this will go a long way towards designing the class.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
I understand some of that. This is what I have figured out so far, but I don't know if it would work when I add it to the code I already have done. Does this look right?
<br />
class Account {<br />
int AccountBalance;<br />
};<br />
class Deposit{<br />
int AccountBalance, amount;<br />
public:<br />
void set_values(int, int);<br />
int dep () {return (AccountBalance+amount);}<br />
}; <br />
class Withdraw{<br />
int AccountBalance, amount;<br />
public:<br />
void set_values(int, int);<br />
int wit () {return (AccountBalance-amount);} <br />
};
Thanks for the help.
Elaine
|
|
|
|
|
Account seems about right. It's a noun, so a class is appropriate. However, Deposit and Withdraw are verbs. This indicates that they should be operations rather than classes.
What do you think about this design: (I will let you fill in the code.. it's your assignment! )
class Account {
int balance;
public:
void Deposit(int amount)
{
}
void Withdraw(int amount)
{
}
void SetBalance(int balance)
{
}
int CurrentBalance()
{
}
}; I made the operations part of the Account class. In an enterprise class design, this should be designed a bit differently. But let's not shoot over the target - the aim is to learn the C++ language, right? I also added SetBalance and CurrentBalance so that client code (fancy name for code which uses objects of a class), can initialize the object and inspect the object.
I would like to know how you reasoned when you made your design. Don't see this is as criticism. If there's one thing I've learned during the years, is that if you try to explain your own design in human language, the design mistakes will be very easy (or at least easier) to spot. The golden rule is that if it doesn't make sense in a human language, it won't make sense in a programming language.
--
Verletzen zerfetzen zersetzen zerstören
Doch es darf nicht mir gehören
Ich muss zerstören
|
|
|
|
|
Thanks for pointing out some fixes. I got the original coding from the python coding that I had already done and knew that it worked.
Elaine
|
|
|
|
|
After inspection of your original python code, it would seem that you are already familiar with my proposed design.. Sorry about that.
--
Verletzen zerfetzen zersetzen zerstören
Doch es darf nicht mir gehören
Ich muss zerstören
|
|
|
|
|
I wouldnt be sorry about it Joergen - you put her back on the tracks with her understanding of what it could/should look like in c++ - when I looked at her suggestion I thought 'yuck', transliteration of Python or not
At least unlike other people's homework attempts, she's made an effort, which is rare enough these days, so good-on-ya
'g'
|
|
|
|
|
I have an existing DLL named as A1.dll ,which is a MFC dll .
I added a configuration that renames the output of the same as B1.dll
hence it generates b1.lib
In my application i used to link with A1.lib which I replaced with B1.lib and I copied B1.dll to the executable folder .
Now when i run it , i get an error saying that A1.dll is missing .
Where do i specify this dependency ?
Engineering is the effort !
|
|
|
|
|