Solved

Changing the color of dialog box in Tab Ctrl

Posted on 1997-07-15
2
463 Views
Last Modified: 2013-11-20
I am creating a tab ctrl inside a scroll view. I am attaching dialog boxes with different tabs in tab ctrl. I want to have different colors for different scroll views (same color for all dialog boxes in one scroll view). I have  tried following options :
1. catch OnEraseBkgnd in my scroll view.
   When I run the program, I get a flickering of the color specified, and then color changes to standard dialog color.
2. catch OnEraseBkgnd in my scroll view.
   It changes the color only for the dialog area (that is fixed). Remaining area on the view is still in standard dialog color.

Any suggestion on this,
Thanks
Pankaj
0
Comment
Question by:pankaj012797
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 4

Accepted Solution

by:
mbhakta earned 100 total points
ID: 1302579
Your question is not very clear as to what you are trying to achieve. But from what you are using to paint the dialog box , you should try OnPaint() inside this function try FillRect() for the client area of that dialog you are trying to change the colour for. If this explaination is not enough to get you going come back with some code.
0
 

Author Comment

by:pankaj012797
ID: 1302580
Hi,
I am putting the code.

// A class derived from CView
int CTabView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
      if (CView::OnCreate(lpCreateStruct) == -1)
            return -1;
// Create a tab control which is a child window of the CTabView // and whose size will be determined in CTabView::OnSize().
      m_TabCtrl = new CTabCtrl;
      ASSERT(m_TabCtrl);
      if (m_TabCtrl->Create(
            WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS,
            CRect(0, 0, 0, 0), this, ID_TABCTRL) == FALSE)
            return -1;
      // Create all pages for the tab control.
      CreatePages();
      return 0;
}

// --------------------------------------------------------------------------
// CTabView::OnSize
//      
// Size the tab control window (CTabCtrl) so it fits the entire // client area of this view window (CTabView).
// --------------------------------------------------------------------------
void CTabView::OnSize(UINT nType, int cx, int cy)
{
      CView::OnSize(nType, cx, cy);

      m_TabCtrl->MoveWindow(0, 0, cx, cy);
}

// --------------------------------------------------------------------------
// CTabView::OnSetFocus
//      
// The view window will get the input focus when the application is first
// running.  It is a good place to show the first page (dialog box)
// by calling OnTabSelChange() function.
// --------------------------------------------------------------------------
void CTabView::OnSetFocus(CWnd* pOldWnd)
{
      CView::OnSetFocus(pOldWnd);

      OnTabSelChange(NULL, NULL);
}

// --------------------------------------------------------------------------
// CTabView::OnTabSelChanging
//      
// This function will hide the currently visible page in the tab // control (CTabCtrl) so the newly selected page can be shown in // OnTabSelChange().
//
void CTabView::OnTabSelChanging(NMHDR* pnmhdr, LRESULT* pResult)
{
// Call GetCurSel() here will return the index of the page that
// will be hidden soon.  This is NOT the newly selected page when
// OnTabSelChange() is called.
      int sel_index = m_TabCtrl->GetCurSel();
      m_DlgArray[sel_index]->ShowWindow(SW_HIDE);
      *pResult = FALSE;
}

// CTabView::OnTabSelChange
//      
// This function will show the newly selected page in the tab //control.  The page will be sized to the display rectangle of // the tab control.
void CTabView::OnTabSelChange(NMHDR* pnmhdr, LRESULT* pResult)
{
// Get rectangle size of the tab control so we know the position
// and size of the page that will be shown.
      RECT rc;
      m_TabCtrl->GetItemRect (0, &rc);

// Call GetCurSel() will return the index of the page that is //newly selected.  This page will be visible soon.
      int sel_index = m_TabCtrl->GetCurSel();
      m_DlgArray[sel_index]->SetWindowPos (
            NULL,
            rc.left + 5, rc.bottom + 5, 0, 0,
            SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW);
      
      // Set input focus to this page.
      m_DlgArray[sel_index]->SetFocus();
}      




// --------------------------------------------------------------------------
// CTabView::CreatePages
//      
// This function creates all pages for the tab control //(CTabCtrl).  The tab text is retrieved from the dialog // template.
// All the created pages will be added to the m_DlgArray so we //know which one to show and hide when a particular tab is // selected.  Pages will be shown
// in the left-to-right order when they are added to the tab //control.  The C++ page objects which are added to the //m_DlgArray will be destroyed in the destructor function of this // view window.
// --------------------------------------------------------------------------
#define       NUM_PAGES 2
void CTabView::CreatePages()
{
      CDialog*      dlg;
      // Create page one and add it to dialog array.
      dlg = new CDialog1;
      ASSERT(dlg);
      m_DlgArray.Add(dlg);
      VERIFY(dlg->Create(IDD_DIALOG1, m_TabCtrl));

      // Create page two and add it to dialog array.
      dlg = new CDialog2;
      ASSERT(dlg);
      m_DlgArray.Add(dlg);
      VERIFY(dlg->Create(IDD_DIALOG2, m_TabCtrl));
// Determine the tab text.  The tab text can be found from the
      // dialog template.
      char str[50];
      TC_ITEM tci;
      tci.mask      = TCIF_TEXT;
      tci.iImage      = -1;
      for (int i = 0; i < NUM_PAGES; i++)
      {      
// Get the caption from dialog template and insert this caption
            // to the tab control.
            dlg = m_DlgArray[i];
            dlg->GetWindowText(str, sizeof(str));
            tci.pszText      = str;
            m_TabCtrl->InsertItem(i, &tci);

// Remove caption from  dialog box because no caption is allowed
            // for pages in the tab control.
            dlg->ModifyStyle(WS_CAPTION, 0);

            dlg->SendMessage(WM_NCACTIVATE, TRUE);
      }
}

// This is the code where I am trying to change the background // color of the view, but I am not successful. Same thing I tried  // in OnEraseBkgnd of dialog box. At that time, it changes the // color of dialog box , not of the complete view
BOOL CTabView::OnEraseBkgnd(CDC* pDC)
{
      CBrush *pOldBrush  = pDC->GetCurrentBrush();
      CBrush newBrush(RGB(255,0,0));
      //pDC->SelectObject(&newBrush);
      CRect rect;
      GetClientRect(&rect);
      pDC->FillRect(rect,&newBrush);
      return 1;
}

I hope, it might help in understanding the problem. Please let me know, if need more clarification.

Thanks for all the help,
Pankaj

0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Whole sheet autoscrub still needed 19 53
Hibernate methods 2 83
sum67 challenge 35 116
Is there a simple front-end menu system. 9 118
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question