15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


Drawing on CEditView or CRichEditView

Seth Goldstein -- seth@mathworks.com
Tuesday, January 23, 1996

Hi folks,

I've been just about tearing out my hair over this one...

All I want to do is receive OnDraw (or even OnPaint)
calls so I can touch up a CEditView or CRichEditView with
my own little decorations.

Overriding OnDraw doesn't work (it never gets called,
because that's blocked by CCtrlView::OnPaint).  Overriding
OnPaint almost works, except I can't call C*EditView::OnPaint,
so only my stuff gets painted.

Is there a way to do this within MFC?  Am I missing something
obvious?  If not, any suggestions for doing it using Win32?

Thanks a million,
Seth
-- 
+------------------------------------------------------+
|   Seth Goldstein         email: seth@mathworks.com   |
|   The Mathworks, Inc.    http://www.mathworks.com    |
|                          info: info@mathworks.com    |
|------------------------------------------------------|
| PGP Public Key on server                             |
|   http://www-swiss.ai.mit.edu/~bal/pks-toplev.html   |
+------------------------------------------------------+



Mike Blaszczak -- mikeblas@msn.com
Friday, January 26, 1996

[Mini-digest: 2 responses]

Seth Goldstein wrote:
 > All I want to do is receive OnDraw (or even OnPaint)
 > calls so I can touch up a CEditView or CRichEditView with
 > my own little decorations.

The Red Hot Chili Peppers, in a Rolling Stone interview a few years ago, said 
that they were finally "popular enough to sell the kids dodads to sew on their 
underwear".  I'm happy to see that MFC is finally popular enough that people 
want to sew dodads on their edit controls.

> Is there a way to do this within MFC?  Am I missing something
> obvious?  If not, any suggestions for doing it using Win32?

You need to subclass the edit control that lives in the view.  To do that, you 
need to override the whole view class and override the Create() function.  So:

1) Create your own derivative of CEditView
2) Create your own derivative of CEdit
3) In CYourView::Create(), let MFC create the window then call 
SubclassDlgItem() to hook CYourEdit to the edit control created by MFC for the 
view
4) Override OnPaint() in CYourEdit and do whatever the heck you'd like.

.B ekiM
TCHAR szRHCP[] = _T("Out on my porch 'cause I lost my house key, pick up my 
book I read Bukowski.");
-----From: Chong Zhang 

On Tue, 23 Jan 1996, Seth Goldstein wrote:

> Hi folks,
> 
> I've been just about tearing out my hair over this one...
> 
> All I want to do is receive OnDraw (or even OnPaint)
> calls so I can touch up a CEditView or CRichEditView with
> my own little decorations.
> 
> Overriding OnDraw doesn't work (it never gets called,
> because that's blocked by CCtrlView::OnPaint).  Overriding
> OnPaint almost works, except I can't call C*EditView::OnPaint,
> so only my stuff gets painted.
> 
> Is there a way to do this within MFC?  Am I missing something
> obvious?  If not, any suggestions for doing it using Win32?

Can you call CCtrlView::OnDraw from your OnPaint? 

> 
> Thanks a million,
> Seth
> -- 

It may not be worth a million thanks :-)
> +------------------------------------------------------+
> |   Seth Goldstein         email: seth@mathworks.com   |
> |   The Mathworks, Inc.    http://www.mathworks.com    |
> |                          info: info@mathworks.com    |
> |------------------------------------------------------|
> | PGP Public Key on server                             |
> |   http://www-swiss.ai.mit.edu/~bal/pks-toplev.html   |
> +------------------------------------------------------+
> 



Seth Goldstein -- seth@mathworks.com
Monday, January 29, 1996

I've managed to get the result I've been looking for just by 
subclassing CRichEditView and overriding OnPaint.  By the way, I 
left out an important piece of information (:v)), that my 
scribblings only need to be in the margins, not on top of the 
text itself.

First, I had to call Default() inside of OnPaint 
(ahem...newbie alert).

The second problem was that when I did my drawing, the control 
stopped doing *its* drawing.  The cause was that the Class Wiz' 
default scaffolding declared a CPaintDC for me.  The constructor 
for CPaintDC called BeginPaint, which validated the update 
region.  Therefore, the output from calling Default() was 
clipped to nothing.

My solution was to use the CClientDC instead of the CPaintDC,
since my little scribblings are so inexpensive.

Hope I'm not pointing a cannon at myself...
Thanks for your help,
Seth

-- 
+------------------------------------------------------+
|   Seth Goldstein         email: seth@mathworks.com   |
|   The Mathworks, Inc.    http://www.mathworks.com    |
|                          info: info@mathworks.com    |
|------------------------------------------------------|
| PGP Public Key on server                             |
|   http://www-swiss.ai.mit.edu/~bal/pks-toplev.html   |
+------------------------------------------------------+




| Вернуться в корень Архива |