|
The Directory Path must not be a static path in DlgDirList-Method!
Sample:
IDC_LIST1 is the box to be filled...
CString *temp1 = new CString("c:\\tmp\\style\\*.xsl");
LPTSTR str1 = temp1->GetBuffer(temp1->GetLength());
int ret=this->DlgDirList(str1,IDC_LIST1,0,0);
|
|
|
|
|
template<class Type> class CBase
template<class Type> class CChild : private CBase<Type>
CChild has members which point to a heap and have related Get and Set functions.
Is it possible for CBase to call it's child's member functions Get and Set to manipulate the heap...?
I've considered passing a pointer to the heap to CBase and just copying the Get/Set functionality into the base class, however this doesn't see to be appropriate and i might as well put everything into one class.
Using RTTI is it possible to obtain pointer to CChild from CBase and call it's Set/Get functions on the current heap rather than using my approach...?
TIA
"An expert is someone who has made all the mistakes in thier field" - Niels Bohr
|
|
|
|
|
HockeyDude wrote:
I've considered passing a pointer to the heap to CBase and just copying the Get/Set functionality into the base class, however this doesn't see to be appropriate and i might as well put everything into one class.
If CBase needs to operate on that data, why wouldn't you place that data in the CBase class? That is where it seems to belong to me.
HockeyDude wrote:
Using RTTI is it possible to obtain pointer to CChild from CBase and call it's Set/Get functions on the current heap rather than using my approach...?
This can be done, but once again, I believe that the data should probably go into the CBase class itself.
Could you give an example of why you want to put this data in the CChild class, and maybe there is a better solution that I could suggest?
kilowatt
|
|
|
|
|
CBase is actually CUndoBuffer and CChild is CBuffer
CBuffer has Get/Set/Del accessor/mutators
friend QSort
and is only going to get more complicated as time goes on.
CUndoBuffer implements a Push/Pop stack with
CanUndo
DoRedo
DoUndo
Clear
SetSize etc...
It makes easier sense to put em' all into one class, but i think more logical sense to seperate them
Cbuffer works with the heap funcitons and is getting pretty complex
CundoBuffer works with new/delete and is pretty trivial until realizing DoUndo/DoRedo don't have explicit(?) access to the Child's Redo/Undo
I personally would prefer to keep them seperated.
"An expert is someone who has made all the mistakes in thier field" - Niels Bohr
|
|
|
|
|
You can adopt the following approach:
template <class Type, class TChild> class CBase
{
...
void SomeMethod()
{
static_cast<TChild&>(*this).Get(...);
static_cast<TChild&>(*this).Set(...);
}
}:
template <class Type> class CChild: private CBase<Type, CChild>
{
...
}; See the idea? CChild passes its own type to CBase, thus informing the base class about whom child to delegate Get and Set . It's like a compile-time virtual function mechanism. This approach is extensively exploited in ATL.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Really...this will work..?
Sweet...I hope it does, i won't have to recosider my design
And it should solve all my problems
Really appreciate it!!
Thanx again and again
"An expert is someone who has made all the mistakes in thier field" - Niels Bohr
|
|
|
|
|
Seems like it shouldn't work because of circular references, but the fact is that this little trick compiles fine (and what's more, it does not incur in any run-time penalty, everything is resolved on compilation). To the best of my knowledge, it was the ATL guys the first who used this idiom.
Templates are a constant source of enjoyment and productivity. I feel sorry about C# & Java users with its "single hierarchy"/"no hassles"/"type-unsafe containers" languages!
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thanx again Joaquín.
Not only does it work, but it works great!
This totally simplifies the everything in my classes, instead of throwing it all into one big class I've seperated them, which is what was wanted. The 2-3 ideas i originally had required so much more overhead and some redudant code. This is great.
Only one question remains. Is this an example of downcasting sort of...? Also, doesn't this break the rules of OOP...? I'm positive this is the best solution for my particular problem, however if used improperly or too often this could cause spaghetti code correct...?
Thanx again!
"An expert is someone who has made all the mistakes in thier field" - Niels Bohr
|
|
|
|
|
Is this an example of downcasting sort of...?
Yes, downcasting is the process of going from a Base * to a Derived * .
Also, doesn't this break the rules of OOP...?
I don't think so; after all, its semantics strongly mimic that of virtual functions mechanisms (although in compile-time).
however if used improperly or too often this could cause spaghetti code correct...?
The main defect of this idiom, IMHO, is that it's little known among C++ programmers, which find it hard to understand at first. If it ever goes commonplace in the C++ community, the technique is as sound as many others. Think about this: 20 years ago, this idiom was probably seen as clumsy and tricky:
while(*dst++=*src++); Now it is only one of those gadgets people are accostumed to use in C/C++ code.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
hi,
what about this approach:
class CBuffer
{
public:
virtual void Set() = 0;
virtual void Get() = 0;
...
};
template<class TBuffer>
class CUndoBuffer
{
public:
...
void SomeFunc()
{
m_theBuffer.Set( whatever );
m_theBuffer.Get( whatever );
}
private:
TBuffer m_theBuffer;
};
class CConcreteBuffer : public CBuffer
{
public:
virtual void Set();
virtual void Get();
...
};
CUndoBuffer<CConcreteBuffer> AConcreteUndoBuffer;
etc..
..have fun..
jk
|
|
|
|
|
Don't pure virtual functions make it a ABC...?
CBuffer is not the base class it's the child which contains most of the functionality and would be much easier and I thought OOD friendly if it shared some of it's functionality with it's parent class. Which made me realize I don't understand inheritence, up/downcasting or MI as well as i thought;P
The template solution given by Joaquín seems most confusing but has no RT penalties.
right now as we speak Joaquín has me convinced, however perhaps you feel another solution is more appropriate.
Opinions...?
thanx again.
"An expert is someone who has made all the mistakes in thier field" - Niels Bohr
|
|
|
|
|
Who have seen the project ICONIZER in codeproject.com??? You can get it by http://codeguru.earthweb.com/shell/iconizer.zip
It is a great code. But I have found a big bug in it.
CASE: Open notepad.exe program -> run ICONIZER -> Open ABOUT DIALOG of notepad.exe -> exit ICONIZER -> press OK button in ABOUT DIALOG, finally, the notepad.exe crashed....
who can anwser this question???????
|
|
|
|
|
If I don't open taht ABOUT DIALOG, this bug will never appear...
|
|
|
|
|
Hi, everybody,
This may be a stupid question, but I really hope somebody to help me...
I got some trouble about the "unit" and "unit conversion" for rendering an image.
I have read some people's share codes on this web site. Those codes are all for image rendering with the COM interface IPicture. Here are my questions.
1. IPicture::get_Width: Returns the current width of the picture in the picture object. (from MSDN), the API is as follows:
HRESULT get_Width( OLE_XSIZE_HIMETRIC* pwidth //Receives a pointer to width );
My question is, what kind of unit we get from pwidth ? I mean, is pwidth in inch ? or in mini-meter ? or anything else ? Does this IPicture use MM_HIMETRIC coordinate system ?
2. If there are some code segment related to calculate the dimension (in pixels) of an image,
HIMETRIC_INCH is 2540
long hmWidth;
long hmHeight;
m_pPicture->get_Width(&hmWidth); /// m_pPicture is of type pointer to ///IPicture
m_pPicture->get_Height(&hmHeight);
rcResult.cx = MulDiv(hmWidth, pDC->GetDeviceCaps(LOGPIXELSX), HIMETRIC_INCH);
rcResult.cy = MulDiv(hmHeight, pDC->GetDeviceCaps(LOGPIXELSY), HIMETRIC_INCH);
Could anybody explain why HIMETRIC_INCH (2540) is used above ? And explain more about the above formula ? Is hmWidth (or hmHeight) in mini-meter ?
Thanks in advance ! Any reponse will be appreciated !
|
|
|
|
|
marouane miftah el kheir wrote:
C:\Windows\Desktop\mCpp2.cpp(8) : error C2146: syntax error : missing ';' before identifier 's'
Check your syntax. Are you missing a semicolon on one of your lines? Perhaps you're missing a semicolon after one of your "class {...};" definitions.
Jon Sagara
What about ?
|
|
|
|
|
LOL
He deleted all his posts
Nish
Sonork ID 100.9786 voidmain
www.busterboy.org
If you don't find me on CP, I'll be at Bob's HungOut
|
|
|
|
|
Too bad, I was willing to help him.
Jon Sagara
What about ?
|
|
|
|
|
Where do i find the exception-declaration info for try-catch statements...?
I'm currently using catch(...) but i'd like to be a little more specific.
Do i have to use (CException* e) with MFC apps?
I can't much on try/catch in the online docs...any ideas?
TIA
"An expert is someone who has made all the mistakes in thier field" - Niels Bohr
|
|
|
|
|
I have some problems with windows messaging
I create a Custom control with the create funtion in my InitDialog function:
m_pGrid = new CGridCtrl(22,9,0,0);
m_pGrid->Create(rect,this,1);
How can I set my dialog up to receive notification messages?
I would use:
ON_NOTIFY(GVN_ENDLABELEDIT, ???, OnGridStartSelChange)
but I do not have the ID of the control.
Thank You
LP
|
|
|
|
|
By specifying the ID in the Create Function.
Sometimes you just search in the wrong spot.
LP
|
|
|
|
|
Hi,
Just wondering if anyone has any ideas on the following.
I have a largish memory mapped file (~80Mb) to which data is being consistantly written to and read from. The problem lays in the once part of the MM file has been written to on Win 9x (the problem doesn't exist on NT) memory is used, the only way to free this memory is to completely close the MM file and re-open it. This is a large hit to take, ie 70-80% of CPU for approx 2 seconds when flushing every 30 seconds. Is there any way I can consistantly flush the data out of memory when it hasn't been used for a specified time?
Thanks
Stuart
|
|
|
|
|
in a MFC dialog based app, i got my previous app to work finally but i also need the edit box to be checked for entered text, if nothing is entered it has to generate a message box stating so when the show button is clicked.
like i said i got it all working, i can enter some text and click the button and have a box pop up displaying what i typed. but i'm not sure how to make the button check the edit box for text and display my error message.
also it's not important but where would i put the updatdata to clear the edit box once ok is clicked on the message box.
here's the part of code i'm referring to:
void CProgEx3Dlg::OnShow()
{
GetDlgItemText(IDC_TEXT,m_sText);
MessageBox(m_sText,"Sample Dialog Box",NULL);
}
thnx again in advance
|
|
|
|
|
I am writing a program.
In this program I wanna know whether the CD-ROM's door is Opened or Closed?
How I can write code?
|
|
|
|
|
hi there,
a good starting point is to search the MSDN for MCI . Another (but much harder) way is the function DeviceIoControl() .
..have fun..
jk
|
|
|
|
|
I wanna know which Function I can use ?
|
|
|
|