Dialog Control Transparent Property
-
Hi, I have changed the background colour of one of my dialogs by handling the WM_CTLCOLOR message. This works OK but the child controls are still painted using the original dialog background colour. I have set the transparent property of the child controls but this makes no difference. Is there something else I need to do? :doh: Thanks Tony
-
Hi, I have changed the background colour of one of my dialogs by handling the WM_CTLCOLOR message. This works OK but the child controls are still painted using the original dialog background colour. I have set the transparent property of the child controls but this makes no difference. Is there something else I need to do? :doh: Thanks Tony
What are your child controls? Static text? Typically you would need to override the WM_ERASEBKGND (OnEraseBkgnd in MFC) in the child controls to stop it painting the background or to copy the parent background (depending on what you are doing). Check out some of the transparent controls[^] in the articles section.
-
What are your child controls? Static text? Typically you would need to override the WM_ERASEBKGND (OnEraseBkgnd in MFC) in the child controls to stop it painting the background or to copy the parent background (depending on what you are doing). Check out some of the transparent controls[^] in the articles section.
My dialog contains a mixture of control types, including CStatic, CEdit etc. I have discovered that if I call pDC->SetBkMode(TRANSPARENT) in my dialog's OnCtlColor() handler then all of the child static controls have a transparent background - GREAT! - but unfortunately, so do my edit controls. So close but yet so far :sigh: I was hoping that I would be able to create a generic dialog class which would allow me to set the background colour without me having to fiddle with the child controls on an individual basis. :sigh:
-
My dialog contains a mixture of control types, including CStatic, CEdit etc. I have discovered that if I call pDC->SetBkMode(TRANSPARENT) in my dialog's OnCtlColor() handler then all of the child static controls have a transparent background - GREAT! - but unfortunately, so do my edit controls. So close but yet so far :sigh: I was hoping that I would be able to create a generic dialog class which would allow me to set the background colour without me having to fiddle with the child controls on an individual basis. :sigh:
Ok, great start. Check out the MSDN page[^] for OnCtlColor(). Notice the
nCtlColor
parameter? Only dopDC->SetBkMode(TRANSPARENT)
if it is equal to CTLCOLOR_STATIC and you should be set. EDIT: If you only want to set specific controls as transperent, rather than all controls of a type, check if pWnd is the instance you want to set instead. -
Ok, great start. Check out the MSDN page[^] for OnCtlColor(). Notice the
nCtlColor
parameter? Only dopDC->SetBkMode(TRANSPARENT)
if it is equal to CTLCOLOR_STATIC and you should be set. EDIT: If you only want to set specific controls as transperent, rather than all controls of a type, check if pWnd is the instance you want to set instead.Thanks Andrew - works a treat :thumbsup: :thumbsup: