Solved

Standalone C(Derived)HeaderCtrl in a CDialog

Posted on 2003-10-21
5
231 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
Comment Utility
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
Comment Utility
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
Comment Utility
remove your ddx_control line and try again.
0
 
LVL 1

Author Comment

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

Expert Comment

by:Priyesh
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Expand LInux Boot partition remotly 3 78
has77  challenge 9 67
withoutTen challenge 14 88
Thin secure Windows 10 5 47
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

744 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

17 Experts available now in Live!

Get 1:1 Help Now