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. Another transparent question

Another transparent question

Scheduled Pinned Locked Moved C / C++ / MFC
questioncsharpvisual-studio
3 Posts 3 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.
  • Z Offline
    Z Offline
    Zizilamoroso
    wrote on last edited by
    #1

    This one is probably asked before, I saw some solutions but none of them seem to work. How do you make a text static transparent? I've got this: CStatic m_ctrlLabel; m_ctrlLabel.Create(_T("TEST"), WS_VISIBLE|WS_CHILD, CRect(0,0,32,16), pParent, 0); m_ctrlLabel.ModifyStyleEx(0,WS_EX_TRANSPARENT); But this doesn't work. Did I forget something? btw. I'm not planning to subclass the control.


    using: [VISUAL STUDIO 6.0 sp5] [WIN98/2]
    V B 2 Replies Last reply
    0
    • Z Zizilamoroso

      This one is probably asked before, I saw some solutions but none of them seem to work. How do you make a text static transparent? I've got this: CStatic m_ctrlLabel; m_ctrlLabel.Create(_T("TEST"), WS_VISIBLE|WS_CHILD, CRect(0,0,32,16), pParent, 0); m_ctrlLabel.ModifyStyleEx(0,WS_EX_TRANSPARENT); But this doesn't work. Did I forget something? btw. I'm not planning to subclass the control.


      using: [VISUAL STUDIO 6.0 sp5] [WIN98/2]
      V Offline
      V Offline
      Valera241176
      wrote on last edited by
      #2

      Control with WS_EX_TRANSPARENT has the background of its parent. You probably put static control on i.e tab control which lies on dialog. But the parent of static control is still this dialog. To correct such situation override CDialog::OnCtlColor. Type ON_WM_CTLCOLOR() in MESSAGE_MAP. Then change the background color of your static control as you wish (i.e set it as those tab control): HBRUSH CTTSDialog::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); if (nCtlColor == CTLCOLOR_STATIC && pWnd->GetDlgCtrlID() != IDC_DEFAULT_CHECK) { CWnd *TabCtrl = GetDlgItem(IDC_LANG_TAB); CWnd *Ctrl = GetDlgItem(pWnd->GetDlgCtrlID()); if (Ctrl) { CRect Rect; Ctrl->GetWindowRect(&Rect); TabCtrl->ScreenToClient(&Rect); COLORREF Clr = TabCtrl->GetDC()->GetPixel(Rect.left-1, Rect.top-1); DeleteObject(hbr); hbr = CreateSolidBrush(Clr); pDC->SetBkColor(Clr); } } return hbr; }

      1 Reply Last reply
      0
      • Z Zizilamoroso

        This one is probably asked before, I saw some solutions but none of them seem to work. How do you make a text static transparent? I've got this: CStatic m_ctrlLabel; m_ctrlLabel.Create(_T("TEST"), WS_VISIBLE|WS_CHILD, CRect(0,0,32,16), pParent, 0); m_ctrlLabel.ModifyStyleEx(0,WS_EX_TRANSPARENT); But this doesn't work. Did I forget something? btw. I'm not planning to subclass the control.


        using: [VISUAL STUDIO 6.0 sp5] [WIN98/2]
        B Offline
        B Offline
        Brian Shifrin
        wrote on last edited by
        #3

        MSDN: WS_EX_TRANSPARENT Specifies that a window created with this style is to be transparent. That is, any windows that are beneath the window are not obscured by the window. A window created with this style receives WM_PAINT messages only after all sibling windows beneath it have been updated. In other words all WS_EX_TRANSPARENT does is changes the way WM_PAINT is sent. To make static transparent You need to override OnCtlColor and set correct dc mode.HBRUSH CMyFormView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { if (m_nWhich==ID_MY_STATIC ) { pDC->SetBkMode(TRANSPARENT); pDC->SetTextColor(GetSysColor(COLOR_WINDOWTEXT)); } }

        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