MFC: calling the Create function of a custom dialog object: rect, parentWnd, nID

I'm following an MFC tutorial that covers the implementation of a custom CListCtrl style control, that is actually a custom Wnd derived class.

I've bound a Custom dialog item to the class in this manner:
void CLustreView::DoDataExchange(CDataExchange* pDX)
{
      CFormView::DoDataExchange(pDX);
      DDX_Control(pDX, IDC_CUSTOM1, grid); // grid is an object I instantiated from the class
}


According to the tutorial, you create the object thusly:

CGridCtrl grid;
grid.Create(rect, pParentWnd, nID);

I suspect that I should call this Create function, having obtained a rect area through the GetClientRect() function, and having obtained the parent through the GetParent() function, while just passing IDC_CUSTOM1 as the third argument. I'm unsure of exactly how to do so. Please advise,

Regards,
Sternocera
sternoceraAsked:
Who is Participating?
 
AndyAinscowFreelance programmer / ConsultantCommented:
CRect rc;
GetDlgItem(IDC_CUSTOM1)->GetWindowRect(&rc);
ScreenToClient(&rc);

rc now has the size/position of IDC_CUSTOM1 in client co-ordinates


by unique identifier, do you mean resource ID? - you ought to have a unique ID for each child window on the dialog - else how can you identify which control a message came from for example.
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
<     DDX_Control(pDX, IDC_CUSTOM1, grid); // grid is an object I instantiated from the class>
not required - you are creating the control yourself.

CGridCtrl grid;  - In header file, not local to a function


grid.Create(rect, pParentWnd, nID);
In the OnInitDialog.
rect is the recatngle you want (client co-ordinates), pParentWnd can be this (the dialog) and nID is the UNIQUE identifier.
0
 
sternoceraAuthor Commented:
CGridCtrl grid is in a header file (though that wasn't apparent from my post).

How can I obtain a rect object that has the same area as my variably sized IDC_CUSTOM dialog item?

by unique identifier, do you mean resource ID?

Thanks a lot,
Sternocera
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
sternoceraAuthor Commented:
This has the effect of making the dialog object fill the entire frame:
CRect rc;
GetClientRect(&rc);
grid.Create(rc, this, IDC_CUSTOM1);

All I need now is to figure out a way of getting a CRect object that has the co ordinates of my IDC_CUSTOM1 object,
Regards,
Sternocera
0
 
sternoceraAuthor Commented:
Thanks again andy
0
 
sternoceraAuthor Commented:
So you mean that I should have an ID for each dialog item, like this, from resource.h?

#define IDC_RADIO1                      1025
#define IDC_RADIO2                      1026
#define IDC_COMBO5                      1027
#define IDC_COMBO6                      1028
#define IDC_PRODUCTSEARCHLIST           1030
#define IDC_COMBO1                      1031
#define IDC_COMBO2                      1034
#define IDC_CUSTOM1                     1035
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
It would be best if the ID of the grid isn't the same as an ID used for another control.  (in numbers of cases it may well not cause a problem if it was duplicated but best to get used to doing it right from the start)
0
 
sternoceraAuthor Commented:
Ok, Thank you.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.