• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1092
  • Last Modified:

Transparent RICHEDIT

How do you make the background of a RICHEDIT control transparent? They've done it again. All the old methods, like making an EDIT control's background transparent, don't work. It's all different. Any suggestions?
0
tfrazier
Asked:
tfrazier
  • 5
  • 2
  • 2
  • +1
1 Solution
 
mnguyen021997Commented:
try trapping the WM_CTLCOLOREDIT message and returning the GetStockObject(NULL_BRUSH).  you will also need to re-rendering the individual strings while the user is deleting them.
0
 
tfrazierAuthor Commented:
Like I said, it's all different. The richedit control DOES NOT send WM_CTLCOLOREDIT to its parent (or any message like it). The old methods don't work. This is a new beast.
0
 
galkinCommented:
Try to add WM_EX_TRANSPARENT extended style to control window. Also handle WM_ERASEBKGND and simply return TRUE.
0
[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

 
tfrazierAuthor Commented:
Sorry, but no dice. The WM_ERASEBKGND message has been handy for things like this in the past, but not here. The
WM_EX_TRANSPARENT style is not intended for things like this and thus has no effect. Thanks for trying though. I'm beginning to think this can't be done. Somebody prove me wrong.
0
 
mnguyen021997Commented:
a quick scan of mfc wizard allows you to trap the WM_CTLCOLOR message from rich edit control types.  it's not a notification message like EN_XXX thus the parent won't get it.  the richedit should be getting that message to itself, so try subclassing it and trap for that message.
0
 
tfrazierAuthor Commented:
mnguyen, You are correct in that the class wizard allows you to put in a method to trap the WM_CTLCOLOR message, but this message is in fact never sent. I confirmed this with spy a few days ago. Thus the method is useless. The class that most closely wraps the actual RICHEDIT control, CRichEditCtrl does not include this ability to trap (of course, the message is never sent). I appreciate your help though and if you have any other ideas, please submit.


0
 
anichiniCommented:
While I think it may be impossible to have RichEdit be transparent while editing, it is possible to have it draw to a window transparently.

I implemented this a while back when I was writing a page layout program. The basic idea is to create the RichEdit control hidden as a child of your window. Then in your window's OnPaint, draw the RichEdit control in its position by using the EM_FORMATRANGE and passing it the HDC of your window. It gets tricky, though, since RichEdit is in TWIPS and you have to do a bunch of messy coordinate space/mapping mode gunk. The result is the RichEdit control draws its content to the window and you can do it in a way that is transparent. Then when the user wants to edit you show the richedit control and you get all the editing functions.

If this meets your needs I can paste the MFC code (converting it to pure Win32 shouldn't be too bad). If you have to have it transparent while editing, I think you may be out of luck.

0
 
tfrazierAuthor Commented:
I have tried your method and IT WORKS. Thank you. The mapping is a little messy but not to bad. This does solve over half our problem as displaying is absolutely necessary and editing would be a great convenience (and our customers will certainly want it). It may be possible to use your method while editing but it would be even more tricky and you'd have to handle the I beam yourself, plus I'm sure other details. Anyway, I have a workaround for now and will implement with your method. But I'm still going to search for a more general solution. Once again, thank you very much for the insight !!!
0
 
anichiniCommented:
you are welcome... answer is above

0
 
tfrazierAuthor Commented:
Thanks again.
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 5
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now