- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have created a Picture object as a Frame IDC_FRAME_OLDAD and want to fill it with colour.
I think the following code should work.
ps is type paintstructure and rect type rect
hdcClr = BeginPaint(hWnd,ps)
hBox=GetDlgItem(hWnd,IDC_FRAME_OLDAD)
lret=GetWindowRect(hBox,rect)
hbr = CreateSolidBrush (RGB(255,0,255))
lret = FillRect (hdcClr, rect, hbr)
lret = DeleteObject (hbr)
lret=EndPaint(hWnd,ps)
What am I doing wrong?
Thanks,
David
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
BeginPaint does not make much (if any) sense outside of WM_PAINT context: basically, you should paint only when you're sent a WM_PAINT.
The simplest workaround is to use an owner-drawn static control, which sends a WM_DRAWITEM message to the parent (during its own WM_PAINT processing), allowing you to paint whatever you like on provided DRAWITEMSTRUCT.hDC.
For examples, check the old Xflogm code (just search for "ownerdraw" and "drawitem" within). Please see also the notes and remarks under DLG_DRAWITEM heading: I'm not sure, but it's possible that you will still have to manually adjust the .rc file to insert SS_OWNERDRAW style.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I think this is what you ment, but case (IDC_FRAME_OLDAC) is never reached.
case (WM_CTLCOLORSTATIC)
iCtrl=LOWORD(wParam)
select case (iCtrl)
case (IDC_FRAME_OLDAD)
hbr = CreateSolidBrush (RGB(255,0,255))
end select
David
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
On testing what I recommended, I found that the WM_CTLCOLORSTATIC message for the Picture control was indeed sent and intercepted, but the returned brush is not used to paint the rectangle (hbrush=SelectObject(hdcstatic, hbackbrush) also fails to set the color).
If all you want is a rectangle to fill with color, why not chose a static text control and delete the text? I know for certainthat willwork with WM_CTLCOLORSTATIC message processing and returning a brush handle.
If you want to draw anything more complicated than text in the rectangle, then you will have to do what Jugoslav recommends and make it 'ownerdrawn' and then draw in the rectangle after you intercept the WM_DRAWITEM message for the control.
The following works:
1) Open your .RC file as text (NOT auto!) and add or change the type for your control to SS_OWNERDRAWN. Then save it.
2) Add the following to your window procedure
USE DFWINTY
type (T_DRAWITEMSTRUCT) ds
Pointer (pdrawitem, ds)
integerret, hitem
....
case (WM_DRAWITEM)
pdrawitem=lparam
hitem=wparam
if(IDC_STATIC_PICTURE.eq.hitem) then
ret=MessageBox(hdlg,'MyDlgProc reached..fill a YELLOW Rectangle'c, &
'MyDlgProc WM_DRAWITEM message'C, MB_ICONEXCLAMATION)
! Create a yellow brush
hbackbrush=CreateSolidBrush(RGB(245, 255, 0))
MyDlgProc=FillRect(ds%hdc,ds%rcItem,hbackbrush)
return
endif
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes, Tony is right: if you just want the color, use a normal static text control. You can add a WS_BORDER, WS_EX_CLIENTEDGE or WS_EX_STATICEDGE for nicer effects.
Tony, you forgot DeleteObject(hbackbrush). ;-)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks all,
I decided just to set the type as bitmap, it was easier but not so flexible, as I only wanted 4 rectangles with 4 set colours.
David

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