Solved

Dialog Messages

Posted on 2000-03-26
11
257 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Visual c++ and text files 7 68
How to copy an image file into clipboard C/C++? 1 170
C++ mouse_event mouse look 7 83
Why isn't object file created? 6 59
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
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 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…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

803 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