|
I'm doing a MFC MDI app, with CScrollView view.
I am getting a very strange problem, the last row of the view is not visible until I resize the window in any way. I can scroll to the bottom, but it won't be visible until the window is resized(Even smaller, I can scroll there and it'll be drawn then)
This is how I set the scroll size
SetScrollSizes(MM_TEXT, CSize(1026, 1026),
CSize(64, 64),
CSize(1, 1));
Everything else draws fine though
This is how the last row is drawn
if (dc->RectVisible(CRect(CPoint(0, 1025), CSize(1026, 1))))
dc->FillSolidRect(0, 1025, 1026, 1, RGB(70, 70, 70));
Still happens if I do it without the RectVisible()
|
|
|
|
|
I can not get the above message to work in an ordinart CDialog messages map.
where the memberFxn looks like:
void edit1Return(NMHDR * pNotifyStruct, LRESULT * result )
{
MessageBox("Carrage return occured");
}
Must there be some kind of initializing in the program? Or how will I get the message to work?
|
|
|
|
|
The dialog is intercepting the pressing of the enter key (and calling OnOK ) before it gets to the focused control. You can try disabling the translation of enter hits as follows:
BOOL CYourDlg::PreTranslateMessage(MSG* pMsg)
{
if(pMsg->message==WM_KEYDOWN&&pMsg->wParam==VK_RETURN)return 0;
return CDialog::PreTranslateMessage(pMsg);
} but we warned that playing with PreTranslateMessage can lead to all sorts of strange behaviors with your app.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Does anybody know how to change the mouse cursor form ? I've been trying using lhCursor = AfxGetApp()->LoadStandardCursor(....) to change the cursor image, then SetCursor(lhCursor) make the change visible and finally OnSetCursor to stick with the changes whenever the mouve moves. The problem is that when the mouse leaves the window and comes backin again, it resets it's cursor to the old image, not the one I changed it to.
Thank you
Nelson Gonçalves
|
|
|
|
|
Load the cursor once in OnInitDialog and set it every time OnSetCursor is called just like this:
BOOL CYourDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
SetCursor(lhCursor);
return TRUE;
} I've tried it and it works OK.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thank you. I've tried and it works.
Nelson Gonçalves
|
|
|
|
|
Hi
I'm a VC beginner.I'm attempting to make use of the CArray template but i'm at a lost now.(i used CArray as the size of my array is not fixed)I declared a CArray object in my document class and wants to create a function so that other classes might access the array.
Below is an abstract of my program.
in CDocument header file, where m_array1 and GetRawDataArray are declared as public...
----------------
struct SRawData
{
double x;
double y;
};
CArray<srawdata, srawdata=""> m_array1;
CArray GetRawDataArray();
--------------------------------
in the CDocument .cpp file...
------------------------------
CArray CRainAttDoc::GetRawDataArray()
{
return m_array1;
}
this gives me the error message:
(a)error C2955: 'CArray' : use of class template requires template argument list
(b)error C2553: no legal conversion of return value to return type 'class CArray *'
Does anyone know what is happening and what i can do?
Thanks.
|
|
|
|
|
Try this:
in your header file, declare outside of the doc class declaration
typedef CArray <SRawData *, SRawData *> CSRawDataArray;
In the document class definition:
CSRawDataArray m_myDataArray;
Now you may use m_myDataArray like
SRawData *pNewData = new SRawData;
m_myDataArray.Add(pNewData);
while(m_myDataArray.GetCount())
delete m_myDataArray.RemoveHead()
HTH,
K.
<font size=0 color=#C0CFC0>
<hr color=#A0AFA0 width = 60% align=left><i>
One small village of indomitable geeks still holds out against the invaders. And life is not easy for the managers legionaries who garrison the fortified camps of Microsoftum, Javum, Ceplumplum and Vebasum</i></font>
|
|
|
|
|
haa ok
i said thks for your suggestion.gave me quite some insight really.But i still dunno how to create a function to return the array in some way so that other classes may access it.u have any suggestion on that?
|
|
|
|
|
There are several solutions:
* You may add public member functions to your document to manipulate the array from the outside of the document object
* You may directly "lend" the array to other classes like this:
CSRawDataArray &CMyDocument::GetArray()<br />
{<br />
return m_myDataArray;<br />
}
Beware that this method returns a reference on the array, i.e. the "real" object, not a copy.
void COtherClass::AddData(CMyDocument *pDoc, CSRawDataArray *pData)<br />
{<br />
CSRawDataArray &myArray = pDoc->GetArray();<br />
<br />
myArray.Add(pData);<br />
}
HTH,
K.
One small village of indomitable geeks still holds out against the invaders. And life is not easy for the managers legionaries who garrison the fortified camps of Microsoftum, Javum, Ceplumplum and Vebasum
|
|
|
|
|
Hi..i've tried the following but it's still not working.Do you know wat i shld do?
-------------------------------------------------------------------
typedef CArray <srawdata *,="" srawdata="" *=""> CSRawDataArray;//outside class declaration
//in doc header
CSRawDataArray m_array1;
CSRawDataArray& GetRawDataArray() const;
//in doc source file
//doing 2 things here.(1)load data into array from text file (2)define get function
void CRainAttDoc::Serialize(CArchive& ar)
{
CString strOneLine;
while(ar.ReadString(strOneLine))
{
SRawData *pData = new SRawData;
sscanf(strOneLine,"%g%g\n",pData->x,pData->y);
m_array1.Add(pData);
}
}
CSRawDataArray &CRainAttDoc::GetRawDataArray() const
{
return m_array1;
}
---------------------------------------------------------------------
This gives me the following error:
error C2440: 'return' : cannot convert from 'const class CArray<struct srawdata="" *,struct="" *="">' to 'class CArray<struct srawdata="" *,struct="" *=""> &'
When i try to change the object declaration to this:
const CSRawDataArray m_array1;
error C2440 remains and on top of that, the following message for RemoveAll() and Add()
'RemoveAll' : cannot convert 'this' pointer from 'const class CArray<struct srawdata="" *,struct="" *="">' to 'class CArray<struct srawdata="" *,struct="" *=""> &'
I was trying to declare the function const so that other classes cant alter the value as suggested by Roman Fadeyev but it just cant work.I'm pulling my hair out!..haa thks alot for your help.
|
|
|
|
|
I don't understand why you're using the keyword "const". Have you tried without it ?
If you want to be sure the others classes don't mess up with the array, you may declare it as protected in your document class and add public methods (to your document class), to be sure it's the only class which will manipulate directly the array.
One small village of indomitable geeks still holds out against the invaders. And life is not easy for the managers legionaries who garrison the fortified camps of Microsoftum, Javum, Ceplumplum and Vebasum
|
|
|
|
|
oh yah you are right, i totally forgot i can declare it as protected.
yes, it can be compiled now.however when trying to open the text file after executing the program, the serialize() function fails and returns a what appear to be an assertion failure.
|
|
|
|
|
I suppose your Serialize method is like
void CRainAttDoc::Serialize(CArchive& ar)<br />
{<br />
CString strOneLine; <br />
<br />
while(ar.ReadString(strOneLine)) <br />
{ <br />
SRawData *pData = new SRawData;<br />
sscanf(strOneLine,"%g%g\n",pData->x,pData->y); <br />
m_array1.Add(pData); <br />
} <br />
}
First of all, you should test if you are writing or reading, using ar.IsStoring() (Serialization works both way). Also instead using a "while" statement, I would suggest you to write explicitly at the beginning of the archive the number of items to read
It would look like this
void CRainAttDoc::Serialize(CArchive& ar)<br />
{<br />
if(ar.IsStoring()){<br />
int iSize = m_array1.GetSize();<br />
ar << iSize;<br />
for(int i = 0; i w iSize; i++){<br />
...<br />
}<br />
}else{<br />
m_array1.RemoveAll();<br />
<br />
int iSize;<br />
ar >> iSize;<br />
m_Array1.SetSize(iSize);<br />
for(int i = 0; i < iSize; i++){<br />
...<br />
}<br />
}<br />
}
I'm not absolutly sure of the syntax, I write it from memory
HTH,
K.
One small village of indomitable geeks still holds out against the invaders. And life is not easy for the managers legionaries who garrison the fortified camps of Microsoftum, Javum, Ceplumplum and Vebasum
|
|
|
|
|
Thks alot.
To read each element and add it to the array, can i use the code below?
SRawData *pData = new SRawData;
sscanf(strOneLine,"%g%g\n",pData->x,pData->y);
m_array1.Add(pData);
|
|
|
|
|
Why not using directly the archive ?
When loading:
SRawData *pData = new SRawData;
ar >> pData->x;
ar >> pData->y;
m_array1.Add(pData);
When writing:
SRawData *pData = m_array1.GetAt(i);
ar << pData->x;
ar << pData->y;
HTH,
K.
One small village of indomitable geeks still holds out against the invaders. And life is not easy for the managers legionaries who garrison the fortified camps of Microsoftum, Javum, Ceplumplum and Vebasum
|
|
|
|
|
Because i'm not familiar with CArchive and have never tried using them before ..Anyway i've tried the following.I think this has the right syntax,i've checked my books.However, it returns a "Failed to open document" dialog so i wrote the try-catch exception handling.
And it turns out that SetSize()is indeed creating problem. And the "Testing" Message Box appears a number of times before "Unexpected file format" is displayed.The document i was opening is a text file with 14 rows, 2 columns of values.
if(ar.IsStoring())
{ // writing the data
int iSize = m_array1.GetSize();
ar << iSize;
for(int i = 0; i < iSize; i++)
{
SRawData *pData = m_array1.GetAt(i);
ar << pData->x;
ar << pData->y;
}
}
else
{
m_array1.RemoveAll();
int iSize=13;
ar >> iSize;
try{
m_array1.SetSize(iSize);
}
catch(CMemoryException *e)
{
AfxMessageBox("Cant set size");
e->Delete();
}
for (int i = 0; i < iSize; i++)
{
AfxMessageBox("Testing");
SRawData *pData = new SRawData;
ar >> pData->x;
ar >> pData->y;
m_array1.Add(pData);
}
}
any idea wat is wrong now?Really appreciate your patience;)
|
|
|
|
|
Check your mail
One small village of indomitable geeks still holds out against the invaders. And life is not easy for the managers legionaries who garrison the fortified camps of Microsoftum, Javum, Ceplumplum and Vebasum
|
|
|
|
|
Firstly, i advise you to read at least a couple pages of any book about templates. It will help you to control a situation. As for your question, you should type:
CArray < SRawData, SRawData& > m_array1;
Notice that your function
CArray CRainAttDoc::GetRawDataArray()
will copy whole array since you return it by value, not by ref. It is better way to use
const CArray<......> & CRainAttDoc::GetRawDataArray() const
|
|
|
|
|
Thanks for your advice but i don't really understand the following
const CArray<......> & CRainAttDoc::GetRawDataArray() const
Can you teach me more explicitly how to pass by reference?I've tried passing a reference to an array before but it didn't work out.
Once again, thank you.
|
|
|
|
|
Can I also recommend that now is a good time to learn about vector, which is part of the STL ( i.e. part of C++ instead of part of Microsofts proprietary code ), and is far better than CArray ? CArray works fine, and the advice you've been given should get it working, but you will eventually wish it did something that the STL does, so now is a good time to learn the better alternative.
Christian
No offense, but I don't really want to encourage the creation of another VB developer.
- Larry Antram 22 Oct 2002
C# will attract all comers, where VB is for IT Journalists and managers - Michael
P Butler 05-12-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not
as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
I'd also like to learn STL with all its useful classes, but I don't know where to start, since STL is quite complex and has many functions like vector, list etc. Can you suggest me some good tutorials on STL apart from the ones here at cp.com?
thanks in advance
Greg
modified 12-Sep-18 21:01pm.
|
|
|
|
|
The ones here are easier ( I hope so, I wrote some of them ), but the definitive reference is www.sgi.com/tech/stl ( from memory, if it's wrong go to www.sgi.com and look for it ). That's where I go. Addison Wesley have several good books on STL, and I know that the main one on the standard library is available through Safari ( safari.oreilly.com ).
Have you looked at my tutorials here ? Is there any way in which they are not clear ?
Christian
No offense, but I don't really want to encourage the creation of another VB developer.
- Larry Antram 22 Oct 2002
C# will attract all comers, where VB is for IT Journalists and managers - Michael
P Butler 05-12-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not
as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
I have read all your tutorials about STL, and they are all great But I think that they cover only the basics (but they to that very well), and I'd like to go more into detail and get to know all the facets of STL. Thanks for the SGI link, seems to be exactly what I was looking for
best regards
Greg
modified 12-Sep-18 21:01pm.
|
|
|
|
|
I see - I thought you were saying the opposite, that you needed something easier to understand. Yes, the SGI site is an excellent place to take it further.
Christian
No offense, but I don't really want to encourage the creation of another VB developer.
- Larry Antram 22 Oct 2002
C# will attract all comers, where VB is for IT Journalists and managers - Michael
P Butler 05-12-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not
as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|