Solved

Dialog Messages

Posted on 2000-03-26
11
255 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Visual c++ and text files 7 55
Need some help with listview limit text 20 85
Header of docx file 17 58
Safe conversion? 4 17
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…
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…
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.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

757 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

21 Experts available now in Live!

Get 1:1 Help Now