Solved

Dialog Messages

Posted on 2000-03-26
11
265 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
[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
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

737 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