SHARE
Facebook X Pinterest WhatsApp

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 = […]

Written By
thumbnail
CodeGuru Staff
CodeGuru Staff
Mar 6, 2002
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

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

Recommended for you...

How To Make Windows 11 Faster
Enrique Stone
Nov 30, 2022
Working with the Windows Registry in C#
Joydip Kanjilal
Jun 17, 2022
Using Multiple Programming Languages to Create an ASP.NET Website
Tariq Siddiqui
Jun 11, 2022
Finding a Microsoft Office version with .NET
Hannes DuPreez
May 20, 2022
CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2025 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.