⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jwlistctrl.cpp

📁 wince list control based on vs2005
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	
	// Draw normal and overlay icon
	pImageList = GetImageList(LVSIL_SMALL);
	if (pImageList)
	{
		UINT nOvlImageMask=lvi.state & LVIS_OVERLAYMASK;
		pImageList->Draw(pDC, lvi.iImage, 
			CPoint(rcIcon.left, rcIcon.top),
			(bHighlight?ILD_BLEND50:0) | ILD_TRANSPARENT | nOvlImageMask );
	}

	
	
	// Draw item label - Column 0
	rcLabel.left += offset/2;
	rcLabel.right -= offset;

	pDC->DrawText(sLabel,-1,rcLabel,DT_LEFT | DT_SINGLELINE | DT_NOPREFIX | DT_NOCLIP 
				| DT_VCENTER | 0x00008000);//DT_END_ELLIPSIS);


	// Draw labels for remaining columns
	LV_COLUMN lvc;
	lvc.mask = LVCF_FMT | LVCF_WIDTH;

	if( m_nHighlight == 0 )		// Highlight only first column
	{
		pDC->SetTextColor(::GetSysColor(COLOR_WINDOWTEXT));
		pDC->SetBkColor(::GetSysColor(COLOR_WINDOW));
	}
	
	rcBounds.right = rcHighlight.right > rcBounds.right ? rcHighlight.right :
							rcBounds.right;
	rgn.CreateRectRgnIndirect(&rcBounds);
	pDC->SelectClipRgn(&rgn);
				   
	for(int nColumn = 1; GetColumn(nColumn, &lvc); nColumn++)
	{
		rcCol.left = rcCol.right;
		rcCol.right += lvc.cx;

		// Draw the background if needed&& m_nHighlight == HIGHLIGHT_NORMAL
		if( m_bitmap.m_hObject == NULL  )
		{	
			pDC->FillRect(rcCol, &CBrush(::GetSysColor(COLOR_WINDOW)));
			pDC->SetBkMode ( TRANSPARENT );
		}



		sLabel = GetItemText(nItem, nColumn);
		if (sLabel.GetLength() == 0)
			continue;


		// Get the text justification
		UINT nJustify = DT_LEFT;
		switch(lvc.fmt & LVCFMT_JUSTIFYMASK)
		{
		case LVCFMT_RIGHT:
			nJustify = DT_RIGHT;
			break;
		case LVCFMT_CENTER:
			nJustify = DT_CENTER;
			break;
		default:
			break;
		}

		rcLabel = rcCol;
		rcLabel.left += offset;
		rcLabel.right -= offset;

		pDC->DrawText(sLabel, -1, rcLabel, nJustify | DT_SINGLELINE 
				| DT_NOPREFIX | DT_VCENTER | 0x00008000);//DT_END_ELLIPSIS);
	}

	// Draw focus rectangle if item has focus
	if (lvi.state & LVIS_FOCUSED && (GetFocus() == this))
		pDC->DrawFocusRect(rcHighlight);

	// Restore dc
	pDC->RestoreDC( nSavedDC );

 	SetRedraw(TRUE); 
//	Invalidate();
}

BOOL CJWListCtrl::InsertImgTextItems( UINT ImgID , int Imgcx , int Imgcy, int ImgNumth , CString strItemText)
{
	//InitImage
	// Create 256 color image lists
 	SetRedraw( FALSE );
	 
 	HIMAGELIST hList = ImageList_Create(Imgcx , Imgcy , ILC_MASK , 1, 1);
	m_cImageListNormal.Attach(hList);
 
	// Load the large icons
	CBitmap cBmp;
	cBmp.LoadBitmap( ImgID );
	m_cImageListNormal.Add(&cBmp, RGB(255,0, 255));
	cBmp.DeleteObject();

	// Attach them
	SetImageList(&m_cImageListNormal, LVSIL_NORMAL);  

	////////////////////////////////////////////////////////////////////////////
    // InserItems
	LVITEM lvi;
	CString strItem;
 
	// Insert the item
	
	lvi.mask =  LVIF_IMAGE | LVIF_TEXT;
	//lvi.iItem = 2;
	lvi.iSubItem = 0;
	lvi.pszText = (LPTSTR)(LPCTSTR)(strItemText);
	lvi.iImage = ImgNumth;		// There are 8 images in the image list

	InsertItem(&lvi);
 
	m_cImageListNormal.Detach();	
	m_cImageListNormal.DeleteImageList();
	m_cImageListNormal.DeleteTempMap();
	cBmp.Detach();
	cBmp.DeleteTempMap();
	cBmp.DeleteObject();

	SetRedraw( TRUE );; 

 	Invalidate();	
 	UpdateWindow();

	return TRUE;

}

 
BOOL CJWListCtrl::SetBkColor(COLORREF cr)
{
	ASSERT(::IsWindow(m_hWnd)); 
	::SendMessage(m_hWnd, LVM_SETTEXTBKCOLOR, 0, cr); 
	return (BOOL) ::SendMessage(m_hWnd, LVM_SETBKCOLOR, 0, cr); 


}
 

BOOL CJWListCtrl::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT *pResult)
{
	HD_NOTIFY	*pHDN = (HD_NOTIFY*)lParam;
  
	// This code is for using bitmap in the background
	// Invalidate the right side of the control when a column is resized
	if(pHDN->hdr.code == HDN_ITEMCHANGINGW || pHDN->hdr.code == HDN_ITEMCHANGINGA)
	{
		if( m_bitmap.m_hObject != NULL )
		{
			SetRedraw(FALSE); 
			CRect rcClient;
			GetClientRect( &rcClient );	
			DWORD dwPos = GetMessagePos();
			CPoint pt( LOWORD(dwPos), HIWORD(dwPos) );
			ScreenToClient( &pt );
			rcClient.left = pt.x;

			SetRedraw(TRUE);
			UpdateWindow();
			//InvalidateRect( rcClient, FALSE );
			Invalidate();
		}
	}
	
	return CListCtrl::OnNotify(wParam, lParam, pResult);

}


void CJWListCtrl::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	// TODO: Add your message handler code here and/or call default
	//InvalidateRect( FALSE );
	m_SkinVerticleScrollbar.UpdateThumbPosition();
	//PositionScrollBars();
	CListCtrl::OnKeyDown(nChar, nRepCnt, nFlags);
}

void CJWListCtrl::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	m_SkinVerticleScrollbar.UpdateThumbPosition();
	//PositionScrollBars();
	CListCtrl::OnKeyUp(nChar, nRepCnt, nFlags);
}


void CJWListCtrl::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	if ( 0x2B == nIDEvent )  InvalidateRect( FALSE );

	CListCtrl::OnTimer(nIDEvent);
}

/*
void CJWListCtrl::OnMouseMove( UINT nFlags, CPoint point )
{
	CHeaderCtrl *pHeader = GetHeaderCtrl();

	if ((MK_LBUTTON & nFlags) == MK_LBUTTON)
	{
		RECT rc;
		GetClientRect(&rc);
		if (point.y < 0 || point.y >= rc.bottom)
		{
			Invalidate(TRUE);
		}
	}

}
*/

//DEL void CJWListCtrl::OnMouseMove(UINT nFlags, CPoint point) 
//DEL {
//DEL 	// TODO: Add your message handler code here and/or call default
//DEL  
//DEL 	CListCtrl::OnMouseMove(nFlags, point);
//DEL }


void CJWListCtrl::LineDown()
{
	SendMessage( WM_VSCROLL, MAKELONG(SB_PAGEDOWN,0), NULL); 
}

void CJWListCtrl::InitVScroll()
{
// 	InitializeFlatSB(m_hWnd);
// 	FlatSB_EnableScrollBar(m_hWnd, SB_BOTH, ESB_DISABLE_BOTH);

	CWnd* pParent = GetParent();

	//Create scrollbars at runtime
	m_SkinVerticleScrollbar.Create(NULL, WS_CHILD|SS_LEFT|SS_NOTIFY|WS_VISIBLE|WS_GROUP,CRect(0,0,0,0), pParent);
	m_SkinVerticleScrollbar.pList = this;
	//call this to position the scrollbars properly
	PositionScrollBars();
}

void CJWListCtrl::PositionScrollBars()
{
	CWnd* pParent = GetParent();
	
	CRect windowRect;
	GetWindowRect(&windowRect);

	
	int nTitleBarHeight = 0;
	
	if(pParent->GetStyle() & WS_CAPTION)
		nTitleBarHeight = GetSystemMetrics(31);
	
	
	int nDialogFrameHeight = 0;
	int nDialogFrameWidth = 0;
	if((pParent->GetStyle() & WS_BORDER))
	{
		nDialogFrameHeight = GetSystemMetrics(SM_CYDLGFRAME);
		nDialogFrameWidth = GetSystemMetrics(SM_CYDLGFRAME);
	}
	
	if(pParent->GetStyle() & WS_THICKFRAME)
	{
		nDialogFrameHeight+=1;
		nDialogFrameWidth+=1;
	}
	
	pParent->ScreenToClient(&windowRect);

	windowRect.top+=nTitleBarHeight+nDialogFrameHeight;
	windowRect.bottom+=nTitleBarHeight+nDialogFrameHeight;
	windowRect.left +=nDialogFrameWidth;
	windowRect.right+=nDialogFrameWidth;

	CRect vBar(windowRect.right-nDialogFrameWidth,windowRect.top-nTitleBarHeight-nDialogFrameHeight,windowRect.right+12-nDialogFrameWidth,windowRect.bottom+12-nTitleBarHeight-nDialogFrameHeight);
	CRect hBar(windowRect.left-nDialogFrameWidth,windowRect.bottom-nTitleBarHeight-nDialogFrameHeight,windowRect.right+1-nDialogFrameWidth,windowRect.bottom+12-nTitleBarHeight-nDialogFrameHeight);
	
	m_SkinVerticleScrollbar.SetWindowPos(NULL,vBar.left,vBar.top,vBar.Width(),vBar.Height(),SWP_NOZORDER);
	
	m_SkinVerticleScrollbar.UpdateThumbPosition();
}

//DEL void CJWListCtrl::OnSize(UINT nType, int cx, int cy) 
//DEL {
//DEL 	
//DEL 	  CJWListCtrl   &   ctrl   =  GetListCtrl();  
//DEL 	  if   (ctrl)  
//DEL 	  {  
//DEL 		//隐藏垂直滚动条  
//DEL 		ShowScrollBar(   ctrl.m_hWnd,   SB_VERT,   FALSE);  
//DEL 	  }   
//DEL 	CJWListCtrl::OnSize(nType, cx, cy);
//DEL 	
//DEL }


void CJWListCtrl::OnSize(UINT nType, int cx, int cy) 
{
 	//隐藏垂直滚动条  
 	ShowScrollBar(SB_VERT,   FALSE);  
  
	CListCtrl::OnSize(nType, cx, cy);
		
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -