|
VC++ doesn't bother if it is an address pointing to start of an array or not. It knows that x is a pointer to double and size off double is 8 bytes. So, if u increment or decrement the pointer, the address will be recuced as multiple of 8 (for double).
But there is a chance of exception in the case of x[-1], since the location x-1 is not reserved for x and that location may not be free.
|
|
|
|
|
Hi,
I like to know if anyone knows how to have the child window of an MDI application maximized at the start of the application...
thanks
ehsan
Ehsan Behboudi
|
|
|
|
|
In the OnInitialUpdate() function of your application's View, write the following code
GetParentFrame()->ShowWindow(SW_SHOWMAXIMIZED);
For example, if the view class is CMyView, then do as follows.
void CMyView::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();
GetParentFrame()->ShowWindow(SW_SHOWMAXIMIZED);
}
Happy coding...
Rejeesh
|
|
|
|
|
it didn't work,,
i added the OnInitialUpdate fucntion from the wizard,,but it didn't work???
Ehsan Behboudi
|
|
|
|
|
It must work. I have done it. Do as follows.
1. Make a MDI project.
2. Using class wizard, add a new OnInitialUpdate() function in ur view class.
3. Add as follows,
void CTestView::OnInitialUpdate()
{
CView::OnInitialUpdate(); //Added by wizard
GetParentFrame()->ShowWindow(SW_SHOWMAXIMIZED);//Added by me
}
4. Compile and run the code.
5. It must work.
|
|
|
|
|
Im trying to understand virtual functions but cant see what they do. I presumed this would
be the situation I would use them in where I have two identical functions with same prototypes
which do different things, however this works as expected - outputs the base class cout, and
then the derived class one.
class CBadGuy {
public:
CBadGuy();
virtual ~CBadGuy();
void vfunc() { cout << "Base class vfunc.\n"; };
protected:
unsigned int speed;
unsigned int height;
char* description;
};
class CSoldier : public CBadGuy {
public:
CSoldier();
virtual ~CSoldier();
void vfunc() { cout << "Derived class vfunc.\n"; }
protected:
unsigned int numBullets;
};
int main() {
CBadGuy a;
CSoldier b;
a.vfunc();
b.vfunc();
return 0;
}
I cant understand why this works though, I thought that the funciton vfunc() would be ambigous when
I refered to it through object b as sureley this contains its own vfunc as well as the derived one.
Is it the case that I am simply "overloading" the b.func() function
Thanks,
Mark
|
|
|
|
|
Actually, you are not using virtual functions for vFunc. You are simply re-defining the base class function. To use virtual functions for this, you would need to modify your code to:
class CBadGuy {
public:
CBadGuy();
virtual ~CBadGuy();
virtual void vfunc() { cout << "Base class vfunc.\n"; };
protected:
unsigned int speed;
unsigned int height;
char* description;
};
class CSoldier : public CBadGuy {
public:
CSoldier();
virtual ~CSoldier();
virtual void vfunc() { cout << "Derived class vfunc.\n"; }
protected:
unsigned int numBullets;
};
int main() {
CBadGuy a;
CSoldier b;
a.vfunc();
b.vfunc();
return 0;
}
Even with this change you would get 'Base class vFunc' followed by 'Derived class vFunc'.
Often when using virtual functions it is desirable to not just "overide" a functions functionality, but to augment it. By doing this you can still use the base class implementation and only add what you want.
The following example demonstrates this.
class CBadGuy {
public:
CBadGuy();
virtual ~CBadGuy();
virtual void vfunc() { cout << "Base class vfunc.\n"; };
protected:
unsigned int speed;
unsigned int height;
char* description;
};
class CSoldier : public CBadGuy {
public:
CSoldier();
virtual ~CSoldier();
virtual void vfunc() { cout << "Derived class vfunc.\n"; CBadGuy::vFunc();}
protected:
unsigned int numBullets;
};
int main() {
CSoldier b;
b.vfunc();
return 0;
}
This will result in 'Derived class vFunc' followed by 'Base class vFunc'. This can be very useful if you are creating your objects at run-time (ie new CSoldier) and passing them as pointers to CBadGuy); The following example demonstrated this.
class CBadGuy {
public:
CBadGuy();
virtual ~CBadGuy();
virtual void vfunc() { cout << "Base class vfunc.\n"; };
protected:
unsigned int speed;
unsigned int height;
char* description;
};
class CSoldier : public CBadGuy {
public:
CSoldier();
virtual ~CSoldier();
virtual void vfunc() { cout << "Derived class vfunc.\n"; }
protected:
unsigned int numBullets;
};
int main() {
CSoldier* pSolider = new CSoldier;
TestObject(pSoldier);
return 0;
}
void TestObject(CBadGuy* pTest)
{
pTest->vFunc();
}
In this scenario you would get the 'Dervice class vFunc' as output. This can be extremely powerful when you have a "class" of objects which share basic functionality and purpose but need to work in different ways.
|
|
|
|
|
virtual functions are useful when we use base class pointer to access derived class objects.
class CBadGuy {
public:
CBadGuy(){};
virtual ~CBadGuy(){};
virtual void vfunc() { cout << "Base class vfunc.\n"; };
protected:
unsigned int speed;
unsigned int height;
char* description;
};
class CSoldier : public CBadGuy {
public:
CSoldier(){};
virtual ~CSoldier(){};
virtual void vfunc() { cout << "Derived class vfunc.\n"; }
protected:
unsigned int numBullets;
};
int main() {
CBadGuy *pBadGuy;
CSoldier b;
pBadGuy = &b;
pBadGuy->vfunc(); //This will call the derived class vfunc()
//If the vfunc() is not declared as virtual in the base class,
//the above call will call the base class vfunc() function.
|
|
|
|
|
Hi
I have a CListctrl & Iam intersted in creating a tooltip in the form f a PopUp window when I select any item in the CListCtrl . Can anybody explain how I can do this ?? Any Sample code would be very useful.
The ClistCtrl is placed in a dialog box. When I try to implement the OnLButtonDown to know whether the left button of mouse is clicked inside the control, it doesn't respond but actually, the control is being trapped by the parent window ( Dialog Box ). Eventually the HitTest member function of the CListCtrl fails.
Thanks
regards
Sankar
|
|
|
|
|
Handle LVN_ITEMCHANGING (or LVN_ITEMCHANGED) to be notified before (after) the selection changes.
--Mike--
http://home.inreach.com/mdunn/
#include "buffy_sig"
|
|
|
|
|
I have the following code, which looks fine but every time the connection fails... the database is an Access 2000 database in the same directory as the VC project:
void CTest9Dlg::OnButton1()
{
_ConnectionPtr m_pConnection = NULL;
char* m_strConnection = _T("Provider=Microsoft.Jet.OLEDB.4.0; Data Source = db1.mdb");
m_pConnection.CreateInstance(__uuidof(Connection));
try
{
HRESULT hr;
hr = m_pConnection->Open(_bstr_t(m_strConnection), "", "", NULL);
if(hr == S_OK) {
TRACE("Connected");
MessageBox("Connected");
}
}
catch(_com_error &e)
{
TRACE("Connect Failed.");
MessageBox("Failed!");
}
}
Thnaks for your help
|
|
|
|
|
The 2 most common mistakes I make is to not call 'OleInitialize(NULL)' (or some variant ie. AfxOleInit()). Also, is the MDB file in your project directory of your build directory (ie. Debug/Release). If is is your project directory you may need to reference the DB like
char* m_strConnection = _T("Provider=Microsoft.Jet.OLEDB.4.0; Data Source = ../db1.mdb");
|
|
|
|
|
I'm working on an application (let's call it SCONES) which can be used as an OLE server, so that its results can be embedded in Word docs, for example. Now, I know I need to implement the Serialize() function for all my data objects for OLE purposes. On the other hand I don't want to use MS's proprietary file format for saving SCONES files to disk when it's not being an OLE server - I want to use XML. Do I have to write two separate sets of code for file saving and loading, or is there some smart way of doing both tasks in one? I can't be the first to encounter this problem, surely?
Peter Robinson
|
|
|
|
|
Hello Dear.
I have windows 98. I'm trying to execute a chatter application which is avaialbe in MSDN. But it is displaying the message & not executing. Message is giving below:
"This Application or Dll can not be loaded on windows 95 or on windows 3.1. It takes advantages of unicode features only available on windows NT."
When I press OK button, it display an other error message "The MFC42UD.DLL file cannot start. Check the file to determine the problem."
When I press ok on this button it terminates my application.
Pls replty me soon. I'll be thankful to you.
|
|
|
|
|
Can't tell you much more than they are - this program requires Unicode, and therefore requires Windows NT or 2000. It won't run under W98.
Christian
#include "std_disclaimer.h"
People who love sausage and respect the law should never watch either one being made.
The things that come to those who wait are usually the things left by those who got there first.
|
|
|
|
|
i want to store key value pairs and access them ,
i want a return type of function to be CMap or something like it,
but this is not possible, = operator not overloaded
is there any alternative ?
parag
|
|
|
|
|
The STL map collection has assignment operation and copy constructor, so you can return a std::map from a function.
|
|
|
|
|
It doesn't make sense to return map by value - it involves creating temporary object and this operation may be costly depending on the size of your map. You should pass the map object by reference:
void foo(CMyMapClass & map);
Tomasz Sowinski -- http://www.shooltz.com.pl
|
|
|
|
|
Why this code doing me troubles ???????????
----------------------------------------------
void CFilesDlg::OnButton1()
{
// TODO: Add your control notification handler code here
CString str(50);
str = "22223333333333222";
CFile file;
if(file.Open("string.data",file.modeWrite|file.modeNoTruncate|file.modeCreate))
file.Write(&str,sizeof(str));
}
void CFilesDlg::OnButton2()
{
// TODO: Add your control notification handler code here
CString str(50);
CFile file;
if(file.Open("string.data",file.modeRead))
file.Read(&str,sizeof(str));
MessageBox(str);
}
---------------------------------------------------------
mimi
|
|
|
|
|
You need to tell us what's going wrong. Compile errors? Not giving the right output when you run it?
--Mike--
http://home.inreach.com/mdunn/
#include "buffy_sig"
|
|
|
|
|
1/ I don't see any CString constructors that take a number
2/ you want to use str.GetLength() instead of sizeof(str).
3/ If the 50 was meant to be a size, you put less than 50 characters into the buffer before writing.
Christian
#include "std_disclaimer.h"
People who love sausage and respect the law should never watch either one being made.
The things that come to those who wait are usually the things left by those who got there first.
|
|
|
|
|
I changed little my code but the problem remained !
It is ok in compilation but write nonsense in the file and same in the messageBox.
Why ??????
--------------------------------------------------------------------------
void CFilesDlg::OnButton1()
{
// TODO: Add your control notification handler code here
CString str("222233772");
CFile file;
if(file.Open("string.data",file.modeWrite|file.modeNoTruncate|file.modeCreate))
file.Write(&str,str.GetLength());
}
///////////////////////////////////////////////////////////
void CFilesDlg::OnButton2()
{
// TODO: Add your control notification handler code here
char str[50];
CFile file;
if(file.Open("string.data",file.modeRead))
file.Read(str,10);
MessageBox(str);
}
---------------------------------------------------------------------
|
|
|
|
|
void CFilesDlg::OnButton1()
{
CString str(50);
str = "22223333333333222"; There's no such constructor for CString. Use
CString str("22223333333333222");
instead
CFile file;
if(file.Open("string.data",file.modeWrite|file.modeNoTruncate|file.modeCreate))
file.Write(&str,sizeof(str));
&str doesn't return a pointer to the characters contained in the CString, and sizeof(str) isn't the string length. To write the contents of the CString instead of pointers, reference counts and other useless information:
file.Write(str, str.GetLength());
}
void CFilesDlg::OnButton2()
{
CString str(50); Same error as before, use
CString str;
CFile file;
if(file.Open("string.data",file.modeRead))
file.Read(&str,sizeof(str));
What you need here is:
{
int len = file.Read(str.GetBuffer(50), 50);
str.ReleaseBuffer(len);
}
MessageBox(str);
}
|
|
|
|
|
now it is ok !
you are explain excellentand very clear.
thank you!
|
|
|
|
|
&str is your problem.
just use str.
CString has a (char *) overload
|
|
|
|