Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

About WM_PAINT and Dialog Boxes

Status
Not open for further replies.

cdgios

Technical User
Jul 17, 2002
40
US
Hi If you have a dialog box with a bunch of pre-defined child window controls,
a) Assuming that i want process the WM_PAINT messages in the dialog box procedure, under what all circumstances/scenarios does the dialog box procedure receive WM_PAINT messages ?

The reason i ask is that i want to paint the static text control on the dialog box in response to any user selection of the other controls (radio buttons) on the dialog box. Also, i want to paint that static text control by a default shape and color when the dialog box is initially created.

Thanks
Best Regards
chandra
 
Hi

Why repaint the dialog while you could repaint only the static control ?
An easy way is, I guess, to add a CStatic-derived class that you can paint with different color and make the required calls to that class in the handler of the other controls

MTC
THierry
 
Hello TGM, Thanks for the reply. My intent is to paint the static control on the dialog box (I must have made a typing mistake). What I would like to know is that,
a) if any of the pre-defined controls (radio buttons, check boxes etc.) on the Dialog Box change (i.e are selected by the user), does Windows generate a WM_PAINT message that can be captured in the dialog box procedure?. In general I wanted to know all the scenariors under which WM_PAINT messages are generated by Windows and sent to the dialog box procedure.
b) When the dialog box with some pre-defined controls (radio buttons, etc.) is created, does Windows generate a WM_PAINT message and send it to the dialog box procedure?.
I want to be able to capture that message in the dialog box procedure and paint the static control with some default color and shape.

Thanks
Best Regards
Chandra
 
Hi

If you want to track the message very easily, add this line to the handler of OnPaint :

::OutputDebugString( "Paint Received \n");

You'll see that the Dialogbox receives the message WM_PAINT each time it needs to be .... repainted, for example if you minimize and maximize it.

If you want to force the message WM_PAINT, in the handler of your check boxes, radio boxes, ... add the following line:
Invalidate();

The dialogbox will receive the WM¨_PAINT message.

Now for the initial painting, why not use the OnInitDialog function. It's typically done for this ...

By the way, OOP means that the controls draw themselves and not the dialog box. So it's still a better design to do it that way.

HTH

Thierry



 
Hello TGM, Thanks for your reply. I agree with you in that the initial painting of the dialog box static control could be done when the dialog box procedure receives the WM_INITDIALOG message ( when the dialog box is created with DialogBox() function call). But I am looking at an example from charles petzold's book ("Programming Windows", Fifth Edition, Chapter 11, Figure 11-3. "the ABOUT2 program") in which the initial static text control painting is not done in response to the WM_INITDIALOG message. Instead he handles the WM_PAINT message in the dialog box procedure and paints the static text control there. So, I was wondering if after the DialogBox() function is called (from the main application window's procedure) to create the dialog box, Windows sends the dialog box procedure the WM_PAINT message soon after it sends the WM_INITDIALOG message. How else is the static text control on the dialog box painted initially according to this example program in his book?.

I understand that incase of a regular window (main application window), the WinMain() calls UpdateWindow () which causes WM_PAINT to be sent to the window procedure where initial painting can be done. I am trying to understand how this is done in case of dialog boxes.

Thanks
Best Regards
Chandra
 
(This is a repost of yesterdays message so that the question could be brought into focus again today)
---Thanks :)
----------------------------------------
Hello TGM, Thanks for your reply. I agree with you in that the initial painting of the dialog box static control could be done when the dialog box procedure receives the WM_INITDIALOG message ( when the dialog box is created with DialogBox() function call). But I am looking at an example from charles petzold's book ("Programming Windows", Fifth Edition, Chapter 11, Figure 11-3. "the ABOUT2 program") in which the initial static text control painting is not done in response to the WM_INITDIALOG message. Instead he handles the WM_PAINT message in the dialog box procedure and paints the static text control there. So, I was wondering if after the DialogBox() function is called (from the main application window's procedure) to create the dialog box, Windows sends the dialog box procedure the WM_PAINT message soon after it sends the WM_INITDIALOG message. How else is the static text control on the dialog box painted initially according to this example program in his book?.

I understand that incase of a regular window (main application window), the WinMain() calls UpdateWindow () which causes WM_PAINT to be sent to the window procedure where initial painting can be done. I am trying to understand how this is done in case of dialog boxes.

Thanks
Best Regards
Chandra
 
Hi

I guess the book of Petzold is about C programming. All my answers were linked to MFC and the C++ way of programming Windows.

And, yes, the message WM_PAINT is sent after the call of the function OnInitDialog.

Thierry

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top