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

📄 gfxincombo.cpp

📁 我自己整理的一些VC源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		}
	}
	if (pMsg->message == WM_KEYDOWN || pMsg->message == WM_CHAR)
	{
		if (pMsg->wParam == VK_UP)   SetCurSel(iCurSel - 1);
		if (pMsg->wParam == VK_DOWN) SetCurSel(iCurSel + 1);
		if (pMsg->wParam == VK_RETURN)
		{
			ProcessSelect();
			pParent->SetFocus();
			return TRUE;
		}
		if (pMsg->wParam == VK_ESCAPE)
		{
			m_bESC = TRUE;
			pParent->SetFocus();
			return TRUE;
		}
		if (pMsg->wParam == VK_TAB)
		{
			SHORT sh = GetKeyState(VK_SHIFT);
			if (sh < 0) PreviousTab();
			else NextTab();
			return TRUE;
		}

		if (pMsg->wParam == VK_LEFT)
		{
			LeftCell();
			return TRUE;
		}
		if (pMsg->wParam == VK_RIGHT)
		{
			RightCell();
			return TRUE;
		}


		if (!bEditable) 
		{
			if (((char) pMsg->wParam >= 'a' && (char) pMsg->wParam >= 'z') || ((char) pMsg->wParam >= 'A' && (char) pMsg->wParam >= 'Z') || ((char) pMsg->wParam >= '0' && (char) pMsg->wParam >= '9'))
			{
				CString cs = FindFromCharPressed((char) pMsg->wParam);
				if (cs != "") 
				{
					wndStatic.SetWindowText(cs);
					wndStatic.Invalidate();
				}
			}
		}

		::TranslateMessage(pMsg);
		::DispatchMessage(pMsg);
		return TRUE;
	}
	
	return CWnd::PreTranslateMessage(pMsg);
}

LRESULT CGfxInCombo::OnSelendOk(WPARAM wParam, LPARAM lParam)
{
	st_iteminfo *pstItem = (st_iteminfo *)lParam;
	m_dwData = pstItem->dwData;
	if (bEditable)
	{
		wndEdit.m_dwData = m_dwData;
		wndEdit.SetWindowText(pstItem->strText.GetBuffer( 0 ));
	}
	else 
	{
		wndStatic.SetWindowText(pstItem->strText.GetBuffer( 0 ));
		wndStatic.Invalidate();
	}
	if ((int) wParam >= 0) iCurSel = (int) wParam;

	return 1L;
}

void CGfxInCombo::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	if (nChar == VK_ESCAPE) 
	{
		m_bESC = TRUE;
		GetParent()->SetFocus();
		return;
	}
	
	CWnd::OnChar(nChar, nRepCnt, nFlags);
}

int CGfxInCombo::FindStringExact(const int iStart, const char * cText)
{
	if (pArray)
	{
		CString csText(cText);
		for (int t = 0; t < pArray->GetSize(); t++)
			if ((*pArray)[t] != "" && (*pArray)[t] == csText && t >= iStart) return t;
	}
	return -1;
}

CString CGfxInCombo::FindFromCharPressed(char c)
{
	CString cs;
	int iActSel = iCurSel;

	if (pArray)
	{
		int t;
		CString csText(c);

		for (t = iCurSel >= 0 ? iCurSel : 0; t < pArray->GetSize(); t++)
		{
			CString item = (*pArray)[t];
			if ((*pArray)[t] != "")
			{
				if (item.Left(1) == csText)
				{
					iCurSel = t;
					return item;
				}
			}
		}
		if (iCurSel > 0)
		{
			for (t = 0; t < iCurSel; t++)
			{
				CString item = (*pArray)[t];
				if ((*pArray)[t] != "")
				{
					if (item.Left(1) == csText)
					{
						iCurSel = t;
						return item;
					}
				}
			}
		}
	}
	return cs;
}

int CGfxInCombo::SetCurSel(const int iSel)
{
	if (iSel >= 0 && (pArray != NULL && iSel < pArray->GetSize()))
	{
		iCurSel = iSel;
		CString cs = (*pArray)[iCurSel];
		if (bEditable)
		{
			wndEdit.m_dwData = m_dwData;
			wndEdit.SetWindowText(cs);
		}
		else 
		{
			wndStatic.SetWindowText(cs);
			wndStatic.Invalidate();
		}
	}
	return -1;
}

void CGfxInCombo::ProcessSelect(const char * cForceText, DWORD dwData)
{
//	if (bProcessed) return;
//	bProcessed = true;
	if (!GetSafeHwnd() || !IsWindow(GetSafeHwnd())) return;
	CString str;

	if (cForceText) 
	{
		str = cForceText;
	}
	else
	{
		if (bEditable) 
		{
			if (wndEdit.GetSafeHwnd()) wndEdit.GetWindowText(str);
			else str = wndEdit.csLstText;
		}
		else wndStatic.GetWindowText(str);
	}

	if (m_sInitText != str) 
	{
		m_sInitText = str;
		LV_DISPINFO dispinfo;
		dispinfo.hdr.hwndFrom = GetParent()->m_hWnd;
		dispinfo.hdr.idFrom = GetDlgCtrlID();
		dispinfo.hdr.code = LVN_ENDLABELEDIT;

		dispinfo.item.mask = LVIF_TEXT | LVIF_PARAM;
		dispinfo.item.iItem = m_iItem;
		dispinfo.item.iSubItem = m_iSubItem;
		dispinfo.item.pszText = m_bESC ? NULL : LPTSTR((LPCTSTR)str);
		dispinfo.item.cchTextMax = str.GetLength();
		dispinfo.item.lParam = m_dwData;

		GetParent()->SendMessage(WM_NOTIFY, GetParent()->GetDlgCtrlID(), (LPARAM)&dispinfo);
	}
}

int CGfxInCombo::FindString(int nStartAfter, CString find)
{
	if (pArray)
	{
		for (int t = nStartAfter >= 0 ? nStartAfter : 0; t < pArray->GetSize(); t++)
		{
			CString item = (*pArray)[t];
			if (item.GetLength() >= find.GetLength())
				if (item.Left(find.GetLength()).CompareNoCase(find) == 0) return t;
		}
	}
	return -1;
}

void CGfxInCombo::OnSetFocus(CWnd* pOldWnd) 
{
	CWnd::OnSetFocus(pOldWnd);
	if (bEditable && wndEdit.GetSafeHwnd()) wndEdit.SetFocus();
}

void CGfxInCombo::LeftCell()
{
	CWnd * pParent = GetParent();
	int ip[2] = { m_iItem, m_iSubItem };
	ProcessSelect();
	//PostMessage(WM_CLOSE);
	DestroyWindow();
	pParent->SendMessage(WM_USER_TAB, 2, (LPARAM) &ip);
}

void CGfxInCombo::RightCell()
{
	CWnd * pParent = GetParent();
	int ip[2] = { m_iItem, m_iSubItem };
	ProcessSelect();
	DestroyWindow();
	//PostMessage(WM_CLOSE);
	pParent->SendMessage(WM_USER_TAB, 3, (LPARAM) &ip);
}

void CGfxInCombo::UpCell()
{

}

void CGfxInCombo::DownCell()
{

}

void CGfxInCombo::NextTab()
{
	CWnd * pParent = GetParent();
	int ip[2] = { m_iItem, m_iSubItem };
	ProcessSelect();
	DestroyWindow();
	//PostMessage(WM_CLOSE);
	pParent->SendMessage(WM_USER_TAB, 0, (LPARAM) &ip);
}

void CGfxInCombo::PreviousTab()
{
	CWnd * pParent = GetParent();
	int ip[2] = { m_iItem, m_iSubItem };
	ProcessSelect();
	DestroyWindow();
	//PostMessage(WM_CLOSE);
	pParent->SendMessage(WM_USER_TAB, 1, (LPARAM) &ip);
}

void CGfxInCombo::OnLButtonDblClk(UINT nFlags, CPoint point) 
{
	CWnd::OnLButtonDblClk(nFlags, point);
	NMHDR nh;
	nh.hwndFrom = GetParent()->GetSafeHwnd();
	nh.idFrom = GetParent()->GetDlgCtrlID();
	nh.code = NM_DBLCLK;
	GetParent()->GetParent()->PostMessage(WM_NOTIFY, GetParent()->GetDlgCtrlID(), (LPARAM) &nh);
}

void CGfxInCombo::PostNcDestroy() 
{
	CWnd::PostNcDestroy();
	delete this;	
}

void CGfxInCombo::ListScroll()
{
	if( wndList.GetSafeHwnd() && bEditable )
	{
		CString strTmp, str1;
		wndEdit.GetWindowText( str1 );
		CRect rc;
		wndList.GetItemRect( 0, &rc, LVIR_BOUNDS );
		int nLen = 0;
		int count = wndList.GetItemCount();
		if( wndList.GetColumnCount() > 1 )
		{
			UINT state = LVIS_SELECTED | LVIS_FOCUSED | LVIS_ACTIVATING | LVIS_DROPHILITED;
			UINT mask  = LVIF_STATE;
			wndList.Scroll( CSize(0,-count * rc.Height()) );
			wndList.SetSelectionMark( -1 );
			for( int i = 0; i < count; i ++ ) wndList.SetItemState( i, 0, mask );
			for( i = 0; i < count; i ++ )
			{
				strTmp = wndList.GetItemText( i, 1 );
				nLen = str1.GetLength() < strTmp.GetLength() ? str1.GetLength() : strTmp.GetLength();
				for( int j = 0; j < nLen; j ++ )
				{
					strTmp.SetAt( j, tolower( strTmp.GetAt( j ) ) );
					str1.SetAt( j, tolower( str1.GetAt( j ) ) );
				}
				if( !strTmp.Left( nLen ).Compare( str1 ) )
				{
					wndList.SetSelectionMark( i );
					wndList.SetItemState( i, state, mask );
					wndList.Scroll( CSize(0,i * rc.Height()) );
					break;
				}
			}
		}
	}
}

⌨️ 快捷键说明

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