CWnd::Create()

I have two basic questions -

CWnd::Create(....) function takes in a parameter nID, The ID of child window.
Can i give any value that comes to my mind to this nID input ? or it is required to be within certain range.
for example I see the CControlBar::Create(..) requires the value to be between AFX_IDW_CONTROLBAR_FIRST and AFX_IDW_CONTROLBAR_LAST (?)
Similarly AFX_IDW_PANE_FIRST and AFX_IDW_PANE_LAST are seen when we create a default SDI without Doc-view support.

m_wndView.Create(NULL, NULL, AFX_WS_DEFAULT_VIEW, CRect(0, 0, 0, 0), this, AFX_IDW_PANE_FIRST, NULL)

1 - What is the significance of nID in CWnd::Create(..), i.e. whats  AFX_IDW_CONTROLBAR_FIRST / LAST / AFX_IDW_CONTROLBAR_FIRST /AFX_IDW_CONTROLBAR_LAST etc

If i make AFX_IDW_CONTROLBAR_FIRST to AFX_IDW_CONTROLBAR_LAST it stops repainting the view  when i resize the main frame.
2 - why

you know i am novice.

LVL 1
bhiveAsked:
Who is Participating?
 
SteHConnect With a Mentor Commented:
Hello bhive,

since you're asking in the MFC forum I suggest to use
CControlBar::CControlBar () to create a control bar. The underlying CWnd::Create () is then called from the framework and the ID assigned there. This assures a proper value of the nID. Unless you really know what to do you should create the control objects and not CWnd's which you have to somehow convert to be of a control class.

The value of AFX_IDW_CONTROLBAR_FIRST is by the time you are calling definitly in use. The next control bar should have a value of LAST + 1 and change the value of LAST. But this should be handled by the framework.
0
 
igor_skConnect With a Mentor Commented:
When you create controls in your window (ex. in your dialog box) you assign unique ID to each one of controls. You can assign it yourself or with DevStudio (when you create dialog boxes).

Then, you can access different controls in your dialog by control ID. You can use CWnd::GetDlgItem(int nID) method for this purpose. It returns a pointer to the given control or child window.
0
 
bhiveAuthor Commented:
thx, that helps taking me closer to understand the nID. I don;t know however why are the nIDs like AFX_IDW_CONTROLBAR_FIRST / LAST , AFX_IDW_PANE_FIRST/LAST etc
 are hardcoded.
and any clue for question - (2) ...
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
SteHCommented:
_FIRST / _LAST are just ends of a range. This allows to use _FIRST / _LAST in a check whether the values are in that range but having the ability to change the actual values of used names.
0
 
bhiveAuthor Commented:
igor, steh you guys answered the first part thx.
Any idea why the making _FIRST to _LAST stops the view from being painted ?
0
 
bhiveAuthor Commented:
thx SteH, i am deriving CMyClass from CControlBar.
I am going to give you the points ...
here is the story that i want to report, and your comments are welcome.
Now i have a
CMyClass::Create(Cwnd *pParent, nID){ CControlBar::Create(.., nID,...), where pParent is my CFrameWnd main frame.
It took long to figure out that CMyClass has to have (?) a CalcFixedLayout() that returns CSize. without which i could not make it see on the screen. correct me if i am doing it unnecessarily.
So now i have my CMyClass visible in the frame wnd as a sibling of the main view.
then the problem was that if i resize the CMyClass control bar, then the view doesnot refresh. So i add a call to pParent->RecalcLayout() in the OnSize event handler of CMyClass.

however i am facing one lil problem when i resize the main frame wnd, MyClass window touches the menu bar and lower edge of the frame wnd and displaces the default toolbar and status bar to the right.

More importantly, i would like to know if i am doing the whole thing right or not. your comments or any sample would be greatly appreciated.
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.