-
November 19th, 2013, 03:07 AM
#1
Auto. start function after cdialog was shown?
Hello,
I want to start a time intensiv function after showing a modal cdialog.
How can I do this?
Starting the function in OnInitDialog do not work because the dialog is not shown, then.
Any ideas?
tx
Ralf
-
November 19th, 2013, 06:25 AM
#2
Re: Auto. start function after cdialog was shown?
If a function is "time intensiv" then create a worker thread and start it from there.
See Using Worker Threads
Victor Nijegorodov
-
November 19th, 2013, 09:28 AM
#3
Re: Auto. start function after cdialog was shown?
Hello,
the problem is not the function.
The problem is that I want to call it immediately after the dialog is shown.
But I can not call the function from OnInitDialog, because in this case, the function is called before the dialog is shown.
It is necessary, that OnInitDialog returns!
Is there a function that is called by the system when the dialog was shown?
thx
Ralf
-
November 19th, 2013, 09:38 AM
#4
Re: Auto. start function after cdialog was shown?
OK, there is a well known trick to implement such a behaviour: PostMessage a user defined message (from WM_APP range or a registered message) from OnInitDialog to the dialog itself.
Then in the message handler of this message call your function (or start a thread...)
Victor Nijegorodov
-
November 19th, 2013, 10:09 AM
#5
Re: Auto. start function after cdialog was shown?
Hello Victor,
I have not tried it, but isn't there a problem:
WM_PAINT for the dialog will only processed when there is no other message in the message queue (says msdn).
But when I post my message, it will be processed first. WM_PAINT (drawing the dialog) will processed after my function is executed. But that behaviour is bad for my app.
Ralf
-
November 19th, 2013, 10:30 AM
#6
Re: Auto. start function after cdialog was shown?
Originally Posted by Ralf Schneider
Hello Victor,
I have not tried it, but isn't there a problem...
Ralf, trying it (about one or two minutes) would have been at least one order faster than typing this post and waiting for reply (more than 30 minutes!)
Victor Nijegorodov
-
November 19th, 2013, 10:35 AM
#7
Re: Auto. start function after cdialog was shown?
You could start in in another thread in OnInitDialog. Since it's in a thread, OnInitDialog will still return and the dialog still be shown.
You may want to look into handling WM_SHOW.
Another option is to set a short timer in OnInitDialog so that OnInitDialog returns, the window is displayed the timer goes off and your function gets executed.
-
November 20th, 2013, 03:09 AM
#8
Re: Auto. start function after cdialog was shown?
...or can post a user-defined message from OnInitDialog.
Example
Code:
// MyDialog.h
class CMyDialog : public CDialog
{
enum {WM_POSTINITDIALOG = WM_APP + 1};
// ...
afx_msg LRESULT OnPostInitDialog(WPARAM wParam, LPARAM lParam);
};
Code:
// MyDialog.cpp
// ...
ON_MESSAGE(CMyDialog::WM_POSTINITDIALOG, &CMyDialog::OnPostInitDialog)
END_MESSAGE_MAP()
BOOL CMyDialog::OnInitDialog()
{
CDialog::OnInitDialog();
// ...
PostMessage(CMyDialog::WM_POSTINITDIALOG);
return TRUE;
}
LRESULT CMyDialog::OnPostInitDialog(WPARAM wParam, LPARAM lParam)
{
// Here the dialog IS visible...
return 0;
}
-
November 20th, 2013, 03:23 AM
#9
Re: Auto. start function after cdialog was shown?
Hello Ovidiu,
I tried it.
But it do not work because it seems, that the OnPaint-function of CDialog was not called before OnPostInitDialog.
And that is my main problem.
I have to think about a basical different solution.
Ralf
-
November 20th, 2013, 03:56 AM
#10
Re: Auto. start function after cdialog was shown?
Originally Posted by Ralf Schneider
...
I have to think about a basical different solution.
Ralf
There is nothing more "to think".
See the post#2.
Victor Nijegorodov
-
November 21st, 2013, 02:19 AM
#11
Re: Auto. start function after cdialog was shown?
Originally Posted by Ralf Schneider
I tried it.
But it do not work because it seems, that the OnPaint-function of CDialog was not called before OnPostInitDialog.
And that is my main problem.
I have to think about a basical different solution.
A basically different solution, though the same well known one, is setting a timer.
Best regards,
Igor
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|