Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Standalone C(Derived)HeaderCtrl in a CDialog

Posted on 2003-10-21
5
Medium Priority
?
244 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 600 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

Technology Partners: 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: 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 …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

618 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