Academic Company Events Community Support Solutions Products & Services Contact NI MyNI
This Document is not yet Rated

Matching the Background Color of 3D Graph and Dialog

Primary Software:
Primary Software Version: 7.0
Primary Software Fixed Version: N/A
Secondary Software: N/A

Problem: I want my 3D graph to have the same background color as the dialog box, but when I use the Window Background system color, the colors do not match. How can I make the colors match?

Solution: The system colors in Visual C++ are not representative of the actual dialog colors. You can get the background color of the dialog box, but it involves handling the WM_CTLCOLOR message, so the code is somewhat difficult. The following steps outline an example solution:

  1. Declare a CNiColor member in your dialog box (in this example, cnicolor).  You need this member to pass the color from the message handler to the OnInitDialog function.

  2. Put the following statement in your OnInitDialog:
    where mygraph is a variable created from the 3D graph.

  3. Create a handler for the WM_CTCOLOR message on your dialog. You create the handler by clicking on the dialog box and bringing up the Messages list. Then find WM_CTCOLOR and select OnCtlColor from the drop-down list next to it.

  4. Use the following code for the function:
    HBRUSH Ctest2Dlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
    HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
    COLORREF color;
    color = GetBkColor(pDC->Detach());
    cnicolor = CNiColor(color);
    return hbr;

Related Links:


Report Date: 12/04/2003
Last Updated: 11/12/2004
Document ID: 343CC31P

Your Feedback! poor Poor  |  Excellent excellent   Yes No
 Document Quality? 
 Answered Your Question? 
  1 2 3 4 5
Please Contact NI for all product and support inquiries.submit