I'd like examples or suggestions on creating an owner-drawn edit control. Functionally, I'd like it to be exactly the same, the only difference is I want my own "border" and "background". Simply a bitmap in the background (using BitBlt). Functionally, I want windows to handle the drawing of Text inside the Edit control with the selected Font. I've tried capturing the WM_PAINT, WM_NCPAINT and WM_ERASEBKGND messages without luck. They simply draw my bitmap, but when I type something inside the control, nothing is there except my bitmap?!?!

Thanks in advance!
Posted on 2004-03-31 23:42:28 by SubEvil
A simple example of what I mean!
Posted on 2004-04-01 00:00:48 by SubEvil
Hi,

That hardly requires an owner drawn control, just create a pattern brush with your bitmap:

invoke LoadBitmap,[hInst],IDR_BITMAP

mov [hBmp],eax
invoke CreatePatternBrush,eax
mov [hBmpBrush],eax


Then respond to WM_CTLCOLOREDIT in your dialog proc

cmp D[uMsg],WM_CTLCOLOREDIT

jne >.NEXTMSG
invoke SetBkMode,[wParam],TRANSPARENT
mov eax,[hBmpBrush]
ret
Posted on 2004-04-01 01:32:55 by donkey
Thanks Donkey!

Also, I don't know if you noticed the above bitmap, it has a "kind of" title bar. I'd like to move the "editable" section down a bit! In other words, define the margins of the edit control so windows only draws the text within my "custom" margins, so I can have a custom drawn "title bar".

Thanks!
Posted on 2004-04-01 01:47:40 by SubEvil
Take a look at the EM_SETMARGINS message.
Posted on 2004-04-01 02:06:38 by donkey
Interesting, I added your code. MSDN said the message is sent to the parent window, so I added it there. Everything works well until I subclass the window :( Then it kinda stuffs things up :( I need some special handling? What it does is draw the brush, but not the text.

Thanks!
Posted on 2004-04-01 02:33:21 by SubEvil
Can't really help there, you didn't mention any special handling was necessary. It depends on what you're doing I geuss. You will have to do it during WM_PAINT, bitblt the bitmap then use DrawText to draw the text over top of it.
Posted on 2004-04-01 02:39:26 by donkey
Damn :( Because I'll have to handle keyboard characters, text buffers etc. :( I like your method! I just need a little special handling ... for example, I want to capture the WM_MOUSEMOVE event, when the mouse moves over the control, the "active" brush changes, so it looks like it handles "mouse focus". Also, I want to limit certain keys from being used in the control. And provide a small button (clickable area) within the control, simply captures mouse click event at certain co-ords and provides handling of that event. But the brush technique so far is great!
Posted on 2004-04-01 02:49:18 by SubEvil
Damn, what the hell??? I changed the control to a Multi-Line edit box, and the text starts drawing over itself? BTW, I need an Owner-drawn control mainly because I'm cutting the control's region, so it's not a square control, as you can tell in the pic. Damn, this stuff is gonna give me headaches. Any idea on the text redrawing itself incorrectly? I'm not drawing the text, windows is handling it. And it's fine until I "add" the "ES_MULTILINE" window style.
Posted on 2004-04-01 03:28:59 by SubEvil
Hello SubEvil
NaN has written some time ago a n object to draw skinned windows that have a title bar and you can freely draw in the client or place there an edit control. I think his work goes in your direction.
NaN?s post is at http://www.asmcommunity.net/board/index.php?topic=17678

Regards, :)

Biterider
Posted on 2004-04-01 03:55:49 by Biterider
Thanks Biterider, but a) That project has no source code (yet) and b) It's written on ObjAsm32, which, as Nan correctly assumed that not "too many people" are familiar with, I'm one of them!
Posted on 2004-04-01 06:02:07 by SubEvil
Sorry, I thought the source code was also posted, but ask him, he will sure send it to you. I have seen it and currently it is a draft but the concepts are fixed.
I also think, that you don?t need ObjAsm32 to understand what he has done. :grin:

Regards,

Biterider
Posted on 2004-04-01 06:11:25 by Biterider
Very weird, it seems that windows is drawing my "brush" at incorrect locations. The way I always thought of a brush was that it's a kind of "tiled pattern". Don't ask my why windows is drawing my brush with new offsets? It worked find for a Single line Edit box!
Posted on 2004-04-01 06:27:14 by SubEvil

Thanks Donkey!

Also, I don't know if you noticed the above bitmap, it has a "kind of" title bar. I'd like to move the "editable" section down a bit! In other words, define the margins of the edit control so windows only draws the text within my "custom" margins, so I can have a custom drawn "title bar".

Thanks!



Use the EM_GETRECT message to retrieve the formatting rectangle(editable section) of edit control and
then use the EM_SETRECT to make the formatting rectangle larger or smaller than the edit control window.
These messages are processed only by multiline edit controls.

Manos.
Posted on 2004-04-01 08:39:13 by Anonymous
btw.. i have a new interesting method ripped from **** ****** window.
if you notice, all **** ****** window have their own Highlight Color and Highlight text in their Edit boxes.
What they've done is.. intercepting the GetSysColor routine.. so every Call to GetSysColor from their own app with a request of COLOR_HIGLIGHT and COLOR_HIGLIGHTTEXT, got their own reply value.. :)
Posted on 2005-03-23 10:26:10 by kocok