Solved

Telling Column to Resize

Posted on 1998-12-17
5
802 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
  • 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

825 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