Solved

Problem In WM_CTLCOLORDLG For Dialogs (SAME As WM_PAINT For Windows)

Posted on 2002-06-30
8
1,295 Views
Last Modified: 2013-12-04
Hello Experts,

I need to paint the Dialog Box just as we paint the Client Area of Windows in the WM_PAINT Messages. For this from MSDN I came to know that equivalent to WM_PAINT, WM_CTLCOLORDLG HANDLES these message for dialog-boxes. So I did the entire painting and all in this for dialog-box.

Here is a BIT CODE :: (Everywhere I have used Off-Screen DC'S For Flicker Free, Since this a High-Image Appl.)

case WM_CTLCOLORDLG:  //wparam is the DC of the dialog-box
{
hdc=(HDC)wParam;
GetClientRect(HWND,&RECT);
SetStretchBltMode(hdc,STRETCH_HALFTONE);
hdcmem=CreateCompatibleDC(hdc);
if (hdcmem==NULL)
......return;
SetStretchBltMode(hdcmem,STRETCH_HALFTONE);
hbmmem=CreateCompatibleBitmap(hdc,RECT.right-RECT.left,RECT.bottom-RECT.top);
if (hbmmem==NULL)
.....return;
hbmold=SelectObject(hdcmem,hbmmem);

umode=SetBkMode(hdcmem,TRANSPARENT);
SetBrushOrgEx(hdcmem,0,0,NULL);
FillRect(hdcmem,&RECT,BRUSH);
StretchBlt(hdcmem,........)
...
...
TextOut(hdcmem,.......)
...

BitBlt(hdc,RECT.left, RECT.top,RECT.right-RECT.left, RECT.bottom-RECT.top,hdcmem,0,0,SRCCOPY);
SelectObject(hdcmem,hdcold);
DELETEALLOBJEST();
}

PROBLEM::
This is working very fine as expected on all OS'S 2000/NT/ME/XP except '98, though I haven't used anything which is not there for '98.

In '98 A Blank dialog-box comes with no paiting and all, which I have done in WM_CTLCOLORDLG. Though, debugging shows, that it is going into this Message whenever dialog-box needs to be re-painted, But NOTHING is being done which I have coded in WM_CTLCOLORDLG, UNLIKE ALL OTHER OS'S.

Why only '98, Any comments/suggestions are welcome.

Best Regards
Sudhaom

0
Comment
Question by:sudhaom
  • 4
  • 3
8 Comments
 
LVL 12

Expert Comment

by:pjknibbs
ID: 7121146
Actually, that isn't the correct way to use the WM_CTLCOLORDLG message. If you read the MSDN documentation you'll see that you should actually return a handle to the brush which will be used to paint the dialog's background--since you're not returning anything it's bound not to work. (In fact, it's certainly a fluke that it DOES work under Win2K/XP etc.--those operating systems obviously handle an incorrect return value from WM_CTLCOLORDLG rather better than 98 does).

Thing is, why don't you just use WM_PAINT? Dialog boxes get sent that message just like any other window does--normally it's handled by DefDialogProc() (which will send the WM_CTLCOLORDLG message and handle all the appropriate repainting), but you can directly handle WM_PAINT if you prefer, and I've done this myself on numerous occasions.
0
 
LVL 1

Author Comment

by:sudhaom
ID: 7121217
Thanks pjknibbs,
Yes I read that, which shows that you should return a handle to Brush In the last, but good for 98/NT and all other OS as they are handling it auto and no problem till now except 98.

Yes I too wanted to use WM_PAINT from the starting for dialog-boxes apart from the Main Wcreen and other windows. But what happened is that when I used the above WM_PAINT for dialog boxes and coded what ever is there in WM_CTLCOLORDLG above, in WM_PAINT for dialog-Box, everything gets hanged, everytime, Neither the main screen window is repainted and when I switch between applications all Windows(Parent etc) are lost and no painting-work which was there in WM_PAINT of Main Window gets repainted and everything else apart from dialog-box get lost (not repainted).

Instead of putting the question right that time only, I found WM_CTLCOLORDLG from MSDN.
But you see WM_PAINT in Dialog-Boxes was creating panic for me. I would also like to tell you that in::

WM_PAINT of Parent Window (rather everywhere) Top 15 Lines(for Offline DC) are same as that of WM_CTLCOLORDLG, the rest will obviously be different as depends what I am going to draw on Main Window or a Dialog-Box etc.

Please Suggest me, why putting code in WM_PAINT for dialog-Box is creating problem for me, as you have already successfully done it.

Best Regards
Sudhaom


0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 7121294
I don't think that

we can paint on CTLCOLOR

You can paint in effective way using WM_ERASEBACKGROUND

CtrlCOlor is only for setting the background color using brush

I'm suggesting WM_ERASEBACKGROUND, becoz in every time before WM_PAINT, this message is called, and using the default brush of the deialog , this fills the color first. Then only WM_PAINT get the control.

So you get flicker if you didn't disable the erasebackground drawing, and draw it in WM_PAINT

Two things can do for this

1. Disable Erase background by returning GetStockObject(NULL_BRUSH) in control color and draw it in WM_PAINT

2. Other is use the drawing in WM_ERASEBACKGROUND

GOOD LUCK
0
 
LVL 12

Accepted Solution

by:
pjknibbs earned 180 total points
ID: 7121451
WM_PAINT hanging? Are you sure you're calling BeginPaint() and EndPaint() correctly within the handling of your WM_PAINT call? If you don't call those functions Windows will never know that you've repainted the window and you'll go into an infinite loop of WM_PAINT calls. (Yes, I've made this mistake myself).
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 1

Author Comment

by:sudhaom
ID: 7123806
Thanks pjknibbs and roshmon for your valued comments.
Yes pjknibbs, In the Parent Window (and child's) WM_PAINT, I used BeginPaint and Endpaint, but in dialog-boxes, Since I jus changed,
case WM_CTLCOLORDLG:    to         case WM_PAINT:
And therefore forgot to include BeginPaint and Endpaint, I will do that and let you know the results.

BTW if I go by WM_CTLCOLORDLG only, and don't want to move to WM_PAINT, becuase WM_CTLCOLORDLG is also meant for the same feature in case of dialog-boxes, you have seen my code above for WM_CTLCOLORDLG, can you please suggest me, after doing everthing how to return a BRUSH handle, what I have to add code-wise, so that thing runs proper in '98 also using WM_CTLCOLORDLG only.

Best Regards
Sudhaom

0
 
LVL 1

Author Comment

by:sudhaom
ID: 7123935
Thanks pjknibbs and roshmon for your valued comments.
Yes pjknibbs, In the Parent Window (and child's) WM_PAINT, I used BeginPaint and Endpaint, but in dialog-boxes, Since I jus changed,
case WM_CTLCOLORDLG:    to         case WM_PAINT:
And therefore forgot to include BeginPaint and Endpaint, I will do that and let you know the results.

BTW if I go by WM_CTLCOLORDLG only, and don't want to move to WM_PAINT, becuase WM_CTLCOLORDLG is also meant for the same feature in case of dialog-boxes, you have seen my code above for WM_CTLCOLORDLG, can you please suggest me, after doing everthing how to return a BRUSH handle, what I have to add code-wise, so that thing runs proper in '98 also using WM_CTLCOLORDLG only.

Best Regards
Sudhaom

0
 
LVL 1

Author Comment

by:sudhaom
ID: 7126933
Hello

Waiting for your comments.

Best egards
Sudhaom

0
 
LVL 12

Expert Comment

by:pjknibbs
ID: 7128032
If you want to use WM_CTLCOLORDLG you must make sure the brush you're using exists throughout the life of the dialog box (e.g. isn't created locally in the WM_CTLCOLORDLG call), then return its handle from the message. That's all you need to do--you shouldn't be doing any real drawing inside WM_CTLCOLORDLG because that's not what the message is designed for!

To clarify: WM_CTLCOLORDLG is ONLY used to set the drawing colours to be used when rendering a dialog box, so you should only call functions like SetTextColor() inside it. If you need to do anything more complex, use WM_PAINT.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now