Re: Custom control with use resource file

Tech-Archive recommends: Fix windows errors by optimizing your registry



On 23 Lip, 20:46, MariuszK <mariusz.kwicz...@xxxxxxxxx> wrote:
On 23 Lip, 09:25, Joseph M. Newcomer <newco...@xxxxxxxxxxxx> wrote:





See below...

On Sat, 21 Jul 2007 22:56:21 -0700, MariuszK <mariusz.kwicz...@xxxxxxxxx> wrote:
On 22 Lip, 07:27, Joseph M. Newcomer <newco...@xxxxxxxxxxxx> wrote:
To call this a "control" means you need to specify the dialog as a child dialog. It is a
bit clumsy, but you can register a window class for the dialog, then specify that class
name as the name of a custom control.

It is usually easier to just place a CStatic frame at the place in the dialog you want
your custom dialog. Then simply, in the OnInitDialog of the parent dialog, you create the
child dialog (using Create), and use SetWindowPos to place it on the (invisible) frame.
Note that you should also set the "Control Parent" property of the child dialog so the tab
key works correctly.
joe

On Sat, 21 Jul 2007 15:47:26 -0700, MariuszK <mariusz.kwicz...@xxxxxxxxx> wrote:
Hello,
How can I create (and display on CDialog or CFormView) custom control
which consist of rc file. I want do it "dialog in dialog"

For example I have dialog in resource file (with has some buttons,
text, checkbox etc.). I would like create this dialog as custom
control. And display this custom control (which look as same as dialog
it is mean has buttons, text, checkbox etc) in another CDialog or
CFormView.

Thank you,
Mariusz

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

Joseph,

Yes, I would like display my custom control (which is created on base
resource file rc and look like dialog - has some buttons,) in CStatic.

I can create custom control. i.e I create Custom contol derive it from
CStatic and write my own implementation OnPaint etc. And it is work.
But I can write custom control with use *.rc file to show content of
my control.

****
The trick here is that to place a custom dialog (a child dialog) in another dialog, you
can only define it in terms of a registered window class, and this involves actually
registering the window class, and making sure this is done before you try to create the
dialog. It is a bit of a pain because not only do you have to do this, but when you set
the style bits for your class, you have to look them up in winuser.h and type in the
correct hex values yourself.

Therefore, a more common practice is to create a child dialog, place all the controls on
the dialog, mark the dialog as having no border, child style, control parent, and creating
it dynamically at runtime. To do this, you have to know where to put it, and that can be
a bit of a pain because of the dialog coordinates all being in Dialog Box Units (DBUs) not
pixels.

So the standard trick goes like this: create your dialog. It is nxm DBUs in size.

Create a CStatic frame control on your dialog's surface, of size nxm DBUs. Change its
style to be "invisible" and change its ID from IDC_STATIC to something like IDC_MY_FRAME
or some suitably useful name.

Create a control member variable for this frame, e.g.,
CStatic c_MyFrame;
using the right-click, Add Member Variable menu item. It should be protected,since no one
else needs to know about it. Make sure you set the Z-order of this CStatic to be the
place in the Z-order you would like your composit control to appear.

Add a member variable for your child dialog, you would typically do this by hand, just add
a declaration in the protected section
CMyControlDialog c_Controls;

Now, at runtime, you do something like this in your OnInitDialog handler

CRect r;
c_MyFrame.GetWindowRect(&r);
ScreenToClient(&r);
c_Controls.Create(CMyControlDialog::IDD, this);
c_Controls.SetWindowPos(&c_MyFrame, r.left, r.top, r.Width(), r.Height(), 0);
c_Controls.ShowWindow(SW_SHOW);

This should force it into the right place.
joe
*****

text, checkbox etc ) in CStatic.
OnInitDialog of the parent dialog, you create the
child dialog (using Create),
I can not create dialog in OnInitDialog of the parent dialog. I have
some ASSERTs

Could you send me on my email sample design (MFC project) with realize
your approach.

Thank you,
Mariusz

Joseph M. Newcomer [MVP]
email: newco...@xxxxxxxxxxxx
Web:http://www.flounder.com
MVP Tips:http://www.flounder.com/mvp_tips.htm-Ukryj cytowany tekst -

- Poka cytowany tekst -

Joseph, Scott,

I do it. It is work. I create dialog and put it in pleace CStatic.

CRect r;
c_MyFrame.GetWindowRect(&r);
ScreenToClient(&r);
c_Controls.Create(CMyControlDialog::IDD, this);
c_Controls.SetWindowPos(&c_MyFrame, r.left, r.top, r.Width(),
r.Height(), 0);
c_Controls.ShowWindow(SW_SHOW);

Thank you!

But ... Could you help me create the same task as "custom control"
with registration window class etc. ?
It is for curiosity. ;)

Regards,
Mariusz- Ukryj cytowany tekst -

- Poka cytowany tekst -

Joseph, Scott,
I have hext problems:
1. How can fix tab order. If I have focus inside "dialog in dialog" I
can iterate only through "dialog in dialog" controls
2. If I have focus inside "dialog in dialog" I can not use shortcats
from parent dialog.

Regards,
Mariusz

.


Quantcast