Adding a control that's not on the resource palette 
Author Message
 Adding a control that's not on the resource palette

I want to add a control to my dialog that's not on the resource palette
in the resource editor. Now, one way to do that is to add an arbitrary
control (like a button), and disable it and make it invisible, then
create the non-standard resource to fit in the place-holder control's
rectangle.

However, I have a question about that:

When I try some fairly obvious code I have to do some really strange
fudging, instead of being able to rely on the numbers I get back. See
the example code below:

CRect rectPlaceholder;
CRect rectMain;              
// first get the dialog's window coords
GetWindowRect(&rectMain);    
// next get the place-holder control's window coords
CWnd *placeholder = GetDlgItem(IDC_PLACEHOLDER);
placeholder->GetWindowRect(&rectPlaceholder);  
width = rectPlaceholder.Width();
height = rectPlaceholder.Height();

// calculate the control's relative coords
rectPlaceholder.top -= rectMain.top + 10;
rectPlaceholder.left -= rectMain.left;
rectPlaceholder.bottom = rectPlaceholder.top + height - 23;
rectPlaceholder.right = rectPlaceholder.left + width;

Without the fudging the resulting rectangle isn't positioned correctly.
Why is that? I expected the place-holder control's window coordinates
to be based off the same coordinates than the dialog's own window
coordinates, but without the fudging the resulting rectangle is way too
low on the dialog.

Oh, and is there an easier way to do this?
--
 Helge Moulding

  http://www.*-*-*.com/ ;                with a weird name



Mon, 12 Sep 2005 00:22:02 GMT  
 Adding a control that's not on the resource palette

Quote:

> I want to add a control to my dialog that's not on the resource palette
> in the resource editor. Now, one way to do that is to add an arbitrary
> control (like a button), and disable it and make it invisible, then
> create the non-standard resource to fit in the place-holder control's
> rectangle.

> However, I have a question about that:

> When I try some fairly obvious code I have to do some really strange
> fudging, instead of being able to rely on the numbers I get back. See
> the example code below:

> CRect rectPlaceholder;
> CRect rectMain;
> // first get the dialog's window coords
> GetWindowRect(&rectMain);
> // next get the place-holder control's window coords
> CWnd *placeholder = GetDlgItem(IDC_PLACEHOLDER);
> placeholder->GetWindowRect(&rectPlaceholder);
> width = rectPlaceholder.Width();
> height = rectPlaceholder.Height();

> // calculate the control's relative coords
> rectPlaceholder.top -= rectMain.top + 10;
> rectPlaceholder.left -= rectMain.left;
> rectPlaceholder.bottom = rectPlaceholder.top + height - 23;
> rectPlaceholder.right = rectPlaceholder.left + width;

> Without the fudging the resulting rectangle isn't positioned correctly.
> Why is that? I expected the place-holder control's window coordinates
> to be based off the same coordinates than the dialog's own window
> coordinates, but without the fudging the resulting rectangle is way too
> low on the dialog.

> Oh, and is there an easier way to do this?
> --
>  Helge Moulding

>  http://hmoulding.cjb.net/                  with a weird name

Use ScreenToClient on the placeholder rect.

--
Scott McPhillips [VC++ MVP]



Mon, 12 Sep 2005 02:59:15 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. control palette not there

2. Nexbie Can't Control Palette

3. Newbie Can't Find Control Palette

4. DOn't get control palette for a new dialog

5. I think I'm adding an extra null, but I'm not sure

6. Adding BLOB's/CLongBinary not working

7. How do I remove an ActiveX control from the Control Palette

8. Remove custom control icon from controls palette

9. ATL Composite Control does not work in VStudio Resource Editor

10. Windowless control (ATL) doesn't work correctly on VC++ dialog resource

11. ATL Prop Page ShellEX - Can't use DTPicker control on dialog resource, page disappears

12. ATL Prop Page ShellEX - Can't use DTPicker control on dialog resource, page disappears

 

 
Powered by phpBB® Forum Software