- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
With many thanks in advance,
Mike
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes, (in a bit unexpected way) -- the edit control sends WM_CTLCOLOREDIT message to the parent window. On receiving it, the dialog is supposed to
1) return a brush handle which will be used to fill edit control's background (this is one of rare situations where DialogProc should not return plain TRUE/FALSE)
2)either do a SetBkMode(hDC, TRANSPARENT) or do a SetBkColor(hDC, same_color_as_the_brush) on given DC to ensure that "text background" is of same color as "window background".
3)do a SetTextColor(hDC) if you want to change the foreground color as well
Pay special attention not to create a GDI memory leak on 1) -- it's a grave sin to do:
case (WM_CTLCOLORSTATIC)
DialogProc = CreateSolidBrush(MyColor)
this will create a brush every while but neverdelete one, so you have to invent a bookkeeping scheme as well. The simplest one is to declare a STATIC hBrush, CreateSolidBrush on WM_INITDIALOG, and DeleteObject on WM_DESTROY, (as well as when it's about to change).
You can take a look at XFLOGM code (either 1.0 or 2.0/XFT) to take a look how it's implemented there.
Jugoslav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
So far so good, I can colour an edit box when the dialog box is first drawn now.
But what I really want to do is respond to a user's selection of an rgb combination and show the resulting colour somehow - I thought an edit box was most suitable, but I don't care what it is.
It looks like the WM_CTLCOLOREDIT message is only sent when the edit box is about to be drawn, so I don't think I can use that more than once. How do I change colour dynamically?
With many thanks again,
Mike
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
WM_CTLCOLOREDIT is sent whenever the edit box receives WM_PAINT. Thus, if you want to generate it programatically,call InvalidateRect(hwndEdit, NULL) (+UpdateWindow(hwndEdit)) (of course, manage to change the hBrush accordingly).
Static control (maybe with SS_SUNKEN or WS_EX_STATICEDGE) looks like a better choice than edit control (as it doesn't display caret). The corresponding message is WM_CTLCOLORSTATIC, with identical usage.
Jugoslav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi there,
I tried to change the backgroundcolor of an edit boxl, butit wont do anything. I tried it withSetBKColor, but it wont work. SetBKColor returns 16777215, but nothing else happens.
use dfwina
implicit none
include 'resource.fd'
integer*4 color,hWnd,hDC
type(dialog) dlg
hWnd=getDlgItem(dlgMain%hwnd,IDC_EDIT1)
hDC=getDC(hWnd)
color=setBkColor(hDC,#0000FF)
Thanks in advance,
Markus
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
No, you can't do that (modulo complicated dialog subclassing) using DFLOGM. As pointed above, it's possible either:
* Using native Windows dialog APIs (DialogBox->handle WM_CTLCOLOREDIT as described above)
* Using Xeffort/XFLOGM's DLG_BKCOLOR extension (it's 99% source-code compatible with DFLOGM, so you can just replace USE DFLOGM with USE XFLOGM and link with Xeffort.lib).

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page