Discussion:
WM_PAINT in DialogBox
(too old to reply)
Rob Roy
2008-06-13 02:11:01 UTC
Permalink
I have a Win32 VC++ program with a MODAL DialogBox (i.e. using DialogBox()
function). I'm using VisualStudio 2005.

I cannot seem to get WM_PAINT messages in the DlgProc. I have tried to use
InvalidateRect, UpdateWindow, RedrawWindow, and nothing seems to allow the
WM_PAINT message to get to my DlgProc.

I want to change a bitmap (or even just draw a FrameRect around a bitmap) on
the dialog based on the selected value of a Radio Button. I can draw stuff
once a user clicks the Radio Button (using GetDC, etc). However, the initial
value of the radio button can be different based on a global variable. So,
the drawing needs to take place after the WM_INITDIALOG message, and before a
user clicks on a Radio Button.

If I understand correctly, I should be able to InvalidateRect at
WM_INITDIALOG time to cause WM_PAINT messages to come to the DlgProc after
the Dialog is visible so I can perform the drawing. But, this doesn't seem to
work to create the WM_PAINT message...and, I cannot get the WM_PAINT message
at ANY time no matter what I do.

Ideas?

Thanks,
Rob
David Lowndes
2008-06-13 09:41:02 UTC
Permalink
Post by Rob Roy
I have a Win32 VC++ program with a MODAL DialogBox (i.e. using DialogBox()
function). I'm using VisualStudio 2005.
I cannot seem to get WM_PAINT messages in the DlgProc.
Rob,

Have you checked if the message is occurring - using Spy++?

Dave
Rob Roy
2008-06-13 19:27:02 UTC
Permalink
Post by David Lowndes
Have you checked if the message is occurring - using Spy++?
Thanks for the suggestion.

There does seem to be a WM_PAINT message that is getting noticed by Spy++
upon Dialog activation, but it is not going to my DlgProc. I have even placed
a MessageBox in the WM_PAINT message in my DlgProc, and it is not getting
displayed. These messages seem to be going to the system instead.

I may guess that DialogBox() painting is completely handled by the system,
though nothing seems to be documented about this. If that's the case, how
can I create a MODAL DialogBox that allows me to receive WM_PAINT messages?
Are there any Dialog Template settings I can use for this?

I suppose I could try using a Modeless Dialog with a MessageLoop immediately
following to allow me to wait until the user closes the dialog.

NOTE: I don't have a "Main Window". It is a Dialog-only-based application
(like a "Wizard"), in case this makes any difference.

Thanks,
Rob
David Lowndes
2008-06-13 22:30:36 UTC
Permalink
Post by Rob Roy
Post by David Lowndes
Have you checked if the message is occurring - using Spy++?
Thanks for the suggestion.
There does seem to be a WM_PAINT message that is getting noticed by Spy++
... and presumably all the indications from that are that it is
intended to get to your dialog window?
Post by Rob Roy
upon Dialog activation, but it is not going to my DlgProc.
I may guess that DialogBox() painting is completely handled by the system,
though nothing seems to be documented about this. If that's the case, how
can I create a MODAL DialogBox that allows me to receive WM_PAINT messages?
I vaguely remember that I have used plain SDK code in the past (around
Windows 3 time) to catch a WM_PAINT message on a dialog - so I'm
surprised it's not working for your example.

I've not got time to try it now myself, but I'd get a copy of the SDK
GENERIC sample (I think that's what it's called) and put a WM_PAINT
case in it's About dialog handler and see if that gets hit - just to
prove that it is possible.
Post by Rob Roy
NOTE: I don't have a "Main Window". It is a Dialog-only-based application
(like a "Wizard"), in case this makes any difference.
It shouldn't as far as I'm aware.

Dave
Norman Bullen
2008-06-13 23:25:22 UTC
Permalink
Post by Rob Roy
Post by David Lowndes
Have you checked if the message is occurring - using Spy++?
Thanks for the suggestion.
There does seem to be a WM_PAINT message that is getting noticed by Spy++
upon Dialog activation, but it is not going to my DlgProc. I have even placed
a MessageBox in the WM_PAINT message in my DlgProc, and it is not getting
displayed. These messages seem to be going to the system instead.
I may guess that DialogBox() painting is completely handled by the system,
though nothing seems to be documented about this. If that's the case, how
can I create a MODAL DialogBox that allows me to receive WM_PAINT messages?
Are there any Dialog Template settings I can use for this?
I suppose I could try using a Modeless Dialog with a MessageLoop immediately
following to allow me to wait until the user closes the dialog.
NOTE: I don't have a "Main Window". It is a Dialog-only-based application
(like a "Wizard"), in case this makes any difference.
Thanks,
Rob
In my test project, the dialog procedure used with a modal dialog as the
main window of the application _does_ get WM_PAINT messages.

Please post the code that creates the dialog and the code from the
dialog procedure.
--
Norm

To reply, change domain to an adult feline.
Rob Roy
2008-06-17 01:21:02 UTC
Permalink
Thanks for the replies.

As it were, I was being a bonehead. The case WM_PAINT was inside a nested
switch instead of where I intended to put it. Sorry to waste your time.

Thanks,
Rob
Joseph M. Newcomer
2008-07-31 09:09:41 UTC
Permalink
Generally, you do not want to draw on the surface of a dialog box. What you will
typically do is put a static control in, and do all drawing in the static control. This
is much safer than trying to draw on the dialog's surface.

WM_INITDIALOG takes place before the image is displayed, so doing an InvalidateRect at
that point is meaningless and redundant, since the first drawing has not yet been done.

From your description, it sounds like you have a raw Win32 program (and my deepest
sympathy). I've not seen WM_PAINT fail. But the last time I had to change the background
of a dialog box (I wanted a picture in it) I did it in WM_ERASEBKGND. But I'd recommend
doing the image in a separate static control.
joe
Post by Rob Roy
I have a Win32 VC++ program with a MODAL DialogBox (i.e. using DialogBox()
function). I'm using VisualStudio 2005.
I cannot seem to get WM_PAINT messages in the DlgProc. I have tried to use
InvalidateRect, UpdateWindow, RedrawWindow, and nothing seems to allow the
WM_PAINT message to get to my DlgProc.
I want to change a bitmap (or even just draw a FrameRect around a bitmap) on
the dialog based on the selected value of a Radio Button. I can draw stuff
once a user clicks the Radio Button (using GetDC, etc). However, the initial
value of the radio button can be different based on a global variable. So,
the drawing needs to take place after the WM_INITDIALOG message, and before a
user clicks on a Radio Button.
If I understand correctly, I should be able to InvalidateRect at
WM_INITDIALOG time to cause WM_PAINT messages to come to the DlgProc after
the Dialog is visible so I can perform the drawing. But, this doesn't seem to
work to create the WM_PAINT message...and, I cannot get the WM_PAINT message
at ANY time no matter what I do.
Ideas?
Thanks,
Rob
Loading...