Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Custom Control Using Dialog Resource?

435 views
Skip to first unread message

T. Ford

unread,
Apr 22, 2009, 1:05:01 PM4/22/09
to
I'm sure this has been done and can be done but I can't find any examples
(probably just not using the right search terms).

I'm looking for an example on how to create a "custom control" that does not
extend from CDialog, but from CWnd, and uses a dialog resource. An example
would be something like the CIPAddressCtrl. The CIPAddressCtrl uses standard
controls (Static, Edit, etc) and doesn't appear to do any special painting on
it's own. You can either drag/drop it in the dialog designer, or you can
just create one and place it in your code. I'm looking for a way to do this.
I'm sure I could just create a class that derives from CWnd, has members
like edits, spinners, etc, and manually place then in the correct places.
But is it possible to just use a dialog resource so that everything is nicely
placed? I want to extend CWnd rather than CDialog. I've come across the
idea of self-drawing controls. According to

http://msdn.microsoft.com/en-us/library/bk2h3c6w.aspx

this sounds like what I want. But I don't see any examples doing what I want.

Thanks,

Torin

Seetharam

unread,
Apr 22, 2009, 2:14:40 PM4/22/09
to

T. Ford

unread,
Apr 22, 2009, 2:32:03 PM4/22/09
to
I don't think this answers my question. Nor does it do what I'm looking for.
Maybe I wasn't very clear. I want to create a dialog resource, add some
common controls to like (such as edit boxes, spinners, statics, etc). I then
want to some how create an object that derives from CWnd rather than CDialog
and be able to reuse this new "control" inside other windows (they might be
CWnd derivatives, or CDialog derivatives, etc).

Torin

Drew

unread,
Apr 22, 2009, 4:09:56 PM4/22/09
to
CFormView?


"T. Ford" <TF...@discussions.microsoft.com> wrote in message
news:2A13B162-6577-4CDB...@microsoft.com...

Message has been deleted

Drew

unread,
Apr 22, 2009, 4:55:02 PM4/22/09
to
Don't know, I've never used one. But even if you can't the document doesn't
really have to do anything.


"T. Ford" <TF...@discussions.microsoft.com> wrote in message

news:BB18385F-1B05-4C71...@microsoft.com...
> Interesting idea, but how do you use one without a doc?
>
> Torin


T. Ford

unread,
Apr 22, 2009, 4:43:02 PM4/22/09
to

AliR (VC++ MVP)

unread,
Apr 22, 2009, 5:33:44 PM4/22/09
to
What would that buy him? What would be the difference between a CDialog and
a CFormView in this case?

AliR.


"Drew" <d...@dam.com> wrote in message
news:OiGwuZ4w...@TK2MSFTNGP06.phx.gbl...

AliR (VC++ MVP)

unread,
Apr 22, 2009, 5:35:07 PM4/22/09
to
Either an ActiveX control, or a custom control would be your best bet.

Here is how to create a custom control derived from CWnd:
http://www.codeproject.com/KB/miscctrl/custbutton001.aspx

AliR.


"T. Ford" <TF...@discussions.microsoft.com> wrote in message
news:2A13B162-6577-4CDB...@microsoft.com...

Drew

unread,
Apr 22, 2009, 6:55:56 PM4/22/09
to
Probably nothing, but it's not a CDialog which seemed to be the only
requirement.


"AliR (VC++ MVP)" <Al...@online.nospam> wrote in message
news:V3MHl.25221$Ws1....@nlpi064.nbdc.sbc.com...

Mihai N.

unread,
Apr 23, 2009, 4:46:14 AM4/23/09
to
> I'm looking for an example on how to create a "custom control" that does
> not extend from CDialog, but from CWnd, and uses a dialog resource.

Why the restriction from using CDialog? What is the problem?

--
Mihai Nita [Microsoft MVP, Visual C++]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email

Joseph M. Newcomer

unread,
Apr 23, 2009, 11:04:19 AM4/23/09
to
See below...

On Wed, 22 Apr 2009 10:05:01 -0700, T. Ford <TF...@discussions.microsoft.com> wrote:

>I'm sure this has been done and can be done but I can't find any examples
>(probably just not using the right search terms).
>
>I'm looking for an example on how to create a "custom control" that does not
>extend from CDialog, but from CWnd,

****
I am not aware of any custom control that extends from CDialog. All custom controls
extend either from CWnd or from some control that itself derives from CWnd, e.g., CStatic,
CEdit, CComboBox, CListBox, etc.
****


>and uses a dialog resource.

****
Once you have your control, you can do anything with it you want. If you want to use a
child dialog as a custom control, feel free, if you want to embed a child dialog as a
child of your CWnd, feel free.
****


>An example
>would be something like the CIPAddressCtrl. The CIPAddressCtrl uses standard
>controls (Static, Edit, etc) and doesn't appear to do any special painting on
>it's own.

****
"Appears to"? In what way does it "appear to"? Using Spy++, for example, a SysIpAddress32
control has four child edit windows. I see no sign of a static window anywhere. It is a
CWnd-derived class with four child windows, it definitely appears to do special painting
on its own (it puts those little dots between the edit controls), and it has nothing to do
with being a dialog at all. Just a window with four edit children.
****


>You can either drag/drop it in the dialog designer, or you can
>just create one and place it in your code. I'm looking for a way to do this.

****
Register a window class name. Then create an instance of that class. If the creation of
the instance of the class requires that child windows be created, feel free. Note that
you have to be careful of what you do in OnCreate because OnCreate will not be called for
any control that is subclassed in MFC.

Having a control you can drop onto your dialog from the toolbox requires that you create
an ActiveX control. Generally, I just plunk down a CStatic and replace it at runtime with
my control, e.g.,

OnInitDialog:

int n = c_MyPlaceholder.GetDlgCtrlId();
CRect r;
c_MyPlaceHolder.GetWindowRect(&r);
ScreenToClient(&r);
c_MyCustomControl.Create(r, n); // and maybe other parameters of my choosing
c_MyCustomControl.SetWindowPos(&c_MyPlaceholder, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
c_MyPlaceholder.DestroyWindow();

Since I rarely have more than one such control in a dialog, this is not a serious burden.
And it saves having to do the custom-control ugliness including hex constants for style
that are required if you do it in the dialog editor.
*****


> I'm sure I could just create a class that derives from CWnd, has members
>like edits, spinners, etc, and manually place then in the correct places.
>But is it possible to just use a dialog resource so that everything is nicely
>placed? I want to extend CWnd rather than CDialog.

****
But how did you ever come across the idea that custom controls extend CDialog? They
don't!
****


>I've come across the
>idea of self-drawing controls. According to
>
>http://msdn.microsoft.com/en-us/library/bk2h3c6w.aspx
>
>this sounds like what I want. But I don't see any examples doing what I want.
>
>Thanks,
>
>Torin

Joseph M. Newcomer [MVP]
email: newc...@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm

Joseph M. Newcomer

unread,
Apr 23, 2009, 11:05:24 AM4/23/09
to
How is it you keep thinking that custom controls extend CDialog? You can certainly create
a child dialog that contains controls, but that's just another control that extends CWnd.
You don't have to get a dialog involved at all!
joe

张聪

unread,
Apr 28, 2009, 9:50:46 PM4/28/09
to
You may need use ATL to develop a compound control or user custom control ?

"T. Ford" <TF...@discussions.microsoft.com> 写入消息
news:2A13B162-6577-4CDB...@microsoft.com...

Joseph M. Newcomer

unread,
Apr 28, 2009, 11:22:37 PM4/28/09
to
Using ATL is considered Good Practice in such cases.
joe

On Wed, 29 Apr 2009 09:50:46 +0800, ?? <wso_...@hotmail.com> wrote:

>You may need use ATL to develop a compound control or user custom control ?
>

>"T. Ford" <TF...@discussions.microsoft.com> ????

0 new messages