Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sorting a "locked" column in a CListCtrl 1

Status
Not open for further replies.

solla

Programmer
Feb 21, 2003
19
FR
Is it possible to click on a column header AND fix the width of the column at the same time?

Basically, in order to fix the size of the column, I have done something like,

my_list_control.GetHeaderCtrl()->EnableWindow(FALSE);

However, this means that I can no longer click on the column header in order to sort the items.

Any solutions?
 
Yes,

Don't disable the column headers.
Instead create your own version of CListCtrl (i.e. insert a new class into your project with a base class of CListCtrl). Point your existing list to this new class instead of CListCtrl. Then within your new class override 'PreTranslateMessage' and alter it to;

BOOL CTest::preTranslateMessage(MSG* pMsg)
{
if(pMsg->message==512)
return TRUE;
return CListCtrl::preTranslateMessage(pMsg);
}

This will prevent the list's columns from being resized.
 
Thanks very much - that works a treat.

However, which message does 512 correspond to?
 
For reference, the message that corresponds to the magic number is WM_MOUSEMOVE
 
This solution works fine when the user wants to drag the column separator. However, they can still double click on the column separator to achieve their goal!

I haven't yet got a solution for this, although I'm sure its just a case of trapping a different message!
 
Good point.
The message for the double click is 515 (WM_LBUTTONDBLCLK).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top