外国网友评论中国菜:CListCtrl CHeadeCtrl height

来源:百度文库 编辑:偶看新闻 时间:2024/04/28 13:25:02
1, CHeadCtrl 发送 WM_WINDOWPOSCHANGED后不能触发ON_WM_MEASUREITEM_REFLECTvoid CHeadCtrlX1::SetHeight( int nHeight){m_bSetHeight = TRUE;#if 1m_nHeight = nHeight;WINDOWPOS wp;CRect rcWindow;::GetWindowRect( m_hWnd, &rcWindow);wp.hwnd = m_hWnd;wp.cx = rcWindow.Width();wp.cy = rcWindow.Height();wp.flags = SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER;SendMessage(WM_WINDOWPOSCHANGED, 0, (LPARAM)&wp);#endif}修改为下面这样的方法LRESULT CHeadCtrlX1::OnLayout( WPARAM wp, LPARAM lParam)
{
 LRESULT lResult = CHeaderCtrl::DefWindowProc(HDM_LAYOUT, 0, lParam);
 HD_LAYOUT &hdl = *( HD_LAYOUT * ) lParam;
 RECT *prc = hdl.prc;
 WINDOWPOS *pwpos = hdl.pwpos; if( bSetHeight ){ pwpos->cy =  m_nHeight ;}else{ m_nHeight = pwpos->cy;}

 return lResult;
}int  CHeadCtrlX1::GetHeight( )
{
 m_bSetHeight = FALSE;
#if 0
 WINDOWPOS wp;
 CRect rcWindow;
 ::GetWindowRect( m_hWnd, &rcWindow);
 wp.hwnd = m_hWnd;
 wp.cx = rcWindow.Width();
 wp.cy = rcWindow.Height();
 wp.flags = SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER;
 SendMessage(WM_WINDOWPOSCHANGED, 0, (LPARAM)&wp);
#endif
 HDLAYOUT  hdl;
 WINDOWPOS wpos;
 RECT      rc; 
 // Reposition the header control so that it is placed at
 // the top of its parent window's client area.
 GetParent()->GetClientRect(&rc);
 
 hdl.prc = &rc;
 hdl.pwpos = &wpos;
 Layout(&hdl);
 return m_nHeight;
}2, CListCtrl 设置各获取和设置高度void CListCtrlCore::SetHeight( int h){ m_bSetHeight = TRUE;m_nHeight = h;WINDOWPOS wp;CRect rcWindow;::GetWindowRect( m_hWnd, &rcWindow);wp.hwnd = m_hWnd;wp.cx = rcWindow.Width();wp.cy = rcWindow.Height();wp.flags = SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER;SendMessage(WM_WINDOWPOSCHANGED, 0, (LPARAM)&wp);}int  CListCtrlCore::GetHeight( ){m_bSetHeight = FALSE;WINDOWPOS wp;CRect rcWindow;::GetWindowRect( m_hWnd, &rcWindow);wp.hwnd = m_hWnd;wp.cx = rcWindow.Width();wp.cy = rcWindow.Height();wp.flags = SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER;SendMessage(WM_WINDOWPOSCHANGED, 0, (LPARAM)&wp);return m_nHeight;}void CListCtrlCore::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct){if ( m_bSetHeight){lpMeasureItemStruct->itemHeight = m_nHeight;}else{m_nHeight = lpMeasureItemStruct->itemHeight;}}