Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2007-08-02
8
Medium Priority
?
760 Views
Last Modified: 2013-11-25
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
0
Comment
Question by:sternocera
  • 5
  • 3
8 Comments
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 19615608
<     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
 

Author Comment

by:sternocera
ID: 19615638
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
 

Author Comment

by:sternocera
ID: 19615668
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 45

Accepted Solution

by:
AndyAinscow earned 2000 total points
ID: 19615687
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
 

Author Comment

by:sternocera
ID: 19615693
Thanks again andy
0
 

Author Comment

by:sternocera
ID: 19615703
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
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 19615773
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
 

Author Comment

by:sternocera
ID: 19615812
Ok, Thank you.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question