?? menulistctrl.cpp
字號:
SetRedraw(TRUE);
UpdateWindow();
Invalidate();
}
}
return CListCtrl::OnNotify(wParam, lParam, pResult);
}
void CMenuListCtrl::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
CListCtrl::OnKeyDown(nChar, nRepCnt, nFlags);
}
void CMenuListCtrl::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)
{
CListCtrl::OnKeyUp(nChar, nRepCnt, nFlags);
}
void CMenuListCtrl::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
// if ( 0x2B == nIDEvent ) InvalidateRect( FALSE );
CListCtrl::OnTimer(nIDEvent);
}
void CMenuListCtrl::LineDown()
{
SendMessage( WM_VSCROLL, MAKELONG(SB_PAGEDOWN,0), NULL);
}
void CMenuListCtrl::InitVScroll()
{
CWnd* pParent = GetParent();
PositionScrollBars();
}
void CMenuListCtrl::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);
}
void CMenuListCtrl::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 CMenuListCtrl::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 CMenuListCtrl::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 CMenuListCtrl::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+36/*((-lf.lfHeight+nAdj) * (m_nLinesPerRow))*/;
else
lpMeasureItemStruct->itemHeight = lf.lfHeight+10/*((lf.lfHeight+nAdj) * (m_nLinesPerRow))*/;
}
void CMenuListCtrl::OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct)
{
CListCtrl::OnMeasureItem(nIDCtl, lpMeasureItemStruct);
}
void CMenuListCtrl::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 = _gmszColumnLabel[i];
lvc.cx = _gmnColumnWidth[i];
lvc.fmt = _gmnColumnFmt[i];
InsertColumn(i,&lvc);
}
m_nLinesPerRow = 2;
if ( m_nLinesPerRow > 1 )
{
m_NewListFont.CreatePointFont(132,_T("MS Serif"));
}
m_NewFont.CreatePointFont(128,_T("宋體"));
}
void CMenuListCtrl::SubclassHeaderControl()
{
if (m_bHeaderIsSubclassed)
return;
CHeaderCtrl* pHeader = GetHeaderCtrl();
if (pHeader)
{
VERIFY(m_HeaderCtrl.SubclassWindow(pHeader->m_hWnd));
m_bHeaderIsSubclassed = TRUE;
}
}
void CMenuListCtrl::PreSubclassWindow()
{
// TODO: Add your specialized code here and/or call the base class
CListCtrl::PreSubclassWindow();
SubclassHeaderControl();
}
int CMenuListCtrl::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 CMenuListCtrl::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 CMenuListCtrl::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 + -