|
I have a rtf app bsed on CRichEditCtrl ( an dialog box based app) and i want to paste a CF_METAFILEPICT in my app.How can I do this?Can anyone help me?
Thanks a lot.
|
|
|
|
|
How to convert a CHAR which contain a number to a INT or WORD ?
|
|
|
|
|
If it's char data, then strtol should help.
Steve S
|
|
|
|
|
if you have ONE digit in the CHAR '7' or '9'
you can do this:
char cCharValue = '9';
int nValue = cCharValue-'0';
if it is a CHAR* (a string)
you must use
atoi()
|
|
|
|
|
All the responses below are correct, but if you want to be extra-nice about it, have a look Boost Lexical cast[^]
|
|
|
|
|
<br />
int num = atoi("65");<br />
<code> <br />
<br />
Pain is a weakness living the body
|
|
|
|
|
Hi,
I want to convert a CString to COleDateTime. I'm using COleDateTime::ParseDateTime()and passing it the string as _T("1/25/1996 8:30:00") which is a valid format acc. to MSDN. But still, it is not working.
Does anyone have any idea of what could be wrong or what setting do I need to change in my workspace (or on my system) to use COleDateTime properly?
Regards,
Pravin
|
|
|
|
|
Are you sure the regional settings for the date on your computer are set to 'MM/dd/yyyy' (or somethoing like that )??
This may be the source of the problem...
|
|
|
|
|
From my testing, ParseDateTime() does not care about the regional settings. I use dd-MMM-yyyy H:mm for mine and I can pass a dozen different formats to ParseDateTime() all yielding correct results.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
I haven't used enums in C++ for a while and now I am using one, but I'm running into something that I don't get. I'm using my enum in a switch statment and I'm doing this
switch (m_eDataType) {
case VerifyType::Ticket :
valid = VerifyTicket ();
break;
} When I compile this it tells me that "Ticket" is not a value of VerifyType. If I take off the type and scope identifier and it works fine, but isn't what I have above a valid way to identify an enum value? I know in C# I could qualify an enum value with it's type, but I guess that's because in C# the enumerator type is a full fledged class. The enum is declared in my classes header file outside the class declaration.
Thanks.
- Aaron
|
|
|
|
|
No. I experienced this myself and found out that an enum in C++ does not declare a new named scope, and so shouldnt be preceded with the type name.
You could convert the enum into a class and have it work the C# way - the enum could be unamed within a class, or as static member variables.
|
|
|
|
|
I usually use enums and haven't seen any problem using it.
Please try the code below...
// ------------------------------------------
class MyClass
{
enum VerifyType {
Ticket = 1,
Money = 2
};
VerifyType m_eDataType;
bool valid;
public:
explicit MyClass(VerifyType const& type = Ticket)
: m_eDataType(type)
{
}
bool VerifyTicket() {
return (Ticket == m_eDataType);
}
bool CheckValidState() {
switch (m_eDataType)
{
case Ticket:
valid = VerifyTicket();
break;
case Money:
valid = false;
break;
}
return valid;
}
};
void main()
{
MyClass bar;
bar.CheckValidState();
}
// ------------------------------------------------
<b>Maxwell Chen</b>
|
|
|
|
|
This works for me:
class CMyClass
{
enum VerifyType {Ticket1, Ticket2, Ticket3};
void SomeFunction( VerifyType );
};
void CMyClass::SomeFunction( VerifyType vt )
{
switch (vt)
{
case Ticket1:
break;
case Ticket2:
break;
case Ticket3:
break;
}
}
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
That's how it's works for me to. The problem was that I couldn't qualify the enum value with the enum's name, for example VerifyType::Ticket1 , like I could do in C#. I guess I'll live with just the value though. Thanks for the replies everyone.
- Aaron
|
|
|
|
|
Hi,
[1]
I have a 3 way splitter which mimics the visual studio IDE.
I have augmented a debugging class (thanks ravi) and am using a CFormView for the bottom
debug window. Which is subclassed (The FormView has an edit control on it) so that debug messages are routed to it.
I have a global function dbg(char *s,...) in my main CWinApp override which finds the dbg class which is buried in the splitter and outputs info to that debug window.
However now I want to call it from anywhere in my src.
What I have done is declared it as
extern void dgb(char *s,...) in the .cpp CWinApp override.
Then to call it from anywhere I declare
extern void dgb(char *s,...)
in stdafx.h.
Then in my code I call
Dbg("test");
and it will call mydebugclass->print("test");
While this works and mimics the beahvior of the VS IDE how would I do this in a less hacky windows MFC fashion?
[2]
For each function in my debug class I have to add an extern for each function in there.
How do I avoid this? For example I may want to turn on my timing trace writes, or turn on
message box alerts where I have them defined etc.
[3]
How Do I pass in the current windows message so in my output I can mimic the MFC tracer?
I am trying to get configurable output e.g.
12:23:0023 CMyDerivedClass::OnInit() "my trace write" "Win32 Err = 0xFF"
and then I should be able to choose on the fly what trace inofrmation I would like to display.
Regards,
axe
|
|
|
|
|
I have a window with no non-client-area and some overriden parameters.
i need to popup the application menu when my simulation caption is clicked...
this does nothing:
<br />
SendMessage(WM_SYSCOMMAND, <br />
SC_MOUSEMENU+HTSYSMENU,<br />
MAKELPARAM(m_clientMenuPos.x, m_clientMenuPos.y));
The only way I can pop it up at the moment is :
<br />
CMenu* sysMenu = GetSystemMenu(false);<br />
int cmd = sysMenu->TrackPopupMenuEx(TPM_RETURNCMD, m_clientMenuPos.x, m_clientMenuPos.y, this, 0);<br />
if (cmd)<br />
SendMessage(WM_SYSCOMMAND, cmd);<br />
but this doesn't always bring the most updated menu.
Also, my application-menu contains only 'Move' and 'Close', what window-styles or overriden return-values do I need to have in-order to get all the other options ? (Maximize, minimize, restore, etc) [my window has WM_MAXIMIZEBOX for example).
|
|
|
|
|
For days,i study the subject of DLL, and I caught some problems in calling DLL as narrated bellow:
First one, in BCB,how to debug a program edited in Visual C++? Is it true that debugging the program I only call the .dll file used by LoadLibrary() and the functions called?
Second,when I debug a program in VC, calling the .dll file edited in Vc,I find out that the functions called have the same address (0x00000000) and the handle pointing to the .dll file have another address (0x00e10000) in called process. Why? At present,I narrate the calling form as following:
typedef int(*pMax)(int a,int b);
HINSTANCE hDLL;
PMax Max
HDLL=LoadLibrary("MyDll.dll");
Max=(pMax)GetProcAddress(hDLL,"Max");
A=Max(5,8);
Printf("比较的结果为%d ",a);
FreeLibrary(hDLL);//卸载MyDll.dll文件;
I don't know why the phenomenon brings about and hope someone can help me.Or contact me.
Thanks first.
dafan
|
|
|
|
|
I know the reason!
dafan
|
|
|
|
|
Alright, thank you ahead of time.
First off here is what the program is supposed to do, what i am having trouble with is in bold..
"Write a program that will accept as input a one character desinator (C,T,S) followed by the number of minutes a vehicle has been in the lot. THe program should then compute the appropriate charge and print a ticket for the custormer. Any part of an hour is to be counted as a full hour. At a later time the program should be modified to loop until the character "x" is entered for input. Use functions as needed! "
Alright this is my problem, the program displays correctly and executes and all that , BUT I just don't know how to do the loop... i think it has to be a while loop ...
I know what it should say in english, I think ...
It should keep asking for C,T, S and the number of minutes..infinitely until I input an "X"..but I dont know how to translate that into code.. here is where I "think" it has to go, but my full program is under it..
Enter car type...C T or S...or press x to exit program..(not exactly say that...) but if you enter c t or s , it will then ask for miles which it does, then it calculates them. But when its done, I want it to keep asking for a new type of car., Then miles...and then calculate all the same stuff all over again Then when I've decided i want to end the program after trying,( say all the different types of cars and different minute variations,
..i would simple type in x, and then enter, and it would end the loop and the program will close.
Hope that helps
void getInput() <br />
{ <br />
<br />
char vType;<br />
<br />
cout << "Enter the type of car"; <br />
cout << endl; <br />
cout << "(e.g. 'C' for car, 'T' for truck, or 'S' for senior citizen: "; <br />
cout << endl; <br />
cout << "Press X to exit program : ";<br />
cin >> vType; <br />
cout << endl; <br />
if (tolower(vType) == 'x') <br />
{ <br />
return; <br />
} <br />
cout <<"Enter the number of minutes the vehicle has been parked: "; <br />
cin >> mtime; <br />
<br />
computePrice(vType,mtime); <br />
} <br />
int main() <br />
{ <br />
getInput(); <br />
<br />
cin.ignore(); <br />
cin.get(); <br />
<br />
return 0; <br />
}
and heres the full beautiful thing...
<br />
#include <iostream> <br />
#include <fstream> <br />
#include <string> <br />
<br />
using namespace std; <br />
<br />
int mtime; <br />
<br />
void printTicket(char vType, int minutes, double p, int hours) <br />
{ <br />
<br />
<br />
string carType; <br />
if(vType == 'c'){ <br />
carType = "Car"; <br />
} <br />
else if(vType == 't'){ <br />
carType = "Truck"; <br />
} <br />
else if(vType == 's'){ <br />
carType = "Senior"; <br />
} <br />
cout<<" PENTAGON VISITOR PARKING" << endl; <br />
cout<<" Type ..... " << carType << endl; <br />
cout<<" Minutes .. " << minutes<< endl; <br />
cout<<" Hours .... " << hours << endl; <br />
cout<<" Charge ... " << p << endl; <br />
} <br />
<br />
<br />
void computePrice(char vType, int time) <br />
{ <br />
vType = tolower(vType); <br />
<br />
double p = 0.0; <br />
double h = time/60;<br />
if(time%60 > 0.0) <br />
h++ ; <br />
if(vType == 'c'){ <br />
if(time <= 120){ <br />
p = 0.00; <br />
} <br />
else if(time > 120 && time <= 300){ <br />
p = .50*(h-2.00); <br />
} <br />
else if(time >300){ <br />
p = .25*(h-5)+1.5; <br />
} <br />
} <br />
else if(vType == 't'){ <br />
if(time <= 60){ <br />
p = 0.00; <br />
} <br />
else if(time > 60 && time <=180){ <br />
p = 1.00*(h-1.00); <br />
} <br />
else if(time > 180){ <br />
p = .75*(h-3)+2.00; <br />
} <br />
} <br />
else if(vType == 's') <br />
p = 0.00; <br />
<br />
printTicket(vType,time,p,h); <br />
} <br />
<br />
<br />
void getInput() <br />
{ <br />
<br />
char vType;<br />
<br />
<br />
cout << "Enter the type of car"; <br />
cout << endl; <br />
cout << "(e.g. 'C' for car, 'T' for truck, or 'S' for senior citizen: "; <br />
cout << endl; <br />
cout << "Press X to exit program : ";<br />
cin >> vType; <br />
cout << endl; <br />
if (tolower(vType) == 'x') <br />
{ <br />
return; <br />
} <br />
cout <<"Enter the number of minutes the vehicle has been parked: "; <br />
cin >> mtime; <br />
<br />
computePrice(vType,mtime); <br />
} <br />
int main() <br />
{ <br />
<br />
getInput(); <br />
<br />
cin.ignore(); <br />
cin.get(); <br />
<br />
return 0; <br />
}
thanks again!
|
|
|
|
|
Try this:
Change getInput() to return a value - 0 to quit, 1 to continue -
int getInput() <br />
{ <br />
char vType;<br />
<br />
cout << "Enter the type of car"; <br />
cout << endl; <br />
cout << "(e.g. 'C' for car, 'T' for truck, or 'S' for senior citizen: "; <br />
cout << endl; <br />
cout << "Press X to exit program : ";<br />
cin >> vType; <br />
cout << endl; <br />
if (tolower(vType) == 'x') <br />
{ <br />
return 0; <br />
} <br />
cout <<"Enter the number of minutes the vehicle has been parked: "; <br />
cin >> mtime; <br />
<br />
computePrice(vType,mtime);<br />
return 1; <br />
}
And change main() -
int main() <br />
{ <br />
int run = 1; <br />
while(run) <br />
{<br />
run = getInput(); <br />
cin.ignore(); <br />
cin.get(); <br />
}<br />
return 0; <br />
}
Crude, I know, but I'm a beginner, too.
Will Build Nuclear Missile For Food - No Target Too Small
|
|
|
|
|
quick hide, Christian is gona blast you for solving homework problems.
jk
MSN Messenger.
prakashnadar@msn.com
Tip of the day of visual C++ IDE.
"We use it before you do! Visual C++ was developed using Visual C++"
|
|
|
|
|
I don't think so... The poster has obviously made an effort to work it out, even coding and testing it enough that it works to some extent. It's just that loops are probably not going to be covered for another week or two, and the problem requires them. My only fear is that he might lambast me for making a dumb mistake in my suggested changes. I try to help, whenever I see something here that my meager skills make me think I can fix. But I'm still green enough at coding C++ to dread displaying my ignorance in public. It's a fine line I walk, being an old procedural coder trying to master a totally new language and programming model.
Will Build Nuclear Missile For Food - No Target Too Small
|
|
|
|
|
Yes sir you are rite. He has tried his best sometimes a little help is needed to complete the task.
Like the other day a novice programmer was tring hard to make a piece of code to work but it was causeing exceptions for some reason he didnt understand..
All i did I had to put a '*' before the pointer so that he works on the value that the pointer is poining to instead of the pointer and woalla the code started working.. and a good experience for him too.
MSN Messenger.
prakashnadar@msn.com
Tip of the day of visual C++ IDE.
"We use it before you do! Visual C++ was developed using Visual C++"
|
|
|
|
|
Mr.Prakash wrote:
woalla
It's spelled 'voila' for some odd reason.;P
And, like you, I enjoy helping someone who is trying. Christian, along with most of us I think, resents people who come here looking for someone else to do the homework. Those who are willing to make an effort he helps generously.
Will Build Nuclear Missile For Food - No Target Too Small
|
|
|
|
|
well my suggestion would be as follows.
int someFuntion(){
for(;;)// causes to loop infinite times, its 2 semicolons.
{
if(gets(c)=='x'){
return 0; //or break; /*breaks out of loop.*/
}
else{
keep going;
}
return 0;
}
i think the above is not a good model and is only necessary when nothing else would work. It is said that a clean program should have 1 entry point and 1 exit point. This does not follow that guideline.
the thing is there are so many things you can do with this.
such as
while(done!=1){
cin>>command;
if(command!='x')
{
done=0;
}
else
do more;
}
Also here is your problem. When you cin you recieve a string once you press the enter button. When you use the function toLower() in the ctype library you are comparing 1 char value. i think this would cause a segmentation fault(exception) if the user types XX by mistake. if you wish for 1 char then i think it would be appropriate to use something like getchar() or getch() not sure what the proper name is but use that instead. When you use C++ don't forget that C is a big part of the C++ language. It was necessary for C++ to be a superset of C simply because of simplification.
http://www-ccs.ucsd.edu/c/
|
|
|
|
|