15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


How do I access the CHeaderCtrl in a CListCtrl?

bshamsian@ccvhs.vhsla.com
Tuesday, November 26, 1996

     Environment: VC++ 4.1b, NT 4.0 
     
     I need to place arrows in the CHeaderCtrl of a CListCtrl to indicate 
     if a column is sorted Ascending or Descending.  I have seen this in 
     other applications like MS Scheduler or the new MS News application 
     which is part of MS Internet Explorer package.  I probably need to 
     draw the column heading myself using OwnerDraw but how do I get hold 
     of the CHeaderCtrl embedded in a CListCtrl?
     
     ==================================
     Ben Shamsian (bshamsian@vhsla.com)




Randy Taylor -- randy_taylor@ebt.com
Wednesday, November 27, 1996

CHeaderCtrl *head = (CHeaderCtrl*) m_yourListCtrl->GetDlgItem(0);

----------
> From: bshamsian@ccvhs.vhsla.com
> To: mfc-l@netcom.com
> Subject: How do I access the CHeaderCtrl in a CListCtrl?
> Date: Tuesday, November 26, 1996 1:58 PM
> 
>      Environment: VC++ 4.1b, NT 4.0 
>      
>      I need to place arrows in the CHeaderCtrl of a CListCtrl to indicate

>      if a column is sorted Ascending or Descending.  I have seen this in 
>      other applications like MS Scheduler or the new MS News application 
>      which is part of MS Internet Explorer package.  I probably need to 
>      draw the column heading myself using OwnerDraw but how do I get hold

>      of the CHeaderCtrl embedded in a CListCtrl?
>      
>      ==================================
>      Ben Shamsian (bshamsian@vhsla.com)



Charles N. Johnson -- charlej9@mail.idt.net
Thursday, November 28, 1996

Ben: I believe the resource ID for the header control that is displayed
inside a list control with the "report" style is 0, so something like the
following should work:

CHeaderCtrl* pHdrCtrl = pYourListCtrl->GetDlgItem(0);
if (pHdrCtrl == NULL)
{
	Trace0("ERROR -- LIST CONTROL: not in report style\n");
	// do an ASSERT and return, 
	// or something to get your attention in DEBUG mode
}
else
{
	// get your work done here...
}
Cheers--
Charles

----------
> From: bshamsian@ccvhs.vhsla.com
> To: mfc-l@netcom.com
> Subject: How do I access the CHeaderCtrl in a CListCtrl?
> Date: Tuesday, November 26, 1996 12:58 PM
> 
>      Environment: VC++ 4.1b, NT 4.0 
>      
>      I need to place arrows in the CHeaderCtrl of a CListCtrl to indicate

>      if a column is sorted Ascending or Descending.  I have seen this in 
>      other applications like MS Scheduler or the new MS News application 
>      which is part of MS Internet Explorer package.  I probably need to 
>      draw the column heading myself using OwnerDraw but how do I get hold

>      of the CHeaderCtrl embedded in a CListCtrl?
>      
>      ==================================
>      Ben Shamsian (bshamsian@vhsla.com)
> 



Thomas Schall -- schall@csv.ica.uni-stuttgart.de
Friday, November 29, 1996


> 
>      Environment: VC++ 4.1b, NT 4.0 
>      
>      I need to place arrows in the CHeaderCtrl of a CListCtrl to indicate

>      if a column is sorted Ascending or Descending.  I have seen this in 
>      other applications like MS Scheduler or the new MS News application 
>      which is part of MS Internet Explorer package.  I probably need to 
>      draw the column heading myself using OwnerDraw but how do I get hold

>      of the CHeaderCtrl embedded in a CListCtrl?
>      
This Problem is easy to solve. You need to subclass the original header
control.
Use for example a member variable m_Header of class CYourHeaderCtrl
(derived from CHeaderCtrl) in your list control.

int CYourListCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
  // subclass default header control
  m_Header.SubclassDlgItem(GetDlgItem(0)->GetDlgCtrlID(), this);
  // .....
  return 0;
}

That's all. Now you can reimplement any WM_xxx event.

Thomas




T.K.Wessing -- tkw@xs4all.nl
Thursday, November 28, 1996

Environment: VC++ 4.2b, NT 4.0


Hi, 
It is really quite simple (if you see it)
First: get a pointer to the header control in the list
then:	Ask the header for it's number of columns

 
CHeaderCtrl* GetHeaderControl( const CListCtrl* pList)
{
	CHeaderCtrl*	pHdr ;

	ASSERT( NULL != pList );

	// the Child ID of the header control is hardcoded (to 0) in Microsoft
Windows
	pHdr = (CHeaderCtrl*) pList->GetDlgItem( 0 ) ;
	//
	// place the calling function after initialization please
	ASSERT( NULL != pHdr );	
	if ( NULL == pHdr )
	{
		return NULL ;
	}

	return pHdr;
}


int GetSizesFromListCtrl( const CListCtrl* pList )
{
	CHeaderCtrl*	pHdr ;

	ASSERT( NULL != pList );

	pHdr = GetHeaderControl( pList ) ;
	//
	// place the calling function after initialization please
	ASSERT( NULL != pHdr );	
	if ( NULL == pHdr )
	{
		return ;
	}

	return GetSizesFromHeaderCtrl( pHdr ) ;
}

int GetSizesFromHeaderCtrl( const CHeaderCtrl* pHeader )
{
	ASSERT( NULL != pHeader );
	ASSERT_VALID( pHeader );


	return pHeader->GetItemCount();
}


-- 

/=====================================
|  T.K.Wessing
|  Senior Software Engineer
|  Caledon Systems International BV
|  The Netherlands
|  Private E-Mail:
|  tkw@xs4all.nl
\=====================================
The Nedherlands ?
Yep, "The Nedherlands" It does exists indeed!


----------
> From: bshamsian@ccvhs.vhsla.com
> To: mfc-l@netcom.com
> Subject: How do I access the CHeaderCtrl in a CListCtrl?
> Date: Tuesday, November 26, 1996 7:58 PM
> 
>      Environment: VC++ 4.1b, NT 4.0 
>      
>      I need to place arrows in the CHeaderCtrl of a CListCtrl to indicate

>      if a column is sorted Ascending or Descending.  I have seen this in 
>      other applications like MS Scheduler or the new MS News application 
>      which is part of MS Internet Explorer package.  I probably need to 
>      draw the column heading myself using OwnerDraw but how do I get hold

>      of the CHeaderCtrl embedded in a CListCtrl?
>      
>      ==================================
>      Ben Shamsian (bshamsian@vhsla.com)
> 




| Вернуться в корень Архива |