Solved

Standalone C(Derived)HeaderCtrl in a CDialog

Posted on 2003-10-21
5
233 Views
Last Modified: 2013-11-20
The MFC Documentation isn't entirely clear on how to work with HeaderCtrls that aren't embedded in List controls. How do I create one? I'm having difficulty.  In the resource editor, I drew a CButton control and edited the .h and .cpp files to change references of CButton to CMyHeaderCtrl. Then I added this code: Seems to be a problem (?) in the Create function because it blanks out everything else in my dialog and causes funny paint problems.

BOOL CXMLDialog::OnInitDialog()
{
      CDialog::OnInitDialog();
      CRect wndRect;
      GetClientRect(&wndRect);
      CRect headerRect;

      headerRect.left = headerRect.top = 0; // -1 ?
      headerRect.right = 10;
      headerRect.bottom = 10;

      m_header.Create(WS_BORDER |WS_CHILD | WS_VISIBLE | HDS_BUTTONS | HDS_HORZ, headerRect, this, IDC_TREE_HEADER);
// my button was called IDC_TREE_HEADER

      HDLAYOUT hdl;
      WINDOWPOS wp;
      hdl.prc = &wndRect;
      hdl.pwpos = ℘
      m_header.Layout(&hdl);

      m_header.SetWindowPos(this,wp.x,wp.y,wp.cx,wp.cy,wp.flags|SWP_SHOWWINDOW);

      HD_ITEM hdi;
      hdi.mask = HDI_TEXT | HDI_FORMAT | HDI_WIDTH;
      hdi.pszText = "Hello";
      hdi.fmt = HDF_LEFT;
      hdi.cxy = 10;
      m_header.InsertItem(0, &hdi);
}
0
Comment
Question by:cshlin
  • 3
  • 2
5 Comments
 
LVL 9

Expert Comment

by:Priyesh
ID: 9596564
header creation should be straightforward, your code seems fine. When you say you replace the CButton with CHeaderCtrl, did you remove the DDX_Control call in the DoDataExchange for your button?(assuming u added CButton member using add member variable.)

0
 
LVL 1

Author Comment

by:cshlin
ID: 9596581
I replaced the line I saw there with
DDX_Control(pDX, IDC_TREE_HEADER, m_header);
which doesn't necessarily mean i had to change anything since the button had the same ID tag and variable...

hmm... that code is fine huh.. does it have something to do with the fact that there's still a blank button in the resource editor? should headers be added not using the res. ed at all?
0
 
LVL 9

Accepted Solution

by:
Priyesh earned 150 total points
ID: 9596587
remove your ddx_control line and try again.
0
 
LVL 1

Author Comment

by:cshlin
ID: 9596626
Ahh, once again you saved me. So why is the DDX line not required..?
0
 
LVL 9

Expert Comment

by:Priyesh
ID: 9596660
Because when it hits the DDX_Control line, MFC will get the dlgitem and subclass it to the class provided by you, in this case, your CHeaderCtrl. I am not sure why you did not get assertions when you tried to call create on the same CWnd derived object in your OnInitDialog. MFC should assert you when it finds that the object is already attached to a window handle.  (assuming you are building in debug configuration).
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

930 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now