【VC开源代码栏目提醒】:网学会员为广大网友收集整理了,JCOMBOBX.CPP,希望对大家有所帮助!
// JComboBox.cpp : implementation file
//
#include "stdafx.h"
#include "JComboBx.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CTitleTip
CTitleTip::CTitleTip()
{
// Register the window class if it has not already been registered.
WNDCLASS wndcls;
HINSTANCE hInst = AfxGetInstanceHandle();
if(!(::GetClassInfo(hInst, TITLETIP_CLASSNAME, &wndcls)))
{
// otherwise we need to register a new class
wndcls.style = CS_SAVEBITS ;
wndcls.lpfnWndProc = ::DefWindowProc;
wndcls.cbClsExtra = wndcls.cbWndExtra = 0;
wndcls.hInstance = hInst;
wndcls.hIcon = NULL;
wndcls.hCursor = LoadCursor( hInst, IDC_ARROW );
wndcls.hbrBackground = (HBRUSH)(COLOR_INFOBK + 1); //COLOR_HIGHLIGHT;//
wndcls.lpszMenuName = NULL;
wndcls.lpszClassName = TITLETIP_CLASSNAME;
if (!AfxRegisterClass(&wndcls))
AfxThrowResourceException();
}
TITLETIP_SHOW = TRUE;
bFocusRect = FALSE;
}
CTitleTip::~CTitleTip()
{
}
BOOL CTitleTip::Create(CWnd * pParentWnd)
{
ASSERT_VALID(pParentWnd);
//ASSERT( !::IsWindow( m_hWnd ) );
DWORD dwStyle = WS_BORDER | WS_POPUP;
DWORD dwExStyle = WS_EX_TOOLWINDOW | WS_EX_TOPMOST;
m_pParentWnd = pParentWnd;
//if (m_hWnd == NULL)
return CreateEx( dwExStyle,
TITLETIP_CLASSNAME,
NULL,
dwStyle,
0,
0,
0,
0,
NULL,
NULL,
NULL );
//return FALSE;
}
// Show - Show the titletip if needed
// rectTitle - The rectangle within which the original
// title is constrained - in client coordinates
// lpszTitleText - The text to be displayed
// xoffset - Number of pixel that the text is offset from
// left border of the cell
void CTitleTip::Show(CRect rectTitle, LPCTSTR lpszTitleText, int xoffset /*=0*/)
{
ASSERT( ::IsWindow( m_hWnd ) );
//ASSERT( !rectTitle.IsRectEmpty() );
// Do not display the titletip is app does not have focus
if(( GetFocus() == NULL )||(!TITLETIP_SHOW))
{
if( IsWindowVisible() )
ShowWindow(FALSE);
return;
}
// Determine the width of the text
m_pParentWnd->ClientToScreen( rectTitle );
CClientDC dctmp(this);
dc = CDC::FromHandle(dctmp.m_hDC);
CString strTitle(lpszTitleText);
strTitle += _T(" ");
CFont *pFont = m_pParentWnd->GetFont(); // use same font as ctrl
dc->SelectObject( pFont );
CRect rectDisplay = rectTitle;
CSize size = dc->GetTextExtent( strTitle );
rectDisplay.top += 24;
rectDisplay.bottom += 25;
rectDisplay.left += xoffset-4;
rectDisplay.right = rectDisplay.left + size.cx +1;
// Do not display if the text fits within available space
if( rectDisplay.right < rectTitle.right-xoffset-5 ){
if( IsWindowVisible() )
ShowWindow(FALSE); //DestroyWindow();
return;
}
//;
if ( DCB_RESET == dc->GetBoundsRect(&rectTitle,DCB_RESET))
dc->SetBoundsRect(NULL,DCB_ENABLE);
dc->SetTextColor(GetSysColor(COLOR_HIGHLIGHTTEXT));
dc->SetBkColor(GetSysColor(COLOR_HIGHLIGHT));
// Show the titletip
// If titletip is already displayed, don't do anything.
if( IsWindowVisible() )
{
MoveWindow(rectDisplay.left, rectDisplay.top,
rectDisplay.Width(), rectDisplay.Height());
dc->FillSolidRect(&rectTitle,::GetSysColor(COLOR_HIGHLIGHT));
//if rectDisplay is not being used, let me use it for Text area
rectDisplay = rectTitle;
rectDisplay.left += 2;
dc->DrawText(strTitle,-1,rectDisplay, DT_LEFT | DT_SINGLELINE |
DT_NOPREFIX | DT_NOCLIP | DT_VCENTER);
dc->DrawFocusRect(&rectTitle);
}
else
{
SetWindowPos( &wndTop, rectDisplay.left, rectDisplay.top,
rectDisplay.Width(), rectDisplay.Height(),
SWP_SHOWWINDOW|SWP_NOACTIVATE );
dc->SetBkMode( OPAQUE );
dc->FillSolidRect(&rectTitle,::GetSysColor(COLOR_HIGHLIGHT));
dc->DrawText(strTitle,-1,rectDisplay, DT_LEFT | DT_SINGLELINE | DT_NOPREFIX |
DT_NOCLIP | DT_VCENTER);
dc->DrawFocusRect(&rectTitle);
}
}
/////////////////////////////////////////////////////////////////////////////
// CJComboBox
CJComboBox::CJComboBox()
{
TotalCol = 1;
CHECKBOX = FALSE;
m_pJStruct = NULL;
/* pFirst = NULL;
pCurrent = NULL;
pObjDump = NULL;
*/
}
CJComboBox::~CJComboBox()
{
////////////////////////////////////////////////////////////////
// Yes, I could use MFC Collection class
// But, it looks crappy anyway.
// It doesn't give me a good practice approach.
// Maybe one of these days I will use it (-; (when I became lazy)
/////////////////////////////////////////////////////////////////
POSITION pos = m_jcbList.GetHeadPosition();
while (pos != NULL)
{
delete m_jcbList.GetNext(pos);
}
m_jcbList.RemoveAll();
///////////////////////////////////////////////////
BOOL bSuccess = m_titletip.DestroyWindow();
/* for(pCurrent = pFirst; pCurrent != NULL ; ){
pObjDump = pCurrent;
pCurrent = pCurrent->next;
delete pObjDump;
}*/
CComboBox::~CComboBox();
}
BEGIN_MESSAGE_MAP(CJComboBox, CComboBox)
//{{AFX_MSG_MAP(CJComboBox)
ON_WM_MOUSEMOVE()
ON_CONTROL_REFLECT(CBN_CLOSEUP, OnCloseup)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CJComboBox message handlers
// if your sorting scheme is different than a standard collating sequence,
// such as one where the comparisons need to be case-insensitive.)
int CJComboBox::CompareItem(LPCOMPAREITEMSTRUCT lpCompareItemStruct)
{
return -1;
}
void CJComboBox::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
BOOL bFocus=(lpDrawItemStruct->itemAction & ODA_FOCUS);
BOOL bDrawEntire=(lpDrawItemStruct->itemAction & ODA_FOCUS);
BOOL bSelected = ((lpDrawItemStruct->itemState & ODS_SELECTED));
//Hide the titletip first until dropdown is active
//but titletip window has been initialised.... (-:
m_titletip.TITLETIP_SHOW = GetDroppedState();
if (bFocus||bSelected)
{
if (EDGE_STYLE == EDGE)
DrawDropList(lpDrawItemStruct, EDGE_HIGHLIGHT);
else
DrawDropList(lpDrawItemStruct,HIGH_LIGHT);
}
else
{
if (EDGE_STYLE == EDGE)
DrawDropList(lpDrawItemStruct, EDGE_NORMAL);
else
DrawDropList(lpDrawItemStruct,NORMAL);
}
if (CHECKBOX)
if( (lpDrawItemStruct->itemID == CurSel)) //(bSelected)||
DrawDropList(lpDrawItemStruct,CHECKED);
}
// You can actually specify variable heights as long as you set the
// CBS_OWNERDRAWVARIABLE style.
void CJComboBox::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct)
{
// all items are of fixed s
上一篇:
JCOMBO.CPP
下一篇:
浅析普外科围手术期抗菌药物的应用