?
Solved

Dialog Messages

Posted on 2000-03-26
11
Medium Priority
?
268 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 200 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 does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Industry Leaders: 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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

650 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