Solved

Standalone C(Derived)HeaderCtrl in a CDialog

Posted on 2003-10-21
5
242 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

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.

Question has a verified solution.

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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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 is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

687 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