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

📄 jwlistctrl.cpp

📁 WinCE 下实现Listctrl自画
💻 CPP
📖 第 1 页 / 共 2 页
字号:
BOOL CMyListCtrl::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT *pResult)
{
	HD_NOTIFY	*pHDN = (HD_NOTIFY*)lParam;
  
	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();
			Invalidate();
		}
	}	
	return CListCtrl::OnNotify(wParam, lParam, pResult);

}


void CMyListCtrl::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	m_SkinVerticleScrollbar.UpdateThumbPosition();
	CListCtrl::OnKeyDown(nChar, nRepCnt, nFlags);
}

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


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

	CListCtrl::OnTimer(nIDEvent);
}


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

void CMyListCtrl::InitVScroll()
{
	CWnd* pParent = GetParent();
	m_SkinVerticleScrollbar.Create(NULL, WS_CHILD|SS_LEFT|SS_NOTIFY|WS_VISIBLE|WS_GROUP,CRect(0,0,0,0), pParent);
	m_SkinVerticleScrollbar.pList = this;
	PositionScrollBars();
}

void CMyListCtrl::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,18/*vBar.Width()*/,vBar.Height(),SWP_NOZORDER);	
	m_SkinVerticleScrollbar.UpdateThumbPosition();
}




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

	EnableScrollBarCtrl(SB_HORZ,FALSE);   
	EnableScrollBarCtrl(SB_VERT,FALSE);   

	CScrollBar * pBar = GetScrollBarCtrl(SB_VERT);//SB_VERT
	if(pBar)
	{
		pBar->ShowWindow(SW_HIDE);
		::AfxMessageBox(_T(""));
	}
	CListCtrl::OnSize(nType, cx, cy);		
}

void CMyListCtrl::HideScrollBars(int Type, int Which)
{
	if(Type==LCSB_CLIENTDATA) //This is the clientrect function
	{
		RECT ierect;
		int cxvs, cyvs;
		GetClientRect(&ierect); //Get client width and height
		
		cxvs = GetSystemMetrics (SM_CXVSCROLL); //Get the system metrics - VERT
		cyvs = GetSystemMetrics (SM_CYVSCROLL); //Get the system metrics - HORZ
		
		if(Which==SB_HORZ) cxvs=0; //Set VERT to zero when choosen HORZ
		if(Which==SB_VERT) cyvs=0; //Set HORZ to zero when choosen VERT
		
		//Here we set the position of the window to the clientrect + the size of the scrollbars
		SetWindowPos(NULL, ierect.left, ierect.top, ierect.right+cxvs, ierect.bottom+cyvs, SWP_NOMOVE | SWP_NOZORDER);
		
		//Her we modify the rect so the right part is subbed from the rect.
		if(Which==SB_BOTH||Which==SB_HORZ) ierect.bottom -= ierect.top;
		if(Which==SB_BOTH||Which==SB_VERT) ierect.right -= ierect.left;
		
		//Just to be safe that the left/top corner is 0...
		ierect.top = 0;
		ierect.left = 0;
		
		HRGN iehrgn = NULL; //This range is created base on which scrollbar that is going to be removed!
		
		//The -2 is probably a border of some kind that we also need to remove. I could not find any good
		//metrics that gave me an 2 as an answer. So insted we makes it static with -2.
		if(Which==SB_BOTH) iehrgn=CreateRectRgn (ierect.left, ierect.top, ierect.right, ierect.bottom-1);
		if(Which==SB_HORZ) iehrgn=CreateRectRgn (ierect.left, ierect.top, ierect.right, ierect.bottom+2);
		if(Which==SB_VERT) iehrgn=CreateRectRgn (ierect.left, ierect.top, ierect.right-2, ierect.bottom);
		
		//After the range has been made we add it...
		SetWindowRgn (iehrgn, TRUE);
		
		//Reset of NCOverride
		NCOverride=FALSE;
	}
	
	if(Type==LCSB_NCOVERRIDE) //This is the NcCalcSize override
	{
		NCOverride=TRUE; //Set to true, so we run the code on each OnNcCalcSize.
		Who=Which; //Selects which scrollbars to get hidden.
	}
}

LRESULT CMyListCtrl::OnSetFont(WPARAM wParam, LPARAM lParam)
{
	CRect rc;
	GetWindowRect(&rc);

	WINDOWPOS wp;
	wp.hwnd = this->m_hWnd;
	wp.cx = rc.Width() ;
	wp.cy = rc.Height() ;
	wp.flags = SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER;

	LRESULT lrReturn(Default());

	SendMessage(WM_WINDOWPOSCHANGED, 0, reinterpret_cast<LPARAM> (&wp));

	return lrReturn;
}

void CMyListCtrl::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct) 
{
	// Get the LOGFONT for the current font.
	LOGFONT lf;
	::ZeroMemory(&lf, sizeof(lf));

	CFont* pFont = GetFont();
	ASSERT_VALID(pFont);
	
	if (pFont) 
		VERIFY(pFont->GetLogFont(&lf));

	int nAdj(0) ;
	m_nLinesPerRow = max(m_nLinesPerRow, 1);

	if (lf.lfHeight < 0) 
		lpMeasureItemStruct->itemHeight = lf.lfHeight+40/*((-lf.lfHeight+nAdj) * (m_nLinesPerRow))*/;
	else 
		lpMeasureItemStruct->itemHeight = lf.lfHeight+10/*((lf.lfHeight+nAdj) * (m_nLinesPerRow))*/;
}

void CMyListCtrl::OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct) 
{
	CListCtrl::OnMeasureItem(nIDCtl, lpMeasureItemStruct);
}

void CMyListCtrl::OnInitialUpdate() 
{
	// Insert Header columns
	int i;
	LV_COLUMN lvc;
	lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;

	for(i = 0; i<1; i++)
	{
		lvc.iSubItem = i;
		lvc.pszText = _T("选项");
		lvc.cx = 303;
		lvc.fmt = LVCFMT_LEFT;
		InsertColumn(i,&lvc);
	}

	m_nLinesPerRow = 2;

	if ( m_nLinesPerRow > 1 ) 
	{
		m_NewListFont.CreatePointFont(148,_T("MS Serif"));
	}
	m_NewFont.CreatePointFont(142,_T("宋体"));

	
}

void CMyListCtrl::SubclassHeaderControl()
{
	if (m_bHeaderIsSubclassed)
		return;
	CHeaderCtrl* pHeader = GetHeaderCtrl();
	if (pHeader)
	{
		VERIFY(m_HeaderCtrl.SubclassWindow(pHeader->m_hWnd));
		m_bHeaderIsSubclassed = TRUE;
	}
}

void CMyListCtrl::PreSubclassWindow() 
{
	// TODO: Add your specialized code here and/or call the base class
	
	CListCtrl::PreSubclassWindow();
	SubclassHeaderControl();
}

int CMyListCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CListCtrl::OnCreate(lpCreateStruct) == -1)
	{
		ASSERT(FALSE);
		return -1;
	}
	
	// TODO: Add your specialized creation code here
	SubclassHeaderControl();
	return 0;
}
/************************************************************************/
/* 
函数名称: PaintIconByFilePath
函数功能: 根据文件后缀名称画文件显示图标
函数参数: 
    CDC *pDC——目标DC
	LPCRECT rcItem——图标位置
	CDC *pSrcDC——源DC
	LPCTSTR pstrName——判断文件名称后缀:
	    1、EXE——各个小应用、游戏
		2、空——文件夹
		3、BMP、JPG、GIF——图片
		4、MP3、WMA——音频播放器
		5、MP4、AVI——视频播放器
函数返回: 无
其他说明: 对于无法识别的图标未作操作
*/
/************************************************************************/
void CMyListCtrl::PaintIconByFilePath(CDC *pDC,LPCRECT rcItem, CDC *pSrcDC,LPCTSTR pstrName)
{
	CString m_csRoot;
	m_csRoot = pstrName;
	int nPos = m_csRoot.ReverseFind('.');
	if(nPos == -1)
	{
		m_csRoot = '\\';
	}
	else
	{
		m_csRoot = m_csRoot.Right(m_csRoot.GetLength()-nPos-1);
	}

	if (m_csRoot==_T("mp4"))//音频播放
	{
		TransparentBlt(pDC->m_hDC,rcItem->left+4,rcItem->top+7,17,16,
			pSrcDC->m_hDC,35,0,17,16,RGB(255,0,255));
	}
	else
		if (m_csRoot == '\\')//文件夹
		{
			TransparentBlt(pDC->m_hDC,rcItem->left+4,rcItem->top+7,17,16,
				pSrcDC->m_hDC,85,0,17,16,RGB(255,0,255));
		}
		else
			if (m_csRoot== _T("txt"))//电子书
			{
				TransparentBlt(pDC->m_hDC,rcItem->left+4,rcItem->top+7,17,16,
					pSrcDC->m_hDC,69,0,17,16,RGB(255,0,255));
			}
			else
				if (m_csRoot== _T("jpg")||m_csRoot== _T("bmp")||m_csRoot== _T("gif"))//电子书
				{
					TransparentBlt(pDC->m_hDC,rcItem->left+4,rcItem->top+7,17,16,
						pSrcDC->m_hDC,0,0,17,16,RGB(255,0,255));
				}
				else
					if (m_csRoot== _T("exe"))//电子书??相关应用程序的识别
					{
						TransparentBlt(pDC->m_hDC,rcItem->left+4,rcItem->top+7,17,16,
							pSrcDC->m_hDC,18,0,17,16,RGB(255,0,255));
					}
}

CString CMyListCtrl::GetFileNameFromPath(LPCTSTR path)
{
	CString m_csRoot;
	m_csRoot = path;
	int nPos = m_csRoot.ReverseFind('\\');
	if(nPos == -1)
	{
		m_csRoot = '\\';
	}
	else
	{
		m_csRoot = m_csRoot.Right(m_csRoot.GetLength()-nPos-1);
	}
	return m_csRoot;
}

⌨️ 快捷键说明

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