|
There are several ways of going about this, but without knowing more about your requirements, some of them might not be applicable.
If the length of the string is constant, something like this:
CStdioFile file(...);
CString strLine;
file.ReadString(strLine);
int nNum = atoi(strLine[24]);
nNum += 1;
... If there is always seven groups of numbers, something like this:
AfxExtractSubString(str1, strLine, 0, 0x2c);
AfxExtractSubString(str2, strLine, 1, 0x2c);
...
AfxExtractSubString(str7, strLine, 6, 0x2c);
int nNum = atoi(str7);
nNum += 1;
if (150 == nNum)
nNum = 0; Do these help at all?
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
Is it possible to dock a Dialog Box just like a toolbar to anyside of the framewindow !
If yes pls tellme
Shailesh
|
|
|
|
|
I have not heared about dialog box!
But you can do this using CDialogBar. You can design the dialogbar in dialog editor and made it dockable.
search for the sample in msdn about CDialogBar.
Hope It help
Kamyar Souri
Booria CAD/CAM Systems
www.booria.com
|
|
|
|
|
I want to implement autoshapes in my sample Dhtml editor and i don't know how to do it? So can anybody help me?
Thanx...
lokesh
|
|
|
|
|
I wrote a string class and try to test with a very simple driver program, but there are some erros, can somebody help me figure out my mistakes?
thank you!
--------------Configuration: main - Win32 Debug--------------------
Compiling...
main.cpp
Linking...
main.obj : error LNK2001: unresolved external symbol "public: __thiscall myString::~myString(void)" (??1myString@@QAE@XZ)
main.obj : error LNK2001: unresolved external symbol "class ostream & __cdecl operator<<(class ostream &,class myString const &)" (??6@YAAAVostream@@AAV0@ABVmyString@@@Z)
main.obj : error LNK2001: unresolved external symbol "public: __thiscall myString::myString(char const *)" (??0myString@@QAE@PBD@Z)
Debug/main.exe : fatal error LNK1120: 3 unresolved externals
Error executing link.exe.
main.exe - 4 error(s), 0 warning(s)
____________________________________________________________________________
myString.h file:
//myString
#ifndef MYSTRING_H
#define MYSTRING_H
#include<iostream.h>
class myString{
friend ostream &operator<<(ostream &, const myString &);
friend istream &operator>>(istream &, myString &);
public:
myString( const char * = "");
myString(const myString &);
~myString();
const myString &operator= (const myString &); //assign string
myString &operator+= (const myString &);
int operator! () const; //empty string
int operator== (const myString &) const;
int operator!= (const myString &) const;
int operator< (const myString &) const;
int operator> (const myString &) const;
int operator>= (const myString &) const;
int operator<= (const myString &) const;
char &operator[] (int);
myString &operator()(int, int);
int getLength() const;
// void toUpper (myString &);
// void toLower (myString &);
private:
char* sPtr;
int length;
};
#endif
________________________________________________________________________
myString.cpp file
//myString.cpp
#include<iostream.h>
#include<string.h>
#include<assert.h>
#include"myString.h"
myString::myString(const char *s)
{
lengh = strlen(s);
sPtr = new char[lengh +1];
assert(sPtr!=0);
strcpy(sPtr, s);
}
//convention constructor
myString::myString(const myString ©)
{
lengh = copy.length;
sptr = new char [length +1];
assert(sPtr!= 0 );
strcpy(sPtr, copy.sPtr);
}
//copy constructor
myString::~myString()
{
delete [] sPtr;
}
//destructor
const myString &myString::operator = (const myString &right)
{
if(&right! = this)
{
delete [] sPtr;
length = right.length;
sPtr = new char [length+1];
assert (sPtr!= 0);
strcpy(sPtr, right.sPtr);
}
else
cout<<"Attempted assignment of a String to itself\n";
return *this;
}
//operator =
myString &myString::operator+= (const myString &right)
{
char * tempPtr = sPtr;
length+= right.length;
sPtr = new char [length +1];
assert(sPtr!= 0);
strcpy(sPtr, tempPtr);
strcat(sPtr, right.Ptr);
delete[] tempPtr;
return *this;
}
//operator +=
int myString::operator! () const{return length == 0;}//empty
int myString::operator == (const String &right) const
{
return strcmp(sPtr, right,sPtr) == 0;
}
int myString::operator!= (const myString &right)const
{
return strcmp(sPtr, right.sPtr)!= 0;
}
int myString::operator< (const myString &right) const
{
return strcmp (sPtr, right.sPtr) < 0;
}
int myString::operator> (const myString &right) const
{
return strcmp (sPtr, right.sPtr) > 0;
}
int myString::operator>= (const myString &right) const
{
return strcmp (sPtr, right.sPtr) >= 0;
}
int myString::operator<= (const myString &right) const
{
return strcmp (sPtr, right.sPtr) <= 0;
}
char &myString:: operator[](int subscript)
{
assert(subscript >= 0 && subscript< length);
return sPtr[subscript];
}
myString &myString::operator() (int index, int subLengh)
{
assert(index >=0 && index<length &&sublength="">=0);
myString *subPtr = new myString;
assert(subPtr! = 0);
int size;
if((subLength == 0)||(index + subLength > length))
size = length - index+1;
else
size = subLength +1;
delete subPtr->sPtr;
subPtr->length = size;
subPtr-> = new char[size];
assert(subPtr->sPtr!=0);
for(int i = index, j = 0; i<index+size-1; i++,j++)
="" subptr-="">sPtr[j] = sPtr[i];
subPtr->sPtr[j] = '\0';
return *subPtr;
}
int myString::getLength()const{return length;}
ostream &operator<< (ostream &output, const myString &s)
{
output<<s.sptr;
return="" output;
}
istream="" &operator="">> (istream &input, myString &s)
{
static char temp[100];
input>>temp;
s=temp;
return input;
}
________________________________________________________________________
very simple main :
#include <iostream.h>
#include "myString.h"
#include <string.h>
int main()
{
myString s1("happy");
cout<
|
|
|
|
|
So is the modified code OK now?
Maxwell Chen
|
|
|
|
|
Thanks for the help, I haven't check it yet.
but I think it will work fine.
Thanks again
from foxele
|
|
|
|
|
Can u send those modified code as attachment in header file and source file, cause I couldn't download them, I don't know why
thanks agian!
|
|
|
|
|
I did send them in attachment form. Check the lower part of the mail! There are [Download] links.
In the email...
My texts,
(blue line) Your text...
(Still blue line) Your original attachment texts...
Do you Yahoo!?
(No blue line since here) My attachments!
Maxwell Chen
|
|
|
|
|
I have sent you another email about the reason having written the email address that way ...
Maxwell Chen
|
|
|
|
|
Maxwell, did you test the myString class with your c++ compiler?
I still got the same four errors about my destructor and operator<< and constructor. If it works fine in your computer, then it is the problem of my compiler.
Please let me know .
Thank You So Much
from foxele
|
|
|
|
|
foxele wrote:
Maxwell, did you test the myString class with your c++ compiler?
I still got the same four errors about my destructor and operator<< and constructor. If it works fine in your computer, then it is the problem of my compiler.
Please let me know .
Yes, with Visual C++ 6.0, I built it, and ran it. The code compiled without any error or warning. And the output was correct ("Happy"... something).
Are you sure that you've downloaded the correct code? Or you just made a mistake that you copied the original code included in the text part of the reply? Or you didn't replace the code in the project with new one?
Check the comments in the cpp file. I have moved some comments from the end of function bodies to the beginning of function bodies. If it is such kind, then it's a new one. For example:
<br />
myString::myString()<br />
{<br />
}
To isolate the problem from your making a mistake replacing files or your compiler's got problem, this time I will send you the whole project in ZIP form.
Please visit WinZip[^] to get a zip tool. Thanks.
Maxwell Chen
|
|
|
|
|
I have created an application.While running and applcation I would like to run another application (exe) using Shell.But I want that application to run in the background i.e. no dialogs or documents associated with it.I don't want the user to know that this application is running.SO how can I create such and application that runs in the backdrop.
|
|
|
|
|
Use CreateProcess and set the wShowWindow member of the STARTUPINFO member to SW_HIDE.
Best regards,
Dominik
_outp(0x64, 0xAD);
and
__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do??
(doesn't work on NT)
|
|
|
|
|
I have a download function that returns the contents in a CString (it mostly downloads text), for simplicities sake I would like to use it to download JPGs (binary content) how can I get the binary contents from teh download function without messing it up when it downloads text and be able to send it to WriteBinaryToFile as the correct size.
CString Download(CString m_strURL); //returns the content
void WriteBinaryToFile(CString m_strFileName, CString m_strFileContents);
(this is specifies the binary flag in the CFile options)
-Steven Hicks
CPACodeProjectAddict
|
|
|
|
|
Steve,
Please be aware that if the file contents contains a zero (null) within the contents, then CString will only give you contents upto the null value.
Do you know the lengths of the files you're downloading?
If I was you, I'd look at CHttpFile. Here's the MSDN link.
Hope this helps,
Andy
|
|
|
|
|
You should not use binary value with CString, must use a buffer of TCHAR to collect the info.
I'll write a suicide note on a hundred dollar bill - Dire Straits
|
|
|
|
|
Personally, I would modify your Download function to return an object, something like the following:
class DownloadObject {
public:
DownloadObject(char *text);
DownloadObject(unsigned char *data,int size);
~DownloadObject();
enum Type { Text, Binary };
Type GetType() const;
bool GetAsText(CString &text) const;
bool GetAsBinary(unsigned char **binary,int *size);
private:
Type _Type;
unsigned char *_Data;
int _Size;
}; This object contains an arbitrary sequence of bytes, that the creator of the object (e.g. the Download function) can specify to be of type 'Text' or 'Binary'. The creator specifies the type of object based on which constructor he uses. When the object is returned to the caller of the Download function, that function can determine the type of data using the supplied member functions, something like this:
DownloadObject *Download(CString URL);
DownloadObject *object = Download(example_URL);
CString text;
unsigned char *data;
int size;
if (object != NULL) {
switch (object->GetType()) {
case DownloadObject::Text:
object->GetText(text);
break;
case DownloadObject::Binary:
object->GetBinary(&data,&size);
break;
}
delete object;
} Note that I've modified the definition of the Download function to return a pointer to a DownloadObject. If the return value is NULL, that can be an error indication.
I think this is a better approach than overloading the CString class. While CString does let you store binary data of arbitrary length which includes '\0' characters, it's primary purpose is to hold text data. Using it to contain binary data confuses the programmers who come after you.
Software Zen: delete this;
|
|
|
|
|
Gary R. Wheeler wrote:
Using it to contain binary data confuses the programmers who come after you.
Hehehehe (evil grin)
I'll have to go about it this way (the object route). Thanks!
-Steven Hicks
CPACodeProjectAddict
|
|
|
|
|
Does the default CIMageList support 32 bpp images?
I have tried using a 32 bpp image and the background comes out black all the time, no matter what flags I use
How does IE 6 (XP anyways) render it's toolbar so nicely?
Any ideas
Cheers
How do I print my voice mail?
|
|
|
|
|
Hockey wrote:
How does IE 6 (XP anyways) render it's toolbar so nicely?
Its XP theme.
I guess its got to do with Manifest. There are few articles discribing how to use it.
I'll write a suicide note on a hundred dollar bill - Dire Straits
|
|
|
|
|
I do not know about CIMageList, but usualy when an image comes out black there it an error in the code; these can be frustrating to solve.
INTP
|
|
|
|
|
Hey,
Im working on a menu-type dialog-based program. Basically, the user can select a button and it'll run a program. The user can define what program to run by clicking Browse for each button.
What I have is a dialog box with 2 buttons, Run "CFloatDlg::OnRun()", and App1 "CFloatDlg::OnApp1()". Here is my code:
void CFloatDlg::OnApp1()
{
CFileDialog fd(TRUE,"exe",NULL,OFN_HIDEREADONLY,
"Programs (*.exe)|*.exe|All Files (*.*)|*.*||",this);
if (fd.DoModal() == IDOK)
{
m_sFilename = fd.GetPathName();
UpdateData(FALSE);
}
}
void CFloatDlg::OnRun()
{
_execlp(m_sFilename, NULL);
}
When the user clicks the App1 button, the open commondialog opens and the user can select an .exe. Then the user clicks run, and the program is executed. The program itself also closes.
How can I make the program save, (internal or external), what the user has selected so that the program selected will be there each and everytime until the user changes it? Also, how can I make it so that the dialog does not close when another program is executed from it?
P.S.: I just wanted to thank everyone for all their work and time here. I've been quiet here, but I love all the code. Everyone is doing awesome work. I do plan on providing back to the community with my own code soon. Thanks to all.
DNFSB
|
|
|
|
|
DNFSB wrote:
Also, how can I make it so that the dialog does not close when another program is executed from it?
how is OnRun called?
in OnRun are you calling baseclass OnOk()??
Your code is incomplete to discribe your problem.
I'll write a suicide note on a hundred dollar bill - Dire Straits
|
|
|
|
|
My OnRun is just:
_execlp(m_sFilename, NULL);
when the user clicks the that button, the m_sFilename selection is ran, but the dialogbox that the button is on closes as the m_sFilename is ran.
DNFSB
|
|
|
|