RGB Preview Dialog

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;
  pStatic->UpdateWindow();
  pStatic->Invalidate();
    
  CDialog::OnVScroll(nSBCode, nPos, pScrollBar);
}

// PaintST.cpp : implementation file
//

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

  CBrush  brBack(m_crBkColor);
  dc.FillRect(rcStatic, &brBack);
  pOldBrush = dc.SelectObject(&brBack);
  dc.SelectObject(pOldBrush);
  
    
  // 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]);

  GetClientRect(rcStatic);
  brBackgnd.CreateSolidBrush(m_crBkColor);
  pDC->FillRect(rcStatic, &brBackgnd);
  
  return CStatic::OnEraseBkgnd(pDC);
}

Downloads

Download demo project - 40 Kb


Comments

  • Please.. please..

    Posted by Hakan Bulut on 06/24/2013 05:02am

    Please, remove this article.. and close this ass door.

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

    Posted by Hakan Bulut on 01/12/2008 04:49pm

    When these codes write would be curious about?

    • Please

      Posted by Hakan BULUT on 06/24/2013 02:10am

      Please close this door.

      Reply
    Reply
  • Use Wm_CtlColor

    Posted by Legacy on 05/15/2002 12: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;
    m_stcBox.GetClientRect(rcStatic);

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

    }
    return hbr;
    }

    • Good idea..

      Posted by Hakan Bulut on 01/12/2008 04:07pm

      Very good.

      Reply
    Reply
  • heh...

    Posted by Legacy on 04/21/2002 12: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
    -O

    • So you say

      Posted by Hakan Bulut on 01/12/2008 04:10pm

      You may say as you wanted.

      Reply
    Reply
  • You've missed the point...

    Posted by Legacy on 03/09/2002 12: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 10:30am

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

      Reply
    • Thank you

      Posted by Hakan Bulut on 01/12/2008 04:13pm

      Thanks for carriage. It works very fast.

      Reply
    Reply
  • Thanks...

    Posted by Legacy on 03/08/2002 12: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

    Reply
  • Thanks..

    Posted by Legacy on 03/07/2002 12: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 10:47am

      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.

      Reply
    • I wont reguest from you feeling shame!.

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

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

      Reply
    • Anyway

      Posted by Hakan Bulut on 01/12/2008 04:44pm

      All posts are looks like a game piece.

      Reply
    • I have been coming more.

      Posted by Hakan Bulut on 01/12/2008 04:40pm

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

      Reply
    • Yes

      Posted by Hakan Bulut on 01/12/2008 04:31pm

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

      Reply
    • Yes so.

      Posted by Hakan Bulut on 01/12/2008 04:27pm

      You are right. I think so too alltime.

      Reply
    • Sorry pal

      Posted by Hakan Bulut on 01/12/2008 04:24pm

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

      Reply
    • LOL?

      Posted by Hakan Bulut on 01/12/2008 04:21pm

      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.

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

    Posted by Legacy on 03/06/2002 12: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.

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

Top White Papers and Webcasts

  • Live Event Date: September 10, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Modern mobile applications connect systems-of-engagement (mobile apps) with systems-of-record (traditional IT) to deliver new and innovative business value. But the lifecycle for development of mobile apps is also new and different. Emerging trends in mobile development call for faster delivery of incremental features, coupled with feedback from the users of the app "in the wild". This loop of continuous delivery and continuous feedback is …

  • This ESG study by Mark Peters evaluated a common industry-standard disk VTl deduplication system (with 15:1 reduction ratio) versus a tape library with LTO-5, drives with full nightly backups, over a five-year period.  The scenarios included replicated systems and offsite tape vaults.  In all circumstances, the TCO for VTL with deduplication ranged from about 2 to 4 times more expensive than the LTO-5 tape library TCO. The paper shares recent ESG research and lots more. 

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds