Solved

Standalone C(Derived)HeaderCtrl in a CDialog

Posted on 2003-10-21
5
235 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
mixString challenge 36 123
Perl Awk Need Help 3 119
iSeries DB2 Query 2 95
How to know only "File created" with EventLog 3 34
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

822 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