Solved

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

Posted on 2002-06-30
8
1,334 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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
 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

729 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