【VC开源代码栏目提醒】:网学会员,鉴于大家对VC开源代码十分关注,论文会员在此为大家搜集整理了“VXOPTPICKER.CPP”一文,供大家参考学习!
/////////////////////////////////////////////////////////////////////////////
// CVxOptPicker.cpp : implementation file
//
//
#include "hello.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CVxOptPicker
CVxOptPicker::CVxOptPicker(int width, int height, int rows, int columns)
{
m_CurText = "M";
m_CurBitmap = 0;
m_CurButton = NULL ;
m_PopupWnd = NULL ;
m_PopupWndVisible = 0 ;
m_Width = width; // default
m_Height = height;
m_Rows = rows;
m_Columns = columns;
}
CVxOptPicker::~CVxOptPicker()
{
ASSERT(m_PopupWnd);
/* We don't need this loop since in real dialog, buttons WILL get deleted
CWnd *childWnd;
childWnd = (CWnd *)m_PopupWnd->GetWindow(GW_CHILD);
while(childWnd != NULL)
{
TRACE("Hmmm somebody created a control and did not add\
it to the control array. This mesg. is coming out\
from CVxDialog::OnClose() function call.");
delete(childWnd);
childWnd = (CWnd *)m_PopupWnd->GetWindow(GW_CHILD);
}
*/
m_PopupWnd->DestroyWindow();
}
BEGIN_MESSAGE_MAP(CVxOptPicker, CButton)
//{{AFX_MSG_MAP(CVxOptPicker)
ON_CONTROL_REFLECT_EX(BN_CLICKED, OnClicked)
ON_CONTROL_REFLECT(WM_ACTIVATE, OnKillFocus)
ON_WM_CREATE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CVxOptPicker message handlers
void CVxOptPicker::OnKillFocus( )
{
CPoint point ;
DWORD pos = GetMessagePos();
point = CPoint(LOWORD(pos), HIWORD(pos));
CRect pickerRect, popupRect ;
this->GetWindowRect(pickerRect);
ASSERT(m_PopupWnd);
m_PopupWnd->GetWindowRect(popupRect);
// Check to see if the point is outside of Picker and Popup
// window rectangles. If it is then hide the popup window
if ( !(pickerRect.PtInRect(point)) && !(popupRect.PtInRect(point)))
m_PopupWnd->ShowWindow(SW_HIDE);
}
int CVxOptPicker::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CButton::OnCreate(lpCreateStruct) == -1)
return -1;
SetWindowSize(); // resize appropriately
// Here we don't need to worry about the position of the window
// since we going to relocate it before it is shown anyways.
m_PopupWnd = new CVxOptPopup(CPoint(0,0), this, 10);
return 0;
}
// On mouse click, create and show a CVxOptPopup window for colour selection
BOOL CVxOptPicker::OnClicked()
{
// If already visible then close the popup window
if(m_PopupWndVisible == 1)
{
m_PopupWndVisible = 0 ;
m_PopupWnd->ShowWindow(SW_HIDE);
//ReleaseCapture();
}
else
{
CRect rect, popupRect, curButRect ;
// Lets get window rect for the picker button
GetWindowRect(rect);
// I always like to assert on my variables
ASSERT(m_PopupWnd);
// Lets get the popup window rect. We need to know the Width, Height
m_PopupWnd->GetWindowRect(popupRect);
if(m_CurButton == NULL)
{
// First move the window at the bottom of the Picker(sucker!) button
m_PopupWnd->MoveWindow(rect.left, rect.top, popupRect.Width(), popupRect.Height(), TRUE);
}
else
{
m_CurButton->GetWindowRect(curButRect);
m_PopupWnd->ScreenToClient(curButRect);
m_PopupWnd->MoveWindow(rect.left - curButRect.left + CONTROL_OFFSET,
rect.top - curButRect.top + CONTROL_OFFSET,
popupRect.Width(), popupRect.Height(), TRUE);
}
// Now lets relocate again in case window has gone outside the screen
m_PopupWnd->SetWindowSize();
// Now that we have repositioned it correctly, we are ready to rock'n'roll
m_PopupWndVisible = 1 ; // Set the visible flag to true
m_PopupWnd->ShowWindow(SW_SHOW);
//m_PopupWnd->SetCapture();
}
// Docs say I should return FALSE to stop the parent also getting the message.
// HA! What a joke.
return TRUE;
}
void CVxOptPicker::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
ASSERT(lpDrawItemStruct != NULL);
CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
CRect rect = lpDrawItemStruct->rcItem;
UINT state = lpDrawItemStruct->itemState;
DWORD dwStyle = GetStyle();
CSize Margins(::GetSystemMetrics(SM_CXEDGE), ::GetSystemMetrics(SM_CYEDGE));
// Draw arrow
pDC->FillSolidRect(m_ArrowRect, ::GetSysColor(COLOR_3DFACE));
pDC->DrawEdge(m_ArrowRect, EDGE_RAISED, BF_RECT);
int nArrowTop = m_ArrowRect.top + m_ArrowRect.