|
shouldn't i reserve memory & copy the szFilename instead of just having m_szFilename member point to it?
Definitely. Use CString or std::string for that.
the derived classes need to use the header file anyway, so they do know the value, don't they?
If you leave the #define in .h the will know, but this isn't a good thing. You're exposing an implementation detail and breaking encapsulation.
What do you mean with create a static function in CInitFile.
If derived classes really need to know what's the default value of filename, you should implement it this way:
class CInitFile
{
static const char* GetDefaultFilename();
};
const char* CInitFile::GetDefaultFilename()
{
return "Whatever.txt";
}
How would you implement the design so i could force the derived class to make a function to initialise his member data
You can't do that. You don't know what exactly is 'His member data'. Even if virtual function would be called virtually from ctor (it isn't), derived class could simply omit some initializations.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Thanks Tomasz! these are the kind of answers i was looking for.
bene
|
|
|
|
|
Hi,
i have a question on class design. I want to build a simple class to save
inifile settings in a binary fle. I started designing and made a class called
CInitfile. This class can only be used to derive classes from s then you
end up with someting like CRecStudioInitfile. Mind i'm still in the design
phase of things so the focus is on the classes, not on the code.
No i have a number of questions and i have marked the code that is related
to the question with a tag like (1) so you can see the part of the code i'm
talking about.
(1) If no arguments are passed, i want the constructur to make an init file
with the default name as specified by INIT_FILENAME. If a name is specified
i want to assign a name. Is the way i'm doing that ok in the base class?
What about the derived class?
(2) What should happen then is that in the constructor, all parameters should be initialised. Since i have 2 constructors and wanted to avoid placing the same code in both functions, i wanted to call another function from both constructors.
This initialisation is a necessity for me, so it seems like i need to specify
a pure virtual function in the base class so the derived classes woul have to build their own version. That was all going ok, but then i want to force this function to be loaded automatically by the constructor. I wanted to define this in the base class but i got an error and had to add (3) in the cpp file.
So i wanted to make sure that the baseclass initializes m_szFilename with either the default name or a name that is specified and after that, forces a function (here InitialiseParameters() ) to be called so that you are sure the memberdata is initialised. By making this function InitialiseParameters() virtual i was hoping to make sure that the derived classes should have one and by putting this in the baseconstructor i wanted to make sure the InitialiseParameters() of the derived class was called.
How do i encorporate such a design?
Thanks.
================== initfile.h ==================
#ifndef _INITFILE_H_
#define _INITFILE_H_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "errorexc.h"
#include "resource.h"
#define INIT_FILENAME _T("logfile.txt") // (1)
class CInitfile {
// since we don not want people to use this class immediately (they need
// to derive a class from this base class)
protected:
// constructor
CInitfile() { CInitfile(INIT_FILENAME); }; // (1)
CInitfile(const _TCHAR *szFilename) : m_szFilename(szFilename) { InitialiseParameters(); }; // (1)
// destructor
virtual ~CInitfile() {};
public:
// Pure virtual functions
virtual BOOL ReadInitfile() const = 0 ; // force derived class to make his own readfile
virtual BOOL WriteInitfile()= 0; // force derived class to make his own writefile
const _TCHAR* GetFilename() {return m_szFilename;};
private:
virtual void InitialiseParameters()=0; // this should be defined in all derived classes //(2)
const _TCHAR *m_szFilename; //filename of the file that is used to store/restore parameters too
};
class CRecStudioInitfile : public CInitfile
{
public:
// constructor & destructor
CRecStudioInitfile() {}; // (1)
CRecStudioInitfile(const _TCHAR *szFilename) : CInitfile(szFilename){}; // (1)
virtual ~CRecStudioInitfile();
BOOL ReadInitfile() const;
BOOL WriteInitfile();
// private data is all the data we want to save
private:
void InitialiseParameters(); //(2)
BOOL m_bLogMemoryToFile;
// other datamembers to come here
};
#endif // ifndef _INITFILE_H_
================== initfile.h ==================
================== initfile.cpp ==================
#include "stdafx.h"
#include "initfile.h"
// had to do this to avoid compile errors
void CInitfile::InitialiseParameters(){}; // (3)
CRecStudioInitfile::~CRecStudioInitfile()
{
}
BOOL CRecStudioInitfile::ReadInitfile() const
{
// no code yet
return TRUE;
}
BOOL CRecStudioInitfile::WriteInitfile()
{
// no code yet
return TRUE;
}
void CRecStudioInitfile::InitialiseParameters()
{
m_bLogMemoryToFile = FALSE;
// other data that needs to be initialised
}
================== initfile.cpp ==================
|
|
|
|
|
pliz look at this code and tell me what is wrong here:
void CFtpExDlg::ExploreDir()
{
CFileFind finder;
BOOL b;
CString name;
//clear the list first
m_FileList.DeleteAllItems();
//clear the fImageList
int count = fImageList.GetImageCount();
for (int i = 0 ; i
|
|
|
|
|
Well the following line makes no sense ...
for (int i = 0 ; i fImageList.Remove(0);
Hope that solves your problem.
Steve T
|
|
|
|
|
Please help, I think I must be going mad!!
I'm in the middle of writing a class to do owner-drawn buttons (to combine the Cool Button of Norm Almond and the Flat Button of Davide Calabro) and I'm having a bit of trouble with the button styles.
The button I'm testing with has only the BS_OWNERDRAW style set (as enforced by the PreSubClassWindow function override). In the DrawItem override I need to check whether the BS_DEFPUSHBUTTON style is set to establish whether or not to draw a thick border. This is where the problem begins as highlighted with the following code:
BOOL bDefaultBtn = FALSE;
UINT nStyle = GetButtonStyle ();
UINT nAND = nStyle & BS_DEFPUSHBUTTON;
if (nAND == BS_DEFPUSHBUTTON) {
bDefaultBtn = TRUE;
}
BS_DEFPUSHBUTTON is defined in winuser.h (?) as 0x01L which is 0001 in binary, but BS_OWNERDRAW is defined as 0x0BL which is 1011 in binary. So, in the above example, the value for nStyle is 0x0BL (or 1011) as it should be because it's only got the BS_OWNERDRAW style set. But when I bitwise AND it with BS_DEFPUSHBUTTON (0001) I get 0001!!!!!!
The value for BS_DEFPUSHBUTTON also clashes with BS_CHECKBOX (0x02L) and BS_USERBUTTON (0x08L) although this one is now obsolete. So whenever you check an owner-drawn button for the default style it always appear to be the default when it isn't.
You can see this in evidence in either of the above two mentioned owner drawn buttons when they aren't flat because they are always drawn as default buttons, having used GetWindowLong to determine the style and AND'ed it with BS_DEFPUSHBUTTON.
Who's messed up here, me or Microsoft?? Or I am I just being stupid?
Derek.
|
|
|
|
|
Someone may problem me completely wrong
I think I've heard somewhere that you can't have a default button owner drawn, so in the owner drawn code you have to implement your own flag fo displaying a think line around it. Then to make it act as a default button, ( ) play with the tab order.
|
|
|
|
|
Thanks for your input.
It looks like thats how I'm going to have to do it
|
|
|
|
|
Hi Derek,
If you can wait a few days for this, I'm writing an article on how to solve this problem, that is how to enable default state for an owner-draw button.
I wrote 1/2 article, so please be patient.
Paolo.
|
|
|
|
|
So far I've implemented it as a separate function call in the class, which provides access to a boolean data member.
I'll be interested to read your article.
|
|
|
|
|
I need to convert a double to a string, because i want to use setwindowtext, but i don't know we could use ecvt(), or fcvt(). How do they work?
thanks.
gerald
|
|
|
|
|
There's plenty of examples on the web & msdn.
int sign=0, decimal=0;
double dval=9999.9999;
char* str;
str = _ecvt(dval, 10, &sign, &decimal);
Easy way.
char buf[21]={0x00};
double dValue = 9.9;
sprintf(buf,"%.2f",dValue);
Only thing to watch is the precision with formatting strings.
Gerry.
|
|
|
|
|
I have created a Dialog box app. All my processing is in ***dlg.cpp.
The app runs fine except for ... The window does not refresh. I have to move the
mouse over the app to refresh the window.
I have tried ShowWindow(SW_SHOW) and UpdateData(FALSE) to no avail.
Please Help.
Thanx
Leezo
|
|
|
|
|
Neither of these force a paint mesage. When you change your data, call Invalidate(false) to force a redraw without erasing the dialog first. Get rid of false to make it also erase.
Christian
#include "std_disclaimer.h"
The careful application of terror is also a form of communication.
Eagles may soar, but weasels don't get sucked into jet engines.
|
|
|
|
|
I'm using ADO to do a connection with Access database. I have a dlgbox with editbox which are linked to this app. When i do the loop:while(!pRs->EndOfFile)
{
if(m_dlglDate==rs.m_ch_RateDate)
{....}
I would like to return value in an editbox when my test "if" succeeded, so how could i do that?
thanks in advance
gerald
|
|
|
|
|
Do you mean, just pass a value into the editbox field?
if so,I just use DDX &
m_EditControl.SetWindowText("VALUE");
or
SetDlgItemText(IDC_EDIT1,"VALUE");
Gerry.
|
|
|
|
|
yes, exactly, if i could find the value in the database i want to return it in the editbox, but it could be a COleDateTime or a double, so i believe that setwindowtext return string. How could i return a double value or a COleDateTime value in editbox?
|
|
|
|
|
There are plenty of ways to convert a double to a string.
Function _ecvt for one. double to string pointer.
As for COleDateTime,
COleDateTime x(1999, 3, 19, 22, 15, 0);
CString str = x.Format(_T("%A, %B %d, %Y"));
m_EditBox.SetWindowText(str);
Hope this helps....
Gerry.
|
|
|
|
|
Hi All,
I have a query regarding MS Access Database.I am creating a Database & a table in it .I add the Records to the table.The size of teh Database mdb file is increasing as I add the record.But, when I deleted all the REcords in the table in Database, the size of the Database remained the same(as before deletion of REcords).Why is it so ?I am using ADOX to add the Records & the same to delete the Records .
How can I overcome this problem ?
Does in MS Access the size of Database decrease on deletion of Records if any ?If so how it can be done ?
YAMINI
|
|
|
|
|
What I use to do was, to repair the db.
Tools, Database Utilities, Repair
&
Then use compact. Not sure why it happens. Might have something to do with system objects in access?
Gerry.
|
|
|
|
|
Hi All,
I have a query regarding MS Access Database.I am creating a Database & a table in it .I add the Records to the table.The size of teh Database mdb file is increasing as I add the record.But, when I deleted all the REcords in the table in Database, the size of the Database remained the same(as before deletion of REcords).Why is it so ?I am using ADOX to add the Records & the same to delete the Records .
How can I overcome this problem ?
Does in MS Access the size of Database decrease on deletion of Records if any ?If so how it can be done ?
YAMINI
|
|
|
|
|
You have to compress the database. I can not remember how to do it from C++, but it's possible to do through ADO...
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
Hello,
I'm urgently looking for a nice little commandline tool (with stdoutput) to stamp the version of an executable (Major, Minor, Build).
Has anybody come across something?
Thanks,
Matthias
|
|
|
|
|
You can quickly create you own program to extract this type of information.
On nt, you have version.dll, which has windows api function GetFileVersionInfo.
Good luck.
Gerry.
|
|
|
|
|
I want to get the cchTextMax property of treeview item.
I'm using the following:
TVITEM tvitem;
tvitem.hItem = m_tree->GetSelectedItem();
tvitem.mask = TVIF_TEXT ;
m_tree->GetItem (&tvitem);
but it doesn't work
at the same time code:
TVITEM tvitem;
tvitem.hItem = m_tree->GetSelectedItem();
tvitem.mask = TVIF_IMAGE ;
m_tree->GetItem (&tvitem);
works correctly
|
|
|
|