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
http://www.codeproject.com/KB/combobox/advcombobox.aspx
-SM
Torin
"T. Ford" <TF...@discussions.microsoft.com> wrote in message
news:2A13B162-6577-4CDB...@microsoft.com...
"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
AliR.
"Drew" <d...@dam.com> wrote in message
news:OiGwuZ4w...@TK2MSFTNGP06.phx.gbl...
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...
"AliR (VC++ MVP)" <Al...@online.nospam> wrote in message
news:V3MHl.25221$Ws1....@nlpi064.nbdc.sbc.com...
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
>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
"T. Ford" <TF...@discussions.microsoft.com> 写入消息
news:2A13B162-6577-4CDB...@microsoft.com...
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> ????