Click here to Skip to main content
15,895,084 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: One last IOCP question :) Pin
Mark Salsbery1-Feb-07 12:12
Mark Salsbery1-Feb-07 12:12 
Questiondisappearing check boxes Pin
maladuk30-Jan-07 11:13
maladuk30-Jan-07 11:13 
AnswerRe: disappearing check boxes Pin
James R. Twine30-Jan-07 11:23
James R. Twine30-Jan-07 11:23 
GeneralRe: disappearing check boxes Pin
maladuk30-Jan-07 23:31
maladuk30-Jan-07 23:31 
AnswerRe: disappearing check boxes Pin
PJ Arends30-Jan-07 15:51
professionalPJ Arends30-Jan-07 15:51 
GeneralRe: disappearing check boxes Pin
maladuk30-Jan-07 22:40
maladuk30-Jan-07 22:40 
QuestionRe: disappearing check boxes Pin
prasad_som30-Jan-07 17:19
prasad_som30-Jan-07 17:19 
AnswerRe: disappearing check boxes -code Pin
maladuk30-Jan-07 22:06
maladuk30-Jan-07 22:06 
Below is the essential code of the dialog and the checkbox class. Hope it helps. Thanks a lot for your assistance so far.

maladuk

dialog class header:
class ShowResultDlg : public CDialog{
//{{AFX_DATA(ShowResultDlg)
CColorCheck m_chk_tmax;
//}}AFX_DATA
protected:
//{{AFX_MSG(ShowResultDlg)
afx_msg void OnChkTmax();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};

dialog class source:
void ShowResultDlg::DoDataExchange(CDataExchange* pDX){
//{{AFX_DATA_MAP(ShowResultDlg)
DDX_Control(pDX, IDC_CHK_TMAX,m_chk_tmax);
//}}AFX_DATA_MAP
}

void ShowResultDlg::OnChkTmax(){
if(m_chk.GetCheck()) m_chk_tmax.SetCheck(FALSE);
else m_chk_tmax.SetCheck(TRUE);
}

BOOL ShowResultDlg::OnInitDialog() {
CDialog::OnInitDialog();
m_chk_tmax.SetArrowColor(RGB(255,0,0);
return TRUE; // return TRUE unless you set the focus to a control
}

void ShowResultDlg::OnPaint(){
CPaintDC dc(this); // device context for painting
}



ColorCheckBox class header
(from: www.codeguru.com/Cpp/controls/controls/checkboxcontrols/article.php/c5319/)
class CColorCheck : public CButton{
DECLARE_DYNAMIC(CColorCheck)
int rightstatus;
public:
CColorCheck();
virtual ~CColorCheck(){;}
virtual void SetCheck(int nCheck);
virtual int GetCheck();
COLORREF SetArrowColor(COLORREF newColor);
int RightStatus() {return rightstatus;}
void RightStatus(int status) {rightstatus=status;}
public:
BOOL checkFlag,drawFocus;
UINT oldAction,oldState;
COLORREF newColor, newArrowColor, newTextColor;
protected:
void DrawCheckCaption(CDC *pDC, CRect R, const char *Buf, COLORREF TextColor);
virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItem);//overrides WM_DRAWITEM !!!
COLORREF GetDisabledColor() { return disabled; }
//{{AFX_MSG(CColorCheck)
afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
//}}AFX_MSG
private:
DECLARE_MESSAGE_MAP()
};

ColorCheckBox class source:
IMPLEMENT_DYNAMIC(CColorCheck, CButton)

CColorCheck::CColorCheck(){
....
rightstatus = 0;
}

BEGIN_MESSAGE_MAP(CColorCheck, CButton)
//{{AFX_MSG_MAP(CColorCheck)
ON_WM_RBUTTONDOWN()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

void CColorCheck::OnRButtonDown(UINT nFlags, CPoint point) {
if(rightstatus) rightstatus = 0;
else rightstatus = 1;
SetArrowColor(RGB((1-rightstatus)*255,0,rightstatus*255)); //red if leftclicked, blue if rightclicked
}

void CColorCheck::SetCheck(int nCheck){
if (nCheck == 1) checkFlag = 1;
else checkFlag = 0;
}

BOOL CColorCheck::GetCheck(){
if (checkFlag == 1) return 1;
else return 0;
}

COLORREF CColorCheck::SetArrowColor(COLORREF arrowColor){
newArrowColor = arrowColor;
return newArrowColor;
}

void CColorCheck::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct){
CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
CRect rc;
CRect rect(13,1,11,11);
CRect focusRect, btnRect;
focusRect.CopyRect(&lpDrawItemStruct->rcItem);
disabled = RGB(100,100,100); // dark gray disabled text
CSize captionSize;


// Retrieve the button's caption
//
const int bufSize = 512;
TCHAR buffer[bufSize];
GetWindowText(buffer, bufSize);

//
// Set the Text Position more to the left
//
captionSize = pDC->GetTextExtent(buffer, strlen(buffer));
btnRect.SetRect(16,1,16 + captionSize.cx + 4,15);

//
// Set the focus rectangle to just past the border decoration
//
focusRect.SetRect(18,1,16 + captionSize.cx +8, 15);

//Get control's ID
int id = GetDlgCtrlID();

UINT state = lpDrawItemStruct->itemState;
UINT action = lpDrawItemStruct->itemAction;

// Don't redraw whole control if only focus has changed
if (action == ODA_FOCUS)
drawFocus = TRUE;

if (!drawFocus)
{
//Start drawing the check box
CPen normRect(PS_SOLID, 1,NULL_PEN);
CPen* m_normRect = pDC->SelectObject(&normRect);

pDC->SelectStockObject(NULL_BRUSH);

//draw the caption
pDC->DrawText(buffer, strlen(buffer), btnRect, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
DrawCheckCaption(pDC, btnRect, buffer, newTextColor);

//draw the check rectangle
pDC->FillSolidRect(2,2,11,11,newColor);
normRect.DeleteObject();

//draw the borders
CPen normRect1(PS_SOLID, 1,RGB(80,80,80));
CPen* m_normRect1 = pDC->SelectObject(&normRect1);

CPoint startPt = pDC->MoveTo(1,13);

pDC->LineTo(1,1);
pDC->LineTo(13,1);
normRect1.DeleteObject(); //release

CPen normRect2(PS_SOLID, 1,RGB(100,100,100));
CPen* m_normRect2 = pDC->SelectObject(&normRect2);

CPoint startPt1 = pDC->MoveTo(0,14);

pDC->LineTo(0,0);
pDC->LineTo(14,0);
normRect2.DeleteObject(); //release

CPen normRect3(PS_SOLID, 1,RGB(255,255,255));
CPen* m_normRect3 = pDC->SelectObject(&normRect3);

CPoint startPt2 = pDC->MoveTo(14,0);

pDC->LineTo(14,14);
pDC->LineTo(0,14);
normRect3.DeleteObject(); //release

CPen normRect4(PS_SOLID, 1,RGB(180,180,180));
CPen* m_normRect4 = pDC->SelectObject(&normRect4);

CPoint startPt3 = pDC->MoveTo(13,1);

pDC->LineTo(13,13);
pDC->LineTo(13,1);
normRect4.DeleteObject(); //release

if (checkFlag == 1)
{
pDC->FillSolidRect(2,2,11,11,newColor);

// draw the arrow
CPen normRect5(PS_SOLID, 1, newArrowColor);//BLACK_PEN);
CPen* m_normRect5 = pDC->SelectObject(&normRect5);

CPoint startPt2 = pDC->MoveTo(4,7);

pDC->LineTo(7,11);
pDC->LineTo(10,3);

CPoint startPt3 = pDC->MoveTo(4,8);

pDC->LineTo(7,9);
pDC->LineTo(9,4);
normRect5.DeleteObject(); //release
}

}

//draw "checked" - arrow depending on state

if (action & ODA_SELECT && checkFlag == 1)

pDC->FillSolidRect(2,2,11,11,newColor);

else if (action & ODA_SELECT && checkFlag == 0)
{

pDC->FillSolidRect(2,2,11,11,newColor);

// draw the arrow
CPen normRect5(PS_SOLID, 1, newArrowColor);//BLACK_PEN);
CPen* m_normRect5 = pDC->SelectObject(&normRect5);

CPoint startPt2 = pDC->MoveTo(4,7);

pDC->LineTo(7,11);
pDC->LineTo(10,3);

CPoint startPt3 = pDC->MoveTo(4,8);

pDC->LineTo(7,9);
pDC->LineTo(9,4);
normRect5.DeleteObject(); //release
}

if( ( state & ODS_FOCUS ) ^ ( oldState & ODS_FOCUS ) ||( !drawFocus && ( state & ODS_FOCUS ) ) )

DrawFocusRect(lpDrawItemStruct->hDC, (LPRECT)&focusRect);

else if (state & ODS_DISABLED)
{
pDC->FillSolidRect(2,2,11,12,RGB(192,192,192)); //grayed
DrawCheckCaption(pDC, btnRect, buffer, GetDisabledColor());
}

oldState = state;
oldAction = action;
}

void CColorCheck::DrawCheckCaption(CDC *pDC, CRect R, const char *Buf, COLORREF TextColor)
{
COLORREF prevColor = pDC->SetTextColor(TextColor);
pDC->SetBkMode(TRANSPARENT);
pDC->DrawText(Buf, strlen(Buf), R, DT_CENTER|DT_VCENTER|DT_SINGLELINE);
pDC->SetTextColor(prevColor);
}


maladuk
QuestionRe: disappearing check boxes -code Pin
prasad_som30-Jan-07 22:31
prasad_som30-Jan-07 22:31 
AnswerRe: disappearing check boxes -code Pin
maladuk30-Jan-07 22:42
maladuk30-Jan-07 22:42 
AnswerRe: disappearing check boxes -code Pin
prasad_som30-Jan-07 23:07
prasad_som30-Jan-07 23:07 
GeneralRe: disappearing check boxes -code Pin
maladuk30-Jan-07 23:13
maladuk30-Jan-07 23:13 
AnswerRe: disappearing check boxes -code Pin
prasad_som30-Jan-07 23:28
prasad_som30-Jan-07 23:28 
GeneralRe: disappearing check boxes -code Pin
maladuk30-Jan-07 23:39
maladuk30-Jan-07 23:39 
GeneralProblem solved ! Pin
maladuk31-Jan-07 3:57
maladuk31-Jan-07 3:57 
AnswerRe: disappearing check boxes Pin
Hamid_RT30-Jan-07 18:05
Hamid_RT30-Jan-07 18:05 
GeneralRe: disappearing check boxes Pin
maladuk30-Jan-07 23:15
maladuk30-Jan-07 23:15 
QuestionIs it Possible to monitor Actions Taken by a Third Party Software? Pin
Khoramdin30-Jan-07 11:03
Khoramdin30-Jan-07 11:03 
AnswerRe: Is it Possible to monitor Actions Taken by a Third Party Software? Pin
James R. Twine30-Jan-07 11:16
James R. Twine30-Jan-07 11:16 
AnswerRe: Is it Possible to monitor Actions Taken by a Third Party Software? Pin
benjymous30-Jan-07 21:49
benjymous30-Jan-07 21:49 
Questionmulti-thread question, perhaps Pin
goodoljosh198030-Jan-07 7:56
goodoljosh198030-Jan-07 7:56 
AnswerRe: multi-thread question, perhaps Pin
James R. Twine30-Jan-07 8:13
James R. Twine30-Jan-07 8:13 
GeneralRe: multi-thread question, perhaps Pin
goodoljosh198030-Jan-07 8:16
goodoljosh198030-Jan-07 8:16 
GeneralRe: multi-thread question, perhaps Pin
James R. Twine30-Jan-07 8:23
James R. Twine30-Jan-07 8:23 
GeneralRe: multi-thread question, perhaps Pin
goodoljosh198030-Jan-07 8:30
goodoljosh198030-Jan-07 8:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.