Solved

Dialog Messages

Posted on 2000-03-26
11
256 Views
Last Modified: 2010-04-02
I want to run some code
after the Dialog Box is initialized
and painted.

I can`t do it in WM_INITDIALOG
beacause the dialog was not painted.

Michael.
0
Comment
Question by:michael_telmap
  • 5
  • 3
  • 2
  • +1
11 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 50 total points
ID: 2658321
The dialog is not vet visible when the WM_INITDIALOG message is received.  It is still hidden.  

If you want the code to run after the dialog is first painted, you nedd to look for the WM_PAINT message.  Pass this message on to the default dialog procedure (DefDlgProc()) so that the window is painted, then what the default dialog procedure returns, do your processing.  If your processing needs to be done only the first time the dialog is painted, you can  use some sort of semaphore to insure it is not done every time the windows is repainted.

let me know if you have any questions.
0
 

Author Comment

by:michael_telmap
ID: 2658748
Could you please send me an Example,
I dont understand exactly how to do it.
0
 

Author Comment

by:michael_telmap
ID: 2658752
PS: I`m Working with VC6++.
0
 
LVL 22

Expert Comment

by:nietod
ID: 2658821
I really don't know what you are doing.....

You woudl have a dialgo procedure with somethign like

BOOL MyDlgProc(HWND WndHnd, UINT Msg,WPARAM WrdPrm,LPARAM LngPrm)
{
    switch (Msg)
   {
       case WM_PAINT:
       {
          DefDlgProc(WndHnd,Msg,WrdPrm,LngPrm);
          // Do something here.
          return TRUE
       }
    }
    return FALSE;
}
0
 

Expert Comment

by:Markenstein
ID: 2659084
If your not going to be hiding the dialog you can use the WM_SHOW message.  This occurs every time the window is set the visible flag to true.  Usually only once.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 22

Expert Comment

by:nietod
ID: 2659156
But that occurs before the dialog is painted (I think), the question said the processing must be done after it is painted (unless that was a mistake.)
0
 

Author Comment

by:michael_telmap
ID: 2660487
Where should call for MyDlgProc?
How does it work?
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 2662127
At the end of your OnInitDialog (or the code that handles WM_INITDIALOG if your not MFC), post yourself a message (eg a WM_USER or a registered message) and in the handler for that message do whatever it is you want to do.

eg.
in MFC:

static const UINT WM_MYATSTARTOFDIALOG= ::RegisterWindowMessage("MYATSTARTOFDIALOG");

BEGIN_MESSAGE_MAP(CMyDialog, CDialog)
//{{AFX_MSG_MAP(QListCtrl)
  ...
ON_REGISTERED_MESSAGE(WM_MYATSTARTOFDIALOG, OnMyMessage)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

BOOL CMyDialog::OnInitDialog() {
  CDialog::OnInitDialog();
  ...
  PostMessage(WM_MYATSTARTOFDIALOG);
  return TRUE;
}

LRESULT CMyDialog::OnMyMessage(WPARAM wparam, LPARAM lparam) {
  ... whatever ...
}

if not in MFC .. I'd rather not think about it :-) .. but it is not hard.

0
 
LVL 22

Expert Comment

by:nietod
ID: 2662244
I don't think that will work, you usually only get WM_PAINT messages when  there are no messages waiting in the message queue, so the message you post will get handled before the WM_PAINT message.  I think.  Its possible that when the window is made visible, a WM_PAINT will be forced earlier, I'm not sure.
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 2662330
One can always do an Invalidate/UpdateWindow or a RedrawWindow to force painting earlier (perhaps at the end of OnInitDialog?)

Infact, that may solw the problem anyway.
0
 
LVL 22

Expert Comment

by:nietod
ID: 2664055
>> One can always do an Invalidate/UpdateWindow
>> or a RedrawWindow to force painting earlier
Right.  MY point (question?) is that being done by the OS?  If so then your suggestion will work, other wise it won't because the message you are posting will get handled before the paint.

......Or when, the message is handled, you could force a paint first, is that your point?  That would make sense.

>> (perhaps at the end of OnInitDialog?)
You can't force a paint there, because the dialog is still hidden.  But you could force the paint when the posted message gets handled.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

862 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

24 Experts available now in Live!

Get 1:1 Help Now