Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. SetBkColor does not seem to work in OnInitDialog

SetBkColor does not seem to work in OnInitDialog

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    maxsteel
    wrote on last edited by
    #1

    hi, i have a dialog box with a static control. the problem is that when i try to use setbkcolor for the static control in oninitdialog of the dialog box, it does not produce any results. i have tried to use GetDC() for the static control to get the DC. and then tried to set the background color of the static control. can any one give me a solution? regards, kevin

    V A R 3 Replies Last reply
    0
    • M maxsteel

      hi, i have a dialog box with a static control. the problem is that when i try to use setbkcolor for the static control in oninitdialog of the dialog box, it does not produce any results. i have tried to use GetDC() for the static control to get the DC. and then tried to set the background color of the static control. can any one give me a solution? regards, kevin

      V Offline
      V Offline
      vcplusplus
      wrote on last edited by
      #2

      Look into using the WM_CTLCOLOR Message http://support.microsoft.com/default.aspx?scid=kb;en-us;32685

      M 1 Reply Last reply
      0
      • M maxsteel

        hi, i have a dialog box with a static control. the problem is that when i try to use setbkcolor for the static control in oninitdialog of the dialog box, it does not produce any results. i have tried to use GetDC() for the static control to get the DC. and then tried to set the background color of the static control. can any one give me a solution? regards, kevin

        A Offline
        A Offline
        Alexander Wiseman
        wrote on last edited by
        #3

        You could also take a look at this excellent article: http://www.codeproject.com/staticctrl/clabel.asp[^] Hope that helps! Sincerely, Alexander Wiseman Est melior esse quam videri It is better to be than to seem

        1 Reply Last reply
        0
        • M maxsteel

          hi, i have a dialog box with a static control. the problem is that when i try to use setbkcolor for the static control in oninitdialog of the dialog box, it does not produce any results. i have tried to use GetDC() for the static control to get the DC. and then tried to set the background color of the static control. can any one give me a solution? regards, kevin

          R Offline
          R Offline
          Ravi Bhavnani
          wrote on last edited by
          #4

          SetBkColor() should be used when handling a WM_PAINT message or within a control's DrawItem() override. Use it to set the background color of the DC for the duration of the painting action. /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com

          M 1 Reply Last reply
          0
          • V vcplusplus

            Look into using the WM_CTLCOLOR Message http://support.microsoft.com/default.aspx?scid=kb;en-us;32685

            M Offline
            M Offline
            maxsteel
            wrote on last edited by
            #5

            using WM_CTLCOLOR causes problems in other parts of my code. is there any other solution?

            V 1 Reply Last reply
            0
            • R Ravi Bhavnani

              SetBkColor() should be used when handling a WM_PAINT message or within a control's DrawItem() override. Use it to set the background color of the DC for the duration of the painting action. /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com

              M Offline
              M Offline
              maxsteel
              wrote on last edited by
              #6

              even if i use setbkcolor in WM_PAINT is does not do anything.

              1 Reply Last reply
              0
              • M maxsteel

                using WM_CTLCOLOR causes problems in other parts of my code. is there any other solution?

                V Offline
                V Offline
                vcplusplus
                wrote on last edited by
                #7

                It should not affect other parts of your code. Here is a sample of my code. HBRUSH CMyView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CFormView::OnCtlColor(pDC, pWnd, nCtlColor); INT nIDCtl = pWnd->GetDlgCtrlID(); switch(nIDCtl) { case IDC_STATIC_CTRL1: { // Change background color to white so that the // text is easier to read. pDC->SetBkColor(RGB(255, 255, 255)); CBrush br; br.CreateSolidBrush(RGB(255, 255, 255)); hbr = (HBRUSH)br; br.Detach(); } break; case IDC_STATIC_CTRL2: .... .... case IDC_STATIC_CTRL3: .... .... case IDC_STATIC_CTRL4: .... .... } return hbr; }

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups