Originally posted by: Thales P. Carvalho
In the CColourPopup::Create:
BOOL CColourPopup::Create(
m_pParent = pParentWnd;
// Get the class name and create the window
// Finding the window's topmost parent
BOOL bCreate = CWnd::CreateEx(0, szClassName, _T(""), WS_VISIBLE|WS_POPUP,
if ( pTopParent != NULL )
if ( !bCreate )
// Store the Custom text
// Store the Default Area text
// Create the tooltips
// Find which cell (if any) corresponds to the initial colour
// Capture all mouse events for the life of this window
return TRUE;
That's a suggestion to keep the parent window title bar visually active when the ColourPopup box is dropped
down. I think it gives that a nicer look.
CPoint p,
COLORREF crColour,
CWnd* pParentWnd,
LPCTSTR szDefaultText /* = NULL */,
LPCTSTR szCustomText /* = NULL */
)
{
ASSERT(pParentWnd && ::IsWindow(pParentWnd->GetSafeHwnd()));
ASSERT(pParentWnd->IsKindOf(RUNTIME_CLASS(CColourPicker)));
m_crColour = m_crInitialColour = crColour;
CString szClassName = AfxRegisterWndClass(CS_CLASSDC|CS_SAVEBITS|CS_HREDRAW|CS_VREDRAW,
0,
(HBRUSH) (COLOR_BTNFACE+1),
0);
CWnd* pTopParent = m_pParent->GetTopLevelParent();
if ( pTopParent != NULL )
pTopParent->SetRedraw( FALSE );
p.x, p.y, 100, 100, // size updated soon
pParentWnd->GetSafeHwnd(), 0, NULL);
{
pTopParent->SendMessage( WM_NCACTIVATE, TRUE );
pTopParent->SetRedraw( TRUE );
}
return FALSE;
if (szCustomText != NULL)
m_strCustomText = szCustomText;
if (szDefaultText != NULL)
m_strDefaultText = szDefaultText;
// Set the window size
SetWindowSize();
CreateToolTips();
FindCellFromColour(crColour);
SetCapture();
}
Originally posted by: John J. Szucs
Thanks to the original author and the other contributors for this control!
I did observe one aesthetic issue, as follows:
Version 1.3 of the CColourPicker control is vertically "scrunched" when compared to the equivalent controls in Microsoft Office 2000 (Beta). To achieve the same appearance as the MS-Office 2000 color picker controls, set the height of this control to same size as a default-sized combo box (14 vertical dialog units) and use the new version of CColourPicker::SetWindowSize() shown below. This code contains a small change to use the greater of the color picker's minimum height or the height of its window (for example, a button laid out in the dialog editor).
void CColourPicker::SetWindowSize()
{
// Get size dimensions of edges
CSize MarginSize(::GetSystemMetrics(SM_CXEDGE), ::GetSystemMetrics(SM_CYEDGE));
// Get size of dropdown arrow
int nArrowWidth = max(::GetSystemMetrics(SM_CXHTHUMB), 5*MarginSize.cx);
int nArrowHeight = max(::GetSystemMetrics(SM_CYVTHUMB), 5*MarginSize.cy);
CSize ArrowSize(max(nArrowWidth, nArrowHeight), max(nArrowWidth, nArrowHeight));
// Get window size
CRect rect;
GetWindowRect(rect);
CWnd* pParent = GetParent();
if (pParent)
pParent->ScreenToClient(rect);
// Set window size at least as wide as 2 arrows, and as high as arrow + margins
int nWidth = max(rect.Width(), 2*ArrowSize.cx + 2*MarginSize.cx);
int nHeight = max(rect.Height(), ArrowSize.cy+2*MarginSize.cy);
MoveWindow(rect.left, rect.top, nWidth, nHeight, TRUE);
// Get the new coords of this window
GetWindowRect(rect);
ScreenToClient(rect);
// Get the rect where the arrow goes, and convert to client coords.
m_ArrowRect.SetRect(rect.right - ArrowSize.cx - MarginSize.cx,
rect.top + MarginSize.cy, rect.right - MarginSize.cx,
rect.bottom - MarginSize.cy);
}
Reply
Originally posted by: Mario Gudelj
Just two things when you add control into the CReBar:
I found easier to send notification messages to parent frame instead parent window. So, I changed calls GetParent() into the GetParentFrame() in functions OnSelEndOK, OnSelEndCancel and OnSelChange. Otherwise, messages comes to CReBar window.
Also, because of resizing bar features in CReBar, I added WM_SIZE handling in CColourPicker. It is needed to update m_ArrowRect member:
void CColourPicker::OnSize(UINT nType, int cx, int cy)
{
SetWindowSize();
}
Originally posted by: Per Grundstr�m
Hi
A very nice control.
Bug in bug fix when losing focus to another application:
You can't call EndSelection(CPN_SELENDCANCEL) when the CColorDialog is vissable, in the
CColourPopup::OnActivateApp procedure.
// Per