change background color

This is a discussion on change background color within the Windows Programming forums, part of the Platform Specific Boards category; I'm trying to change the background color of a static control (text). I know that this can be normally done ...

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    53

    Question change background color

    I'm trying to change the background color of a static control (text). I know that this can be normally done by the message WM_CTLCOLORSTATIC, however, the control i'm talking about is the child of another static control (because i'm using tabs), so there is no way i can check WM_CTLCOLORSTATIC. How can i achieve this?

    Thanks in advance...

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    That's how you get boxed in when using tabs...

    Rather than doing "child of child" you should probably investigate making borderless child dialogs that fit in your tab control's client area. Show/hide the entire dialog according to the selected tab... This gives you separate message procedures for each dialog (hense, each tab) where you can do a lot more customization than by the more conventional methods.

    Code:
    //////////////////////////////////////////////////////////////////////////////
    // Tab message handlers
    //
    
    BOOL CALLBACK TabTosser(HWND Dlg,UINT Msg,WPARAM wParm,LPARAM lParm)
      { switch(Msg)
          { case WM_INITDIALOG :
              EnableThemeDialogTexture(Dlg,ETDT_USETABTEXTURE);
              return TRUE;
            case WM_COMMAND :
              switch (LOWORD(wParm))
                { case 4002 :
                    GetFolderName(Dlg,4001);
                    return FALSE;
                  case 4003 :
                    RemoveFolderNames(Dlg,4001);
                    return FALSE;
                  case 4004 :
                    ClearFolderNames(Dlg,4001);
                    return FALSE;
                  case 4006 :
                    GetFolderName(Dlg,4005);
                    return FALSE;
                  case 4007 :
                    RemoveFolderNames(Dlg,4005);
                    return FALSE;
                  case 4008 :
                    ClearFolderNames(Dlg,4005);
                    return FALSE;
                  case 4103 :
                    GetFolderName(Dlg,4102);
                    return FALSE;
                  case 4104 :
                    RemoveFolderNames(Dlg,4102);
                    return FALSE;
                  case 4105 :
                    ClearFolderNames(Dlg,4102);
                    return FALSE;
                  case 4202 :
                    GetFolderName(Dlg,4201);  
                    return FALSE;
                  case 4203 :
                    RemoveFolderNames(Dlg,4201);
                    return FALSE;
                  case 4204 :
                    ClearFolderNames(Dlg,4201);
                    return FALSE;
                  case 4206 :
                    GetFolderName(Dlg,4205);
                    return FALSE;
                  case 4207 :
                    RemoveFolderNames(Dlg,4205);
                    return FALSE;
                  case 4208 :
                    ClearFolderNames(Dlg,4205);
                    return FALSE;
                  case 4302 :
                    GetFileName(Dlg,4301,_T("Help File (*.chm)\0*.chm\0\0")); 
                    return FALSE;
                 default :
                    return FALSE; }
            default :
              return FALSE; } }
    
    
    //////////////////////////////////////////////////////////////////////////////
    // Main Dialog functions
    //
    
    // switch tab out
    VOID HideTab(HWND Ctrl )
      { ShowWindow(hPage[TabCtrl_GetCurSel(Ctrl)],SW_HIDE); }
    
    
    
    // switch tab in
    VOID ShowTab(HWND Ctrl )
      { ShowWindow(hPage[TabCtrl_GetCurSel(Ctrl)],SW_SHOW); }
    
    
    
    // initialize tabs and sub-dialogs
    BOOL InitSetup(HWND Dlg)
      { TCITEM tci;    //tab struct
        TCHAR tab[16]; // tab text
        hTabCtrl = GetDlgItem(Dlg,4901); // page global handle
        // add tabs to main dialog
        tci.mask = TCIF_TEXT; 
        tci.cchTextMax = 16;
        tci.pszText = tab;
        lstrcpy(tab, _T("Executables"));
        TabCtrl_InsertItem(GetDlgItem(Dlg,4901),0,&tci);
        lstrcpy(tab, _T("Compiler"));
        TabCtrl_InsertItem(GetDlgItem(Dlg,4901),1,&tci);
        lstrcpy(tab, _T("Linker"));
        TabCtrl_InsertItem(GetDlgItem(Dlg,4901),2,&tci);
        lstrcpy(tab, _T("Help"));
        TabCtrl_InsertItem(GetDlgItem(Dlg,4901),3,&tci);
        TabCtrl_SetCurSel(Dlg,0);
        // create tab dialogs
        hPage[0] = CreateDialog(hInst,_T("SETUP0"),Dlg,(DLGPROC)&TabTosser); 
        hPage[1] = CreateDialog(hInst,_T("SETUP1"),Dlg,(DLGPROC)&TabTosser); 
        hPage[2] = CreateDialog(hInst,_T("SETUP2"),Dlg,(DLGPROC)&TabTosser); 
        hPage[3] = CreateDialog(hInst,_T("SETUP3"),Dlg,(DLGPROC)&TabTosser);     
        // get settings from registry
        LoadSettings();
        return TRUE; }
    
    
    
    // tosser for the main setup dialog
    BOOL CALLBACK SetupTosser(HWND Dlg,UINT Msg,WPARAM wParm,LPARAM lParm)
      { switch(Msg)
          { case WM_INITDIALOG :
              InitSetup(Dlg);
              return TRUE;
            case WM_COMMAND :
              switch(LOWORD(wParm))   
                { case IDOK :          // save button
                    SaveSettings();
                    EndDialog(Dlg,1);
                    return FALSE;
                  case IDCANCEL :      // cancel button
                    EndDialog(Dlg,0);
                    return FALSE;
                  default :
                    return FALSE; }
            case WM_NOTIFY :          // from tab control
              switch(wParm)
                { case 4901 :
                    switch ( ((LPNMHDR) lParm)->code)
                      { case TCN_SELCHANGING :  // hide old dialog
                          HideTab(((LPNMHDR) lParm)->hwndFrom); 
                          return FALSE;
                        case TCN_SELCHANGE :   // show new dialog
                          ShowTab(((LPNMHDR) lParm)->hwndFrom);
                          return FALSE;
                        default :
                          return FALSE; }
                  default :
                    return FALSE; }
            default :
              return FALSE; } }  
    
    
    
    void ShowGlobalSetup(HWND Parent)
      { DialogBox(hInst,_T("SETUP"),Parent,(DLGPROC) &SetupTosser); }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Unable to change the windows background color
    By Hawkin in forum Windows Programming
    Replies: 3
    Last Post: 12-29-2007, 01:31 AM
  2. how to change background color in console mode
    By smore in forum C++ Programming
    Replies: 1
    Last Post: 12-02-2003, 01:44 PM
  3. How do I change background color?
    By kinghajj in forum Windows Programming
    Replies: 16
    Last Post: 11-10-2003, 02:20 AM
  4. Can I change background color
    By Bryan in forum C++ Programming
    Replies: 2
    Last Post: 10-25-2002, 01:14 PM
  5. CEditView Background Color & Font Color :: MFC
    By kuphryn in forum Windows Programming
    Replies: 5
    Last Post: 05-30-2002, 10:44 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21