|
mostafa_pasha wrote: in OnFileNew:
//create document that class view is CStartPageView
CDocument* pDoc = m_pDocTemplateStartPage->OpenDocumentFile(NULL);
// & for CImageProcessingView is
pDocTemplate->OpenDocument(BULL);
There are problems in your code. Try this in OnFileNew():
CImageProcessingDoc* pDoc = (CImageProcessingDoc*)m_pDocTemplate->OpenDocumentFile(NULL);
CFrameWnd* pNewFrame = m_pDocTemplateStartPage->CreateNewFrame(pDoc, NULL);
if (pNewFrame != NULL)
{
m_pDocTemplateStartPage->InitialUpdateFrame(pNewFrame, pDoc);
}
Best,
Jun
|
|
|
|
|
I am over-riding operator new [] so that when an array of "Objects" is created they contain information about adjacent items in the array. I am getting the following error....
c:\Visual Studio Projects\JLib\main.cpp(149): error C2661: 'Object<T>::operator new[]' : no overloaded function takes 3 arguments
The following code results in the above comilation error.
Object<double>* objects;
objects = new Object<double>[5]; // <- error occurrs here
delete [] objects;
If anyone knows what is going on I would very much appreciate an explanation.
Here is the relevant declarations and definitions...
#pragma once
#include <new>
using namespace std;
template <typename T> class Object{
public:
//CONSTRUCTORS ETC ETC ETC
void* operator new[](size_t size) throw(bad_alloc);
void* operator new[](size_t size,const nothrow_t&) throw();
void operator delete[](void* ptr) throw();
void operator delete[](void* ptr,const nothrow_t&) throw();
//OTHER STUF
};
template <typename T> void* Object<T>::operator new[](size_t size) throw(bad_alloc){
Object<T>* data = 0;
if ( (data = ::operator new[](size){
//ommitted for brevity
}
return data;
}
template <typename T> void* Object<T>::operator new[](size_t size,const nothrow_t&) throw(){
Object<T>* data = 0;
if ( (data = ::operator new[](size,const nothrow_t&)) ){
//ommitted for brevity
}
return data;
}
template <typename T> void Object<T>::operator delete[](void* ptr) throw(){
::operator delete [] (ptr);
ptr = 0;
}
template <typename T> void Object<T>::operator delete[](void* ptr,const nothrow_t&) throw(){
::operator delete [] (ptr,const nothrow_t&);
ptr = 0;
}
|
|
|
|
|
With GCC, the only error I get in your code is caused by the following (in bold):
template <typename T> class Object{
public:
void* operator new[](size_t size) throw(bad_alloc);
void* operator new[](size_t size,const nothrow_t& nt) throw();
void operator delete[](void* ptr) throw();
void operator delete[](void* ptr,const nothrow_t& nt) throw();
};
template <typename T> void* Object<T>::operator new[](size_t size) throw(bad_alloc){
Object<T>* data = 0;
if ( (data = ::operator new[](size){
}
return data;
}
template <typename T> void* Object<T>::operator new[](size_t size,const nothrow_t& nt) throw(){
Object<T>* data = 0;
if ( (data = ::operator new[](size, nt)) ){
}
return data;
}
template <typename T> void Object<T>::operator delete[](void* ptr) throw(){
::operator delete [] (ptr);
ptr = 0;
}
template <typename T> void Object<T>::operator delete[](void* ptr,const nothrow_t& nt) throw(){
::operator delete [] (ptr, nt);
ptr = 0;
}
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Hi,
I have problems reading values from a text file into an array. The first problem is reading the data from the file and the other is about data type conversion.
The values in a textfile are arranged vertically, like in a column:
0
1
0
1
1
0
0
1
.
. and so on. There is only 1 vertical column of numbers in the textfile.
I used a loop below to read the values from the file into an array:
while( inClientFile >> values) //inClientFile is an ifstream object.
cout<<.......<
|
|
|
|
|
See this response.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
I'm having problems reading in line by line.
at the moment i have 2 and 3 in a text file sperated by a line. eg:
2
3
I am using the code below to read from the file...
<br />
while (PrimeFile.eof() == false && PrimeNumbers.size() < size){<br />
temp.clear();<br />
<br />
getline (PrimeFile,temp);<br />
<br />
tempInt = atoi(temp.c_str());<br />
<br />
<br />
<br />
PrimeNumbers.push_back(tempInt);<br />
<br />
<br />
}<br />
When the loop goes around once 2 goes into the int and is subsequently going into the vector PrimeNumbers. When it goes around again it reads 32 into the int.
Anyone know how i can get it so that it reads through the file one line at a time?
|
|
|
|
|
Since you are reading in numbers that are delimited by whitespace, you can use the following code:
while (PrimeFile.eof() == false && PrimeNumbers.size() < size)
{
int newPrimeNumber = 0;
PrimeFile >> newPrimeNumber;
PrimeNumbers.push_back(newPrimeNumber);
}
Alternatively, you can avoid writing your own loop altogether:
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <iterator>
using namespace std;
int main()
{
ifstream fin;
vector<int> MyVector;
fin.open("test.txt");
copy(istream_iterator<int>(fin), istream_iterator<int>(), back_inserter(MyVector));
fin.close();
copy(MyVector.begin(), MyVector.end(), ostream_iterator<int>(cout, " "));
}
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Hi,
I have some code which loads a char[] into memory from the source txt file,
Example
ifstream inn;
char text[20];
char text2[10];
inn.open("test.txt");
inn >> text; inn >> text2;
cout << text; cout << text2;
inn.close();
the text file contains
test and test
test
My problem is that this code only loads each word, seperated by a space in order. I want it to load it in order based on a new line.
Any ideas?,
thanks
Fred
|
|
|
|
|
FredrickNorge wrote: My problem is that this code only loads each word, seperated by a space in order. I want it to load it in order based on a new line.
The opeartor>> will stop when it gets to any whitespace. To get an entire line, use getline instead.
ifstream inn;
char text[20] = {0};
char text2[10] = {0};
inn.open("test.txt");
inn.getline(text, 19);
inn.getline(text2, 19);
cout << text; cout << text2;
inn.close();
Alternatively, you can use another version of getline that takes a string argument:
ifstream inn;
string text = "";
string text2 = "";
inn.open("test.txt");
getline(inn, text);
getline(inn, text2);
cout << text.c_str(); cout << text2.c_str();
inn.close();
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
thanks!, exactly what i needed.
Fred
|
|
|
|
|
Hello,
What is the difference between 'TRUE' and 'true'
BOOL IsYes;
IsYes = TRUE;
IsYes = true;
Does TRUE and true give different results?
Thanks.
Fortitudine Vincimus!
|
|
|
|
|
BOOL is defined as typedef LONG in Visual C++ libraries
TRUE is defined as #define 1
bool is built-in data type supported in C/C++ and true. This value has 1 byte in length while BOOL has 4 bytes in a 32 bit system
-Sarath.
The more you can dream the more you can do - Michael Korda"
|
|
|
|
|
Tara14 wrote: Does TRUE and true give different results?
no. they will both set IsYes to 1
|
|
|
|
|
TRUE is a #define that Microsoft's header files defines to 1. true is a built-in value for a bool that is equal to 1 (or rather, !false ).
It makes a little more sense when you look at the differences in the datatypes. BOOL is a typedef (or #define depending on the version of the header files) for an unsigned int (that is, it is 4 bytes in size). bool is a C++ standard type that is 1 byte in size (but easily can be represented by 1 bit).
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
TRUE is actually an int , because defined like this :
typedef enum {
FALSE = 0,
TRUE
} BOOL;
on the other side, bool is from the native language...
|
|
|
|
|
The important difference is between BOOL and bool . With BOOL , any non-zero value (not just TRUE ) is "true". This is the reason for the rule about never comparing a BOOL for equality with TRUE .
bool only has two possible values (true and false ).
|
|
|
|
|
If I understand correctly, if I declare a variable as
BOOL IsYes; then I can write a statement
if (IsYes == TRUE){....}
otherwise:
bool IsYes; if (IsYes == true) {...}
The confusion arose when I declare the variable as
BOOL IsYes; then, I wrote
if (ISYes == true) {..}
On compiling, I got the following warning:
warning C4805: '==' : unsafe mix of type 'int' and type 'const bool' in operation
Fortitudine Vincimus!
|
|
|
|
|
Tara14 wrote: if (IsYes == TRUE){....}
It's safer to do this :-
if(IsYes != FALSE){...}
|
|
|
|
|
Tara14 wrote: BOOL IsYes;
if (IsYes == TRUE){....}
Well, you can write that, but that's exactly what you should not do. As I just explained, TRUE is not the only value for a BOOL that means "true". The clearest (and correct) way to test a boolean for truth is simply:
if (IsYes) { ... }
|
|
|
|
|
Tara14 wrote: if (IsYes == TRUE){....}
You could write it that way, but it is much safer to write it like:
if (FALSE != IsYes)
The constant is first to avoid typographical errors (tracking down bugs when you type if (IsYes = FALSE) is a royal pain when you have large projects).
And testing against FALSE for BOOL variables is safer than testing against TRUE since TRUE is equal to 1, but a boolean expression is simply !FALSE (that is, anything other than 0).
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
I understand. With BOOL, any non-zero value is true...
Thank you.
Fortitudine Vincimus!
|
|
|
|
|
I have a subclass of a CEdit. I want to be able to resize the visible edit control until it reaches a preset bound and then to keep scrolling horizontaly and vertically. I wrote the following code
To create the control
<br />
dwStyle = ES_LEFT | WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL;<br />
<br />
if( multiline ) {<br />
m_pEdit->setMultilineOn();<br />
dwStyle = dwStyle | ES_AUTOVSCROLL | ES_MULTILINE | ES_WANTRETURN;<br />
}<br />
m_pEdit->set_bounds(maxWidth, maxHeight);<br />
<br />
m_pEdit->Create(dwStyle, rect, this, ID_inline_edit);<br />
<br />
m_pEdit->SetWindowText(text.data());<br />
The message mapping of my CEdit is
<br />
BEGIN_MESSAGE_MAP(U_W_Edit, CEdit)<br />
ON_WM_CTLCOLOR_REFLECT()<br />
ON_CONTROL_REFLECT(EN_UPDATE, OnEditUpdate)<br />
ON_NOTIFY_REFLECT(EN_UPDATE, OnEditUpdate)<br />
ON_WM_KEYUP()<br />
ON_WM_SIZE()<br />
ON_WM_CHAR()<br />
END_MESSAGE_MAP()<br />
My resize code is simple
<br />
afx_msg void<br />
U_W_Edit::OnEditUpdate()<br />
{<br />
<br />
if( !::IsWindow(this->m_hWnd) )<br />
return;<br />
<br />
if( m_bMaxSizeReached )<br />
return;<br />
<br />
int length = this->GetWindowTextLength() + 1;<br />
<br />
AB_TextBuffer text(length);<br />
<br />
GetWindowText(text.data(), length);<br />
<br />
AB_Integer width;<br />
AB_Integer height;<br />
<br />
this->get_text_extend((AB_Text) text, width, height);<br />
<br />
BOOL resize = FALSE;<br />
<br />
if( width.to_long() > m_width && width <= m_maxWidth ) {<br />
resize = TRUE;<br />
m_width = width.to_long();<br />
}<br />
<br />
if( height.to_long() > m_height && height <= m_maxHeight ) {<br />
resize = TRUE;<br />
m_height = height.to_long();<br />
}<br />
<br />
if( resize )<br />
this->SetWindowPos( NULL, 0, 0, m_width, m_height,<br />
SWP_NOMOVE | SWP_NOREPOSITION | SWP_NOZORDER );<br />
}<br />
However, any time that I type a new character it scrolls it horizontally or vertically. It never resizes the control until it reaches the maximum sizes.
I used Spy++ and realised that the EN_UPDATE message never reaches my CEdit subclass. I wonder how can I know that the stored text has changed. I tried doing it within the OnChar but it is a nightmare to filter out all characters like arrow keys etc and add in the existing text the new key. Is any simple way to track that the stored text has changed?
Making things simple is an art...
|
|
|
|
|
Have you tried catching the EN_CHANGE message instead of EN_UPDATE?
Kelly Ryan
|
|
|
|
|
Just tried that, makes no difference. I think the parent (a CScrollView subclass) does not reflect the EN_UPDATE/EN_CHANGE message properly to the child CEdit for some reason.
|
|
|
|
|
Hi there,
using Visual studio 2005, VC++ static library project, MFC in shared dll.
I am allocating large chunks of memory (close to 5 gb) of data, after 3 gb of allocation i get "out of memory" exception, machine has a physical memory of size 6 gb and also lot of paged memory, so i know that it is not about memory size.
if i use the same code in a vc++ MFC application with /largeaddressware turned on in Linker/System options it runs fine and allocates all the structures, i cannot find the same option for my VC++ static library project.
can some help me how do i make my static library project LARGEADDRESSAWARE or there is any workaround. I tried adding this option in additional options it did'nt work.
Thank you
Imad Khan
|
|
|
|