Solved

Telling Column to Resize

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

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: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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 video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

705 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

14 Experts available now in Live!

Get 1:1 Help Now