Virtual Developer Workshop: Containerized Development with Docker

This application shows a COLORREF structure that use Slider Control to determinates your 24-bit RGB color and shows also simple way to communicate between CSliderCtrl, CEdit, and CStatic.

void CRGBDlg::OnVScroll( UINT nSBCode, 
                         UINT nPos, 
                         CScrollBar* pScrollBar) 
  CSliderCtrl* pSlider = (CSliderCtrl*) pScrollBar;
  CString szColorValue;
  int i = pSlider->GetDlgCtrlID () - IDC_SLIDER1;

  // Now, nColor = current SliderPosValue
  nColor[i] = pSlider->GetPos();
  szColorValue.Format("%d", nColor[i]);

  SetDlgItemText(i + IDC_EDIT1, szColorValue);
  // Get a pointer to the static window.
  CStatic* pStatic = &m_ctlPaintStatic;
  CDialog::OnVScroll(nSBCode, nPos, pScrollBar);

// PaintST.cpp : implementation file

void CPaintST::OnPaint() 
  CPaintDC dc(this); // device context for painting
  CBrush*  pOldBrush;

  CBrush  brBack(m_crBkColor);
  dc.FillRect(rcStatic, &brBack);
  pOldBrush = dc.SelectObject(&brBack);
  // Do not call CStatic::OnPaint() for painting messages

BOOL CPaintST::OnEraseBkgnd(CDC* pDC) 
  CBrush  brBackgnd;

  // Get a pointer to the parent window
  CRGBDlg* pColorDlg = (CRGBDlg*) GetParent();
  ASSERT(pColorDlg != NULL);  

  // Get new color value from SliderCtrl.
  m_crBkColor = RGB ((BYTE) pColorDlg->nColor[0],
      (BYTE) pColorDlg->nColor[1],
      (BYTE) pColorDlg->nColor[2]);

  pDC->FillRect(rcStatic, &brBackgnd);
  return CStatic::OnEraseBkgnd(pDC);


Download demo project - 40 Kb


  • In what time? 2008? 2001? 2009? What the difference?

    Posted by Hakan Bulut on 01/13/2008 12:49am

    When these codes write would be curious about?

  • Use Wm_CtlColor

    Posted by Legacy on 05/15/2002 07:00am

    Originally posted by: Eric Schmidt

    I used OnCtlColor which was much easier than creating a static box class

    // CColorChooserDlg message handlers

    HBRUSH CColorChooserDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
    HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

    if (pWnd == GetDlgItem(IDC_STATIC_PAINT))
    CRect rcStatic;
    CDC *pDlgDc = m_stcBox.GetDC();
    CBrush* pOldBrush;

    CBrush brBack(RGB(m_nColors[0],m_nColors [1],m_nColors[2]));
    pDlgDc->FillRect(rcStatic, &brBack);
    pOldBrush = pDlgDc->SelectObject(&brBack);

    return hbr;

    • Good idea..

      Posted by Hakan Bulut on 01/13/2008 12:07am

      Very good.

  • heh...

    Posted by Legacy on 04/21/2002 07:00am

    Originally posted by: g.sharp

    it was so amusing to read everyone getting all serious about code like this... i just had to say something

    • So you say

      Posted by Hakan Bulut on 01/13/2008 12:10am

      You may say as you wanted.

  • You've missed the point...

    Posted by Legacy on 03/09/2002 08:00am

    Originally posted by: Ryan Binns

    How many times have you borrowed someone else's code and not had to modify it, even one tiny little bit??? I have used a fair amount of code from this site, and I have never had one bit of code that I didn't have to change to suit my application.

    This code is obviously not going to suit every situation, but it works perfectly for the situation it was designed for. If you make sure that the slider control IDs are defined consecutively, then there will be no problem at all.

    If you "criticisers" are not smart enough to work this out, then I suggest you take your comments elsewhere, rather than abusing someone who wants to share some of their code with other people.

    • The answer of this unrequired polemic.

      Posted by Hakan Bulut on 01/13/2008 06:30pm

      I'm 33 years old!. If you are just as allright?

    • Thank you

      Posted by Hakan Bulut on 01/13/2008 12:13am

      Thanks for carriage. It works very fast.

  • Thanks...

    Posted by Legacy on 03/08/2002 08:00am

    Originally posted by: Hakan

    Thanks to Andy because of this good comment. Thanks as well to Mr. Bruce. I know, this just the first day's homework of Visual C++ programming class. I didn't say "I am a professional". For Painter: Sorry pal but I think of this is fastest and simple the code way to control 3 slider controls, at the same time. I want to note something down:
    The important line of this function is this? (int i = pSlider->GetDlgCtrlID () - IDC_SLIDER1;)
    If you ask to this question that means you must obtain information about GetDlgCtrlID() Please take a look at the MSDN for "GetDlgCtrlID()"..
    By the way, the greatest thanks go to Mr. Rick Wallach who support me morally..
    Yours faithfully

  • Thanks..

    Posted by Legacy on 03/07/2002 08:00am

    Originally posted by: Anoop

    Sometimes some code is not submitted just to prove something, but to show how something can be done.

    • At first!

      Posted by Hakan Bulut on 01/13/2008 06:47pm

      We can be a people who have an idea of what is the people and a people is what mean that in the humanity history. We can be ask a question to ourselves in our minds, so could i be a people? Some take a look at the back whom are there in this world and whom are came to the world. I am so sorry that because of the putting up this bad things and the bad position in which completely oputside of the humanity.

    • I wont reguest from you feeling shame!.

      Posted by Hakan Bulut on 01/13/2008 06:35pm

      This is just to be brazen-faced!. If I am going to go to put something down!...

    • Anyway

      Posted by Hakan Bulut on 01/13/2008 12:44am

      All posts are looks like a game piece.

    • I have been coming more.

      Posted by Hakan Bulut on 01/13/2008 12:40am

      How much more can i come? To be rescued from this LOL position.

    • Yes

      Posted by Hakan Bulut on 01/13/2008 12:31am

      Because the Visual C++ Resource editor has been counted it automatically.

    • Yes so.

      Posted by Hakan Bulut on 01/13/2008 12:27am

      You are right. I think so too alltime.

    • Sorry pal

      Posted by Hakan Bulut on 01/13/2008 12:24am

      There is something in this life but no left choice to coming success. This was the one of that things.

    • LOL?

      Posted by Hakan Bulut on 01/13/2008 12:21am

      PLEASE, I WANT TO DRAW THE ATTENTION IN THAT DOT. I am not taking a clue if the life is to take only a clue. I can not take it anymore this is impossible.

  • Ahh...I'm sorry but what's the point of this code

    Posted by Legacy on 03/06/2002 08:00am

    Originally posted by: painter

    I'm sorry but this looks like the first day's homework of Visual C++ programming class...
    and this line -
    int i = pSlider->GetDlgCtrlID () - IDC_SLIDER1;

    has huge possibilities to produce bug.

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date