Solved

Telling Column to Resize

Posted on 1998-12-17
5
806 Views
Last Modified: 2013-11-20
I've searched and found HDN_DIVIDERDBLCLICK, which is exactly what I want to do, but I don't want to have to dbl-click on the column divider in the listctrl myself.  I want it to resize itself on inserting an item.

I have a Dialog, with a listctrl in it, with 3 columns.

How do I post the message (HDN_DIVIDERDBLCLICK);

I've done the following :

func()
{
  m_pHeaderCtrl = m_ListScript.GetHeaderCtrl();
  int iNumHeaderItems = m_pHeaderCtrl->GetItemCount();
  HDITEM m_HdItem;
  NMHEADER m_NmHeader;
  NMHDR m_NmHdr;
  for(int i=0; i<iNumHeaderItems; i++)
  {
    TRACE("iNumHeaderItems = %d\n",iNumHeaderItems);

    m_pHeaderCtrl->GetItem(i, &m_HdItem);

    m_NmHdr.hwndFrom = GetSafeHwnd();
    m_NmHdr.idFrom   = GetDlgCtrlID();
    m_NmHdr.code     = HDN_DIVIDERDBLCLICK;
    m_NmHeader.hdr.hwndFrom = GetSafeHwnd();
    m_NmHeader.hdr.idFrom   = GetDlgCtrlID();
    m_NmHeader.hdr.code     = HDN_DIVIDERDBLCLICK;
    m_NmHeader.iItem = i;
    m_NmHeader.iButton = 0; // Left Button
    m_NmHeader.pitem = &m_HdItem;

    m_ListScript.SendMessage(WM_NOTIFY, GetDlgCtrlID(), (long)&m_NmHeader);
  }
}

How do I tell each column to resize itself??? ??? ???
0
Comment
Question by:jubjub
[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
  • 2
  • 2
5 Comments
 
LVL 8

Expert Comment

by:Answers2000
ID: 1326366
Can't you simply us SetItem to set a column's width

HDITEM hdi ;
memset( hdi, 0, sizeof hdi ) ;
hdi.mask = HDI_WIDTH
hdi.cxy = 100 ; // new width
pHeaderCtrl->SetItem( i, &hdi ) ;  // i = column to size
0
 

Author Comment

by:jubjub
ID: 1326367
Nope..I don't want to be able to calculate what width I want it to be...
For example, if I enter a string of 1 character, then the column would be really thin, else if I enter a 100 char string, the column will resize, because the new string is bigger, and will be exactly the right size to fit that string.

The only reason i want this, is because I can see that it does it anyway..so how do i tell it to resize, without having to dbl-click on the divider??
0
 
LVL 8

Expert Comment

by:Answers2000
ID: 1326368
Okay I understand the question now.  

The bad news is I don't know the exact answer

Your basic approach you have won't work (HDN_ messages are notifications sent to you to tell you something has happened, sending them to the control will not trigger the action).

If you want to trigger the action, you need to fake a double click message on the divider of the control  (e.g. WM_LBUTTONDBLCLK).  As MS don't give me source for Windows, I don't know exactly which message the header control responds to, but I guess it's WM_LBUTTONDBLCLK.

Here's what I suggest you do.

(a) Try sending WM_LBUTTONDBLCLK to the control

or
if this doesn't work

(b) get out spy++ and spy on a headercontrol and see what messages are going on when you double click.  Maybe one of the other messages sent to the control triggers the double click behaviour, in which case SendMessage that.

Let me know if this is the answer, or you need more clues on how to figure this out.
0
 
LVL 15

Accepted Solution

by:
Tommy Hui earned 50 total points
ID: 1326369
If you're using a CListCtrl, why not use

  CListCtrl::SetColumnWidth(col, LVSCW_AUTOSIZE);

A header control by itself doesn't do it because it does not know what is in each column. A list control does.

0
 

Author Comment

by:jubjub
ID: 1326370
Bravo...that's exactly what I want..

Thanx..Thui

Answer2000 Thanx for your help too, you gave some pointers which I may use later..
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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
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