Link to home
Start Free TrialLog in
Avatar of sternocera
sternocera

asked on

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
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

<     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.
Avatar of sternocera
sternocera

ASKER

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
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
ASKER CERTIFIED SOLUTION
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks again andy
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
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)
Ok, Thank you.