Originally posted by: paulpv
etc, etc...
Excellent!
I had a weird cut-n-paste error (no CRLF terminating my rc2 file).
Anyhoo, I'd like to suggest that you wrap all text/strings in _T's:
return (AfxGetApp()->WriteProfileBinary(_T("ColorData"), _T("ColorTable"), (LPBYTE)CColorBtnDlg::colors, sizeof(COLORREF)*20) &&
AfxGetApp()->WriteProfileBinary(_T("ColorData"), _T("MRU"), (LPBYTE)CColorBtnDlg::used, sizeof(BYTE)*20));
Originally posted by: John Dixson
Subclassing the button is not necessary. Just use the MFC class wizard and add a control variable to the dialog box, for the variable type select 'CColorBtn' instead of the standard 'CButton'.
You will need to rebuild the ClassWizard database (delete projects *.clw) for the Class Wizard to "see" the class.
Originally posted by: Chuck Messenger
To accomplish this, add to ColorBtn.h:
// Overrides
And add to ColorBtn.cpp:
--> void CColorBtn::PreSubclassWindow() {
Anyway, it's a very nice class -- thanks, Luis! (and Dan,
As per Roger Onslow's neat 3D text button, it's convenient
to make it so the button class takes care of setting up its
own style, rather than relying on you to remember to set
Owner Draw.
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CColorBtn)
--> virtual void PreSubclassWindow();
//}}AFX_VIRTUAL
--> SetButtonStyle(GetButtonStyle() | BS_OWNERDRAW);
--> }
for the Unsubclass() fix).
Originally posted by: Laurence
Would you like to tell me how to design a dialog box which has 16 color button, click each button, occur the custom color selector
ReplyOriginally posted by: sdfa
Class wizard inserts DDX_Control() in DoDataExchange()
when I put the button in the dialog box.
DDX_Control does SubclassDlgItem().
SubclassDlgItem() does SubclassWindow().
SubclassWindow() does Attach().
Debug build of Attach() checks ASSERT(m_hWnd == NULL).
If it is NULL, it sets m_hWnd = hWndNew.
But OnInitDialog() I did SubclassDlgItem() also.
Thus, debug build reported error message.
Conclusion is if you already have DDX_Control(),
don't do SubclassDlgItem() for each color button
in OnInitDialog().
This will fix debug build error.
Reply
Originally posted by: Tony Leigh
Add the member function:
And in the cpp file:
void CColorBtn::OnLButtonDown(UINT nFlags, CPoint point)
//check to see if click is in down arrow section
BEGIN_MESSAGE_MAP(CColorBtn, CButton)
A great little control! I added this code so that the
dialog only appears when you click on the arrow, and that
the current colour is selected if you click anywhere else.
afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
{
RECT buttonsize;
// get the size of the button
GetClientRect(&buttonsize);
if(point.x > buttonsize.right-10)
{
// in the arrow section
if (dlg.DoModal() == IDOK)
{
currentcolor = CColorBtnDlg::colors[dlg.colorindex];
InvalidateRect(NULL);
}
}
// update the colour anyway
// Add whatever code you need when the
// colour changes
}
//{{AFX_MSG_MAP(CColorBtn)
ON_CONTROL_REFLECT(BN_CLICKED, OnClicked)
ON_WM_LBUTTONDOWN()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
Originally posted by: Dan Mitchell
Just another note to say what everyone else is saying -- many thanks for the code, it's saved me a lot of hassle..
Oh, and the glitch in debug builds can be removed by calling
m_buttonChooseColor.UnsubclassWindow();
before the call to SubclassWindow.
-- dan
ReplyOriginally posted by: martin zidek
Thanx a lot I used it in my school project !
Thanx again !
Originally posted by: Jack Thomason
Its Simply Great.
Thanks Luis..
Originally posted by: Isabelle Chauv�
The macro ON_CONTROL_REFLECT_EX links a function without parameter to the message WM_COMMAND+WM_REFLECT_BASE
Actions to perform:
Remove All the parameters of the OnClicked function in the .cpp and .h files:
CColorBtn::OnClicked(NMHDR* pNotifyStruct, LRESULT* result)
CColorBtn::OnClicked()
and removes the following line inside the OnClicked function
*result=0;
With this line, the code could write anywhere in the memory,
so the consequence of this bug could be null or not.
Reply