|
I am not getting what is your exact requirement any how I am giving you the skeleton to do sub clssing.Suppose handle of edit box is
hWndEdt
then
WNDPROC oldEditProcedure ;
WINAPI SubClassFunc(HWND hWnd,WORD Message,WORD wParam, LONG lParam);
oldEditProcedure = (WNDPROC) GetWindowLong(hWndEdt, GWL_WNDPROC);
SetWindowLong(hWndEdt, GWL_WNDPROC, (LONG)SubClassFunc);
do not forget to call in your destructor or at the appropriate place
SetWindowLong(hWndEdt, GWL_WNDPROC, (LONG)oldEditProcedure );
WINAPI SubClassFunc(HWND hWnd,
WORD Message,
WPARAM wParam,
LPARAM lParam)
{
if(Message == WM_PAINT)
{
SetWindowText(hWnd, "Hello SubClassFunc");
}
return CallWindowProc(oldEditProcedure, hWnd, Message, wParam, lParam);
}
|
|
|
|
|
All this is not required to solve the query that was asked. See the answer from Sarath.
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
base class:
class B ()
{
public:
virtual ~B(){};
}
No difference between the two derived classes below?
I've tried, both can destruct.
class D : public B
{
public:
virtual ~D(){}
}
class D : public B
{
protected:
virtual ~D(){}
}
|
|
|
|
|
followait wrote: No difference between the two derived classes below?
Nope. There is a difference (find it here [^]).
followait wrote: I've tried, both can destruct.
How?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Here is the code.
Though
D::~D() is protected, it works just like public, any differece?
#include <iostream>
#include <assert.h>
using namespace std;
class B
{
public:
B(){v();}
virtual ~B() {
assert(false);
int j=0;
++j;
}
virtual void v(){cout<<"B"<<endl;}
private:
};
class D : public B
{
public:
D(){v();}
protected:
~D() {
assert(false);
int i=0;
++i;
};
virtual void v(){cout<<"D"<<endl;}
private:
};
int main()
{
B *p=new D;
delete p;
return 0;
}
|
|
|
|
|
Your code does not compile. Anyway, probably you intended something similar to
#include <iostream>
#include <assert.h>
using namespace std;
class B
{
public:
B(){v();}
virtual ~B() {
cout<<"~B"<<endl;
}
virtual void v(){cout<<"B"<<endl;}
private:
};
class D : public B
{
public:
D(){v();}
protected:
~D() {
cout<<"~D"<<endl;
};
virtual void v(){cout<<"D"<<endl;}
private:
};
int main()
{
B *p=new D;
delete p;
return 0;
}
it outputs (maybe surprisingly):
B
D
~D
B
It compiles due to runtime binding. I.e. compiler doesn't know that D destructor will be called.
As someone already pointed out, however, you cannot use the following code
D d;
while
B b;
is legal.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Is this a loop hole in C++ or it is left like that for some specific reason?
|
|
|
|
|
It isn't a bug, it's feature. More likely a side effect, though.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
you mean accessing a virtual protected derived class member using a base class pointer is a feature?
|
|
|
|
|
Yes, it is a side effect of polymorphism.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Its the normal behaviour of virtual members, the access control is compile time restriction it depends on which function you call. see this, [Access to Virtual Functions^].
|
|
|
|
|
followait wrote: protected: virtual ~D(){}
Did you success in creating an object of the class D in another class or global function?
|
|
|
|
|
|
D objD;
can't be compiled, and
D *p=new D();
delete p;
also can't be compiled.
However,
B *p=new D();
delete p;
works.
I know, it should be called through the right interface.
Thanks.
|
|
|
|
|
Obvious that, that are the difference you can expect from the protected keyword, you cannot have obj of D allocated other than through new operator you can delete only through B and it remains correct only if B has virtual destructor.
I mean protected keyword does its job expected.
|
|
|
|
|
Hi,
Any one know which message Windows sent to Explorer windows indicating a new file is created so that it must refresh and indicate the new changes in the Explorer window.
thanks
Nitheesh
|
|
|
|
|
Nitheesh George wrote: Any one know which message Windows sent to Explorer windows indicating a new file is created so that it must refresh and indicate the new changes in the Explorer window.
I am not sure whether the explore is getting any message. May be the explorer is watching the changes in the current directory using ReadDirectoryChangesW() or using the FindFirstChangeNotification() function.
|
|
|
|
|
|
Hey everybody,
I got problem with prototype. I do have 2 classes both inherited from CDialog. And these two have pointer, which points each other.
It seems smt like this:
<br />
CChild : CDialog<br />
{<br />
CMain* parent;<br />
<br />
void doSmt();<br />
};<br />
<br />
CMain : CDialog<br />
{<br />
CChild* child;<br />
<br />
void doSmt();<br />
};<br />
I got a header file which includes Child first and Main after. OK now my problem is
if I do not write class prototype of Main in the header file before including Child header file it gives me error: CMain undeclared identifier which makes sense.
But, when I do write prototype:
<br />
class CMain;<br />
<br />
#include "CChild.h"<br />
#include "CMain.h"<br />
then it gives me use of undefined type CMain at the line which I call a function of CMain from CChild class.
And when I do (try to) write a prototype of DoSmt function:
<br />
class CMain;<br />
void CMain::doSmt();<br />
<br />
#include "CChild.h"<br />
#include "CMain.h"<br />
gives me the same error at line where I define function prototype.
So I guess the question is, how can I define prototype of my class function
Thanks....
|
|
|
|
|
dehseth wrote: class CMain;
#include "CChild.h"
#include "CMain.h"
then it gives me use of undefined type CMain at the line which I call a function of CMain from CChild class.
What is the source file compiling (whenever this error occurs)?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
source code is a lil bit long it makes more confusion if I paste it in here.
this error occurs during compiling:
I have 2 classes which points each other with pointers.
During compile I include child.h first and main.h later.
Since child class includes a main class pointer in itself it asks for the class. So I need to write a prototype for mainclass before including child class. When I write class CMain; it asks for Main class functions, cause child class calls function of main class. And here my problem starts cause compiler says undeclare identifier of CMain class...
So how can I declare a working prototype of CMain class to compile whole code
|
|
|
|
|
Deferred declaration (the one you used for class CMain should work, but you've define methods containing references to CMain methods inside CChild source (not inside the header).
for instance:
class A;
class B
{
A * _pA;
B(pA){_pA=pA;}
void DoSomethingWithA();
};
void B::DoSomethingWithA()
{
_pA->DoSomething();
}
should work, while
//FILE: B.h
class A;
class B
{
A * _pA;
B(pA){_pA=pA;}
void DoSomethingWithA()
{
_pA->DoSomething(); // ERROR, UNDEFINED REFERENCE
}
};
shouldn't.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
ok! I got a lil bit confused right now... You sound right. I need to include header files.. Well I did writye the source code bottom of header files which is wrong, I get that now!
Now my problem continues... These are the files I have got:
Main.cpp
Child.cpp
MSFLexGrid.cpp
Application.cpp
I include header files in each of them correctly. Compling each one one by one does not create any errors. But when I do Build, if says
error LNK2005: "int __cdecl getSize(char *)" (?getSize@@YAHPAD@Z) already defined in App.obj
cause it's already included in cpp file... So Do I have to write
#ifndef
directives to each header file
How can I build without having any linker errors??
Thanks...
|
|
|
|
|
How did you define such function? Where?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
ok I have solved the problem!
I've got linker error problems because I am defining Message Map declerations in header file.
I just move BEGIN_MESSAGE_MAP parts into cpp file and my problem is solved!
Thank you for your help!
|
|
|
|