jubjub
asked on
Telling Column to Resize
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->GetItemCoun t();
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(W M_NOTIFY, GetDlgCtrlID(), (long)&m_NmHeader);
}
}
How do I tell each column to resize itself??? ??? ???
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->GetItemCoun
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(W
}
}
How do I tell each column to resize itself??? ??? ???
ASKER
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??
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??
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Bravo...that's exactly what I want..
Thanx..Thui
Answer2000 Thanx for your help too, you gave some pointers which I may use later..
Thanx..Thui
Answer2000 Thanx for your help too, you gave some pointers which I may use later..
HDITEM hdi ;
memset( hdi, 0, sizeof hdi ) ;
hdi.mask = HDI_WIDTH
hdi.cxy = 100 ; // new width
pHeaderCtrl->SetItem( i, &hdi ) ; // i = column to size