【VC开源代码栏目提醒】:网学会员鉴于大家对VC开源代码十分关注,论文会员在此为大家搜集整理了“DROPLISTBOX.CPP”一文,供大家参考学习
/************************************
REVISION LOG ENTRY
Revision By: Mihai Filimon
Revised on 10/16/98 9:46:06 AM
Comments: DropListBox.cpp : implementation file
************************************/
#include "stdafx.h"
#include "xpropertieswnd.h"
#include "DropListBox.h"
#include "PageListCtrl.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDropListBox
// Function name : CDropListBox::CDropListBox
// Description : Default consturctor
// Return type :
CDropListBox::CDropListBox()
{
m_pNotifyClass = NULL;
m_bCancel = FALSE;
m_nSelectedItem = -1;
}
// Function name : CDropListBox::~CDropListBox
// Description : Virtual destructor
// Return type :
CDropListBox::~CDropListBox()
{
}
BEGIN_MESSAGE_MAP(CDropListBox, CListBox)
//{{AFX_MSG_MAP(CDropListBox)
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONDOWN()
ON_WM_KEYDOWN()
ON_WM_KILLFOCUS()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDropListBox message handlers
#define IDLISTBOX 1000
// Function name : CDropListBox::_Create
// Description : Create the list box.
// Return type : BOOL
// Argument : CControlsWnd_CComboBox* pNotifyClass
CWnd* CDropListBox::Create(CControlsWnd_CComboBox* pNotifyClass)
{
// Do not call this twice
ASSERT (!::IsWindow(GetSafeHwnd()));
// if (CListBox::Create(WS_CHILD | WS_VSCROLL | WS_HSCROLL | WS_BORDER ,CRect(0,0,0,0), GetDesktopWindow(), IDLISTBOX))
if (CWnd::CreateEx(WS_EX_TOOLWINDOW, _T("LISTBOX"), NULL, WS_POPUP | WS_VSCROLL | WS_HSCROLL | WS_BORDER , 0,0,0,0 , pNotifyClass->GetWindowNotify()->m_hWnd, NULL))
{
m_pNotifyClass = pNotifyClass;
// ModifyStyleEx(0, WS_EX_TOOLWINDOW);
SetFont(m_pNotifyClass->GetWindowNotify()->GetFont());
return this;
}
return NULL;
}
// Function name : CDropListBox::Load
// Description : Load Items into list box
// Return type : void
// Argument : LPCTSTR lpszItems
// Argument : TCHAR c
void CDropListBox::Load(LPCTSTR lpszItems, TCHAR c)
{
ASSERT (m_pNotifyClass);
ResetContent();
LPTSTR lpszItem = (LPTSTR)lpszItems;
while (lpszItem)
{
LPTSTR lpszNItem = _tcschr(lpszItem, c);
AddString(lpszNItem ? CString(lpszItem, lpszNItem - lpszItem) : CString(lpszItem));
lpszItem = lpszNItem ? lpszNItem + 1 : NULL;
}
}
// Function name : CDropListBox::Show
// Description : Show the window
// Return type : BOOL
// Argument : CRect rect
void CDropListBox::Show(CRect rect, int nLines)
{
// You must call Load function before
ASSERT(::IsWindow(GetSafeHwnd()));
{
nLines = abs(nLines);
m_pNotifyClass->GetWindowNotify()->ClientToScreen(rect);
int h = GetItemHeight(0); h = h == LB_ERR ? 16 : h;
int nDY = max(1,min(nLines, GetCount())) * (h + 1);
CRect rMove(rect);
rMove.bottom = rMove.top + nDY;
MoveWindow(rMove);
GetWindowRect(rMove);
nDY = rMove.Height();
if (nDY + rect.bottom < GetSystemMetrics(SM_CYSCREEN))
{
rect.top = rect.bottom;
rect.bottom = rect.top + nDY;
}
else
{
rect.bottom = rect.top;
rect.top = rect.bottom - nDY;
}
MoveWindow(rect);
SetWindowPos(&CWnd::wndTopMost,0,0,0,0, SWP_NOMOVE | SWP_NOSIZE);
ShowWindow(SW_SHOW);
SetFocus();
SetCapture();
}
}
// Function name : CDropListBox::OnMouseMove
// Description : MouseMove
// Return type : void
// Argument : UINT nFlags
// Argument : CPoint point
void CDropListBox::OnMouseMove(UINT nFlags, CPoint point)
{
CRect rect; GetClientRect(rect);
if (rect.PtInRect