15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


OnCreate

Joao Vargem -- jpv.loyaltech@taguspark.pt
Monday, March 17, 1997

Environment:    Windows 95, MSVC++ 4.1 

        Hi all. My problem is this:
       I've derived my own class 'ClEdit' from CEdit and I need to pass
information to my
controls during their creation. For that I use the creation data
parameter in the DLGITEMTEMPLATE structure. The manuals say this
creation data is passed to the control in the:
        - WM_CREATE message (MSDN);
        - when the windows call the CreateWindowEx function (MSVC on
line help).

My problem is that my controls OnCreate function doesn't even get
called. If anyone could help me I'd really apreciate. 

Just another thing. Could anyone also explain me when does the control
class get attached to the
window? Is it on the DDX_Control call? But at this time the window is
already created. I can't grasp when or how does the framework knows that
when it is creating this control window it must send the WM_CREATE
message to that class.
TIA
-- 
				Joao Vargem	(jpv.loyaltech@taguspark.pt)
				LoyalTech Portugal SA
				Oeiras, Portugal



CADS Software Developer -- jonathan@pindar.com
Wednesday, March 19, 1997

[Mini-digest: 9 responses]

Did you include the ON_WM_CREATE() entry in your control's message map ?

@:-) Jonathan Cox (jonathan@pindar.com)

----------
> From: Joao Vargem 
> To: MFC Mailing List 
> Subject: OnCreate
> Date: 17 March 1997 17:55
> 
> Environment:    Windows 95, MSVC++ 4.1 
> 
>         Hi all. My problem is this:
>        I've derived my own class 'ClEdit' from CEdit and I need to pass
> information to my
> controls during their creation. For that I use the creation data
> parameter in the DLGITEMTEMPLATE structure. The manuals say this
> creation data is passed to the control in the:
>         - WM_CREATE message (MSDN);
>         - when the windows call the CreateWindowEx function (MSVC on
> line help).
> 
> My problem is that my controls OnCreate function doesn't even get
> called. If anyone could help me I'd really apreciate. 
> 
> Just another thing. Could anyone also explain me when does the control
> class get attached to the
> window? Is it on the DDX_Control call? But at this time the window is
> already created. I can't grasp when or how does the framework knows that
> when it is creating this control window it must send the WM_CREATE
> message to that class.
> TIA
> -- 
> 				Joao Vargem	(jpv.loyaltech@taguspark.pt)
> 				LoyalTech Portugal SA
> 				Oeiras, Portugal
-----From: Mario Contestabile

>Just another thing. Could anyone also explain me when does the control
>class get attached to the
>window? Is it on the DDX_Control call?

Yes. Take a dialog for example. OnInitDialog() calls UpdateData which
calls your DoDataExchange(). Your DDX_Control(..) lines there simply
calls thecontrol.SubClassWindow(HWND of ID) thus routing the CWnd
messages through the control's message map first. You can then call the
base class in your handler to pass the message to the default handler.

Mario
mcontest@universal.com

-----From: "Kenneth A. Argo" 

Reading between the lines in your message I suspect that you must be =
using a control that lives on a dialog resource.  If this is correct =
than you will never get a call to OnCreate() since the dialog manager is =
the one creating the controls.  You are correct in your assumption that =
the control is already created by the time MFC knows about it, that is =
unless you are actually calling the Create() function for the control.

The call to the DDX routine is where things get linked up, it is first =
called after the controls have been created, but before the dialog is =
visible.  It has been a long misunderstanding that you need to Subclass =
a control if you want it to be one of your own.  This is in fact false =
since it is possible to link your own derived control in using the =
features of DDX, of course if you want to you can still do it the old =
fashion way.

Ken



-----Original Message-----
From:	Joao Vargem [SMTP:jpv.loyaltech@taguspark.pt]
Sent:	Monday, March 17, 1997 12:56 PM
To:	MFC Mailing List
Subject:	OnCreate

Environment:    Windows 95, MSVC++ 4.1=20

        Hi all. My problem is this:
       I've derived my own class 'ClEdit' from CEdit and I need to pass
information to my
controls during their creation. For that I use the creation data
parameter in the DLGITEMTEMPLATE structure. The manuals say this
creation data is passed to the control in the:
        - WM_CREATE message (MSDN);
        - when the windows call the CreateWindowEx function (MSVC on
line help).

My problem is that my controls OnCreate function doesn't even get
called. If anyone could help me I'd really apreciate.=20

Just another thing. Could anyone also explain me when does the control
class get attached to the
window? Is it on the DDX_Control call? But at this time the window is
already created. I can't grasp when or how does the framework knows that
when it is creating this control window it must send the WM_CREATE
message to that class.
TIA
--=20
				Joao Vargem	(jpv.loyaltech@taguspark.pt)
				LoyalTech Portugal SA
				Oeiras, Portugal


-----From: spencer@cix.compulink.co.uk (Steve Spencer)

In-Reply-To: <332D85AB.65F0@taguspark.pt>
On 17th March, Joao Vargem (jpv.loyaltech@taguspark.pt) said;
> I've derived my own class 'ClEdit' from CEdit and I need to pass
> information to my controls during their creation. For that I use
> the creation data parameter in the DLGITEMTEMPLATE structure. The
> manuals say this creation data is passed to the control in the:
>         - WM_CREATE message (MSDN);
>         - when the windows call the CreateWindowEx function (MSVC on
> line help).
> 
> My problem is that my controls OnCreate function doesn't even get
> called. If anyone could help me I'd really apreciate. 
> 
> Just another thing. Could anyone also explain me when does the control
> class get attached to the
> window? Is it on the DDX_Control call? But at this time the window is
> already created. I can't grasp when or how does the framework knows that
> when it is creating this control window it must send the WM_CREATE
> message to that class.

Joao, your subclassed ClEdit is still a standard "EDIT" control, I 
assume, but you are handling some of the messages. If this is the case, 
then neither your ClEdit::OnCreate or CEdit::OnCreate will be called. 
This is because the control class gets attached to the window on the 
DDX_Control call, as you believed. So the framework DOESN'T send the 
WM_CREATE message to the class.

Why must the information be passed at creation time? Normally for 
dialogs, you can set things up in your derived OnInitDialog code, when 
the controls exist, but are not yet shown. The only way you would be able 
to do what you want would be to register a window class "ClEdit", and 
name the control in the dialog as being of that type. That might be more 
complicated than fiddling with your dialog's OnInitDialog function. You 
could always define another dialog constructor, which took parameters, 
which could then be examined in OnInitDialog to adjust your ClEdit stuff.
For example;

struct myInfo {
        UINT controlID;
        char *initData;
};
class CMyDialog : public CDialog
{
 ...
        CMyDialog(CWnd*pWnd = NULL, struct myInfo*pInfo = NULL);
 ...
 private:
        struct myInfo *pValue;
};

CMyDialog::CMyDialog(CWnd*pWnd, struct myInfo*pInfo) :   
CDialog(CMyDialog::IDD, pWnd)
{
        pValue = pInfo;
}
BOOL CMyDialog::OnInitDialog()
{
        CDialog::OnInitDialog();
        ClEdit*pCtrl;
        if (pValue)
        {
                while (pValue->controlID!=0)
                {
                        pCtrl = (ClEdit*)GetDlgItem(pValue->controlID);
                        if (pCtrl)
                        {
                                Ctrl->SetUp(pValue->initData);
                        }
                }
        }
        return TRUE;
}

Hope this helps...

Steve Spencer
spencer@cix.co.uk
[
Why don't we all send Mike B 50 cents each. Then he could afford more 
vowels for his surname, and we'd all be able to pronounce it correctly. 
]

-----From: "Peter R. Vermilye" 

I'll take a stab at this answer as I was stumped by this as well and
here's what I THINK is happening:  Windows itself creates the
dialog/controls (when loading them from the resources, that is) NOT MFC
so MFC doesn't know anything about the dialog/controls until after the
fact (hence, no OnCreate() calls).  The first crack you have at the
dialog is in the InitDialog() or OnInitialUpdate() call.  You must FIRST
call the base class in order for all the attachments to be made.  During
the execution of the base class's InitDialog() or OnInitialUpdate()
call, the DoDataExchange() function gets called the first time which
actually links everything together.

Hope this helps and is reasonably accurate!!

-- 

Peter R. Vermilye
cpudude@netten.net

PS: Who does Microsoft call for help?

Joao Vargem wrote:
> 
> Environment:    Windows 95, MSVC++ 4.1
> 
>         Hi all. My problem is this:
>        I've derived my own class 'ClEdit' from CEdit and I need to pass
> information to my
> controls during their creation. For that I use the creation data
> parameter in the DLGITEMTEMPLATE structure. The manuals say this
> creation data is passed to the control in the:
>         - WM_CREATE message (MSDN);
>         - when the windows call the CreateWindowEx function (MSVC on
> line help).
> 
> My problem is that my controls OnCreate function doesn't even get
> called. If anyone could help me I'd really apreciate.
> 
> Just another thing. Could anyone also explain me when does the control
> class get attached to the
> window? Is it on the DDX_Control call? But at this time the window is
> already created. I can't grasp when or how does the framework knows that
> when it is creating this control window it must send the WM_CREATE
> message to that class.
> TIA
> --
>                                 Joao Vargem     (jpv.loyaltech@taguspark.pt)
>                                 LoyalTech Portugal SA
>                                 Oeiras, Portugal

-----From: "Jason Healy" 

When you create controls, within a dialog resource,  WM_CREATE messages 
are sent to the native windows windows procedure (ie in your case to the
class
"edit" window proc. What you are doing is subclassing the control to your
member, 
which simply attaches the HWND and replaces the window proc after it has
been created hence the OnCreate function is not called.

You have a number of choices,
	
1.	Create the control dynamically, in your OnInitDialog.
	This has draw backs, about positioning and Tab order.

2.	Use Custom Controls, a lot of work is involved 

or

3.	Override the PreSubclassWindow function in your
	derived control and put your code in here.

Jason
jason@hkjcs.oz.au



----------
> 
> Environment:    Windows 95, MSVC++ 4.1 
> 
>         Hi all. My problem is this:
>        I've derived my own class 'ClEdit' from CEdit and I need to pass
> information to my
> controls during their creation. For that I use the creation data
> parameter in the DLGITEMTEMPLATE structure. The manuals say this
> creation data is passed to the control in the:
>         - WM_CREATE message (MSDN);
>         - when the windows call the CreateWindowEx function (MSVC on
> line help).
> 
> My problem is that my controls OnCreate function doesn't even get
> called. If anyone could help me I'd really apreciate. 
> 
> Just another thing. Could anyone also explain me when does the control
> class get attached to the
> window? Is it on the DDX_Control call? But at this time the window is
> already created. I can't grasp when or how does the framework knows that
> when it is creating this control window it must send the WM_CREATE
> message to that class.
> TIA
> -- 
> 				Joao Vargem	(jpv.loyaltech@taguspark.pt)
> 				LoyalTech Portugal SA
> 				Oeiras, Portugal


-----From: "Dan Kirby" 

You're correct.  Your CIEdit C++ object doesn't get hooked up with the
control until after it has been created and the DDX functions do their
thing. That's too late.

Part of the problem here is that you are using a standard windows control
and then subclassing the window procedure of the control at some later time
using your CIEdit object.  This is too late to catch the WM_CREATE.   You
could use superclassing.  That is where you get the class information for
the edit control using GetClassInfo(), register a new class with a new
window procedure which you define,and then specify that class name in the
dialog template. 

Maybe all of this is more than you really need.  Perhaps you could explain
more about what it is that you are trying to do.

--dan

----------
> From: Joao Vargem 
> To: MFC Mailing List 
> Subject: OnCreate
> Date: Monday, March 17, 1997 9:55 AM
> 
> Environment:    Windows 95, MSVC++ 4.1 
> 
>         Hi all. My problem is this:
>        I've derived my own class 'ClEdit' from CEdit and I need to pass
> information to my
> controls during their creation. For that I use the creation data
> parameter in the DLGITEMTEMPLATE structure. The manuals say this
> creation data is passed to the control in the:
>         - WM_CREATE message (MSDN);
>         - when the windows call the CreateWindowEx function (MSVC on
> line help).
> 
> My problem is that my controls OnCreate function doesn't even get
> called. If anyone could help me I'd really apreciate. 
> 
> Just another thing. Could anyone also explain me when does the control
> class get attached to the
> window? Is it on the DDX_Control call? But at this time the window is
> already created. I can't grasp when or how does the framework knows that
> when it is creating this control window it must send the WM_CREATE
> message to that class.
> TIA
> -- 
> 				Joao Vargem	(jpv.loyaltech@taguspark.pt)
> 				LoyalTech Portugal SA
> 				Oeiras, Portugal
-----From: "Dmitry A. Dulepov" 

        [Mailer: "Groupware E-Mail". Version 1.03.000]

>        [From: Joao Vargem
>
>       I've derived my own class 'ClEdit' from CEdit and I need to pass
>information to my
>controls during their creation. For that I use the creation data
>parameter in the DLGITEMTEMPLATE structure. The manuals say this
>creation data is passed to the control in the:
>        - WM_CREATE message (MSDN);
>        - when the windows call the CreateWindowEx function (MSVC on
>line help).
>
>My problem is that my controls OnCreate function doesn't even get
>called. If anyone could help me I'd really apreciate. 
>
>Just another thing. Could anyone also explain me when does the control
>class get attached to the
>window? Is it on the DDX_Control call? But at this time the window is
>already created. I can't grasp when or how does the framework knows that
>when it is creating this control window it must send the WM_CREATE
>message to that class.
>TIA

When you use a member variable for a control in your CDialog-derived class, it is attached to a 'real window' during DDX_Control() call. At that moment 'real window' already exists and it have received its creation messages. MFC cannot trap them for you.


Dmitry A. Dulepov
Software Design Engineer
Samsung Electronics Co., Ltd.
Russian Research Center
E-mail: dima@src.samsung.ru
====================================

-----From: Roma 

Hello, 

Joao Vargem wrote:
> 
> Environment:    Windows 95, MSVC++ 4.1
> 
>         Hi all. My problem is this:
>        I've derived my own class 'ClEdit' from CEdit and I need to pass
> information to my
> controls during their creation. For that I use the creation data
> parameter in the DLGITEMTEMPLATE structure. The manuals say this
> creation data is passed to the control in the:
>         - WM_CREATE message (MSDN);
>         - when the windows call the CreateWindowEx function (MSVC on
> line help).
> 
> My problem is that my controls OnCreate function doesn't even get
> called. If anyone could help me I'd really apreciate.
> 
> Just another thing. Could anyone also explain me when does the control
> class get attached to the
> window? Is it on the DDX_Control call? But at this time the window is
> already created. I can't grasp when or how does the framework knows that
> when it is creating this control window it must send the WM_CREATE
> message to that class.
> TIA

 That's not another thing - this is exactly why you don't get WM_CREATE
in the objects of your class
  All controls defined in the dialog template are created inside Windows
code. No MFC
code is involved in this process. So your class objects will never get
WM_CREATE, because
the window is already created when DDX_Control get called (and WM_CREATE
is already handled 
by default message handler of the "edit" window class).

Or, in other words:
here is what exactly documentation says about this creation parameter:
>...
>The creation data array follows the text array. This array can contain any number of >elements; the control's window procedure must understand the content and format of the >data. Windows passes this data to the control when it calls the CreateWindowEx function. 
>...
There is a note, that '..control's window procedure must understand the
contents and format..'.
When the dialog is created, Windows creates edit boxes as windows of
"edit" class whose 
procedure doesn't know anything about your creation parameter. The
window procedure defined
in your class will be involved in the process ONLY after DDX_Control
call.

Usually to do some initialization of such controls, I add a member to my
class (smth. like 
Init(some param)) and place a call of this member in the OnInitDialog()
after call to base 
class's OnInitDialog();
 
HTH,
-Roma
roma@neonet.lv



Mihir Dalal -- m_dalal@ECE.concordia.CA
Saturday, March 22, 1997


On Wed, 19 Mar 1997, CADS Software Developer wrote:

> > Date: 17 March 1997 17:55
> > 
> > Environment:    Windows 95, MSVC++ 4.1 
> > 
> >         Hi all. My problem is this:
> >        I've derived my own class 'ClEdit' from CEdit and I need to pass
> > information to my
> > controls during their creation. For that I use the creation data
> > parameter in the DLGITEMTEMPLATE structure. The manuals say this
> > creation data is passed to the control in the:
> >         - WM_CREATE message (MSDN);
> >         - when the windows call the CreateWindowEx function (MSVC on
> > line help).
> > 
> > My problem is that my controls OnCreate function doesn't even get
> > called. If anyone could help me I'd really apreciate. 

When writting member functions, people often tend to forget a fundamental 
thing about member functions in MFC. Not all, member functions that you 
write and override are plain member functions. Some of them are 
_windows message handlers_. The declarations for these usually start with 
the "afx_msg" prefix. This clearly distinguishes them from other member 
functions. 

An "afx_msg" needs to have a corrosponding message map entry for it to 
get called in a class. 

The problem that you are having is most probably because, you hand coded 
the OnCreate() and thus forgot to put the message map entry 
"ON_WM_CREATE", in your class message map. 

It is good idea to let class wizard write the base code for message 
handlers. This will save you from making such mistakes. 

Mihir. 

 _________________________________________________________________________
     Mihir Dalal , M.Engg. (Electrical) Student
              Department of Electrical and Computer Engineering
                   Concordia University, Montreal, Canada
                http://www.ECE.Concordia.CA/~m_dalal/addr.html





Become an MFC-L member | Вернуться в корень Архива |