Calling a function AFTER OnInitDialog completes.
-
I was looking to run a function after OnInitDialog completes and has fully drawn the dialog to the screen. I am getting some good results using this method, however, not all of the dialog objects and dialog are showing up. Not to sure why either. // stdafx.h #define WM_MY_USER_DEFINED_MESSAGE WM_APP + 0x10 // MyDialog.h virtual BOOL OnInitDialog(); afx_msg LRESULT OnMyUserDefinedMessage(WPARAM wParam, LPARAM lParam); DECLARE_MESSAGE_MAP() // MyDialog.cpp BEGIN_MESSAGE_MAP(CMyDialog, CDialog) ON_MESSAGE(WM_MY_USER_DEFINED_MESSAGE, OnMyUserDefinedMessage) END_MESSAGE_MAP() BOOL CMyDialog::OnInitDialog() { CDialog::OnInitDialog(); PostMessage(WM_MY_USER_DEFINED_MESSAGE); return TRUE; } LRESULT CMyDialog::OnMyUserDefinedMessage(WPARAM wParam, LPARAM lParam) { //I would imagine that if we are here, the dialog has completley drawn by now. //but this does not seem to be the case Sleep(5000); AfxMessageBox(L"ok"); return NULL; }
-
I was looking to run a function after OnInitDialog completes and has fully drawn the dialog to the screen. I am getting some good results using this method, however, not all of the dialog objects and dialog are showing up. Not to sure why either. // stdafx.h #define WM_MY_USER_DEFINED_MESSAGE WM_APP + 0x10 // MyDialog.h virtual BOOL OnInitDialog(); afx_msg LRESULT OnMyUserDefinedMessage(WPARAM wParam, LPARAM lParam); DECLARE_MESSAGE_MAP() // MyDialog.cpp BEGIN_MESSAGE_MAP(CMyDialog, CDialog) ON_MESSAGE(WM_MY_USER_DEFINED_MESSAGE, OnMyUserDefinedMessage) END_MESSAGE_MAP() BOOL CMyDialog::OnInitDialog() { CDialog::OnInitDialog(); PostMessage(WM_MY_USER_DEFINED_MESSAGE); return TRUE; } LRESULT CMyDialog::OnMyUserDefinedMessage(WPARAM wParam, LPARAM lParam) { //I would imagine that if we are here, the dialog has completley drawn by now. //but this does not seem to be the case Sleep(5000); AfxMessageBox(L"ok"); return NULL; }
-
I was looking to run a function after OnInitDialog completes and has fully drawn the dialog to the screen. I am getting some good results using this method, however, not all of the dialog objects and dialog are showing up. Not to sure why either. // stdafx.h #define WM_MY_USER_DEFINED_MESSAGE WM_APP + 0x10 // MyDialog.h virtual BOOL OnInitDialog(); afx_msg LRESULT OnMyUserDefinedMessage(WPARAM wParam, LPARAM lParam); DECLARE_MESSAGE_MAP() // MyDialog.cpp BEGIN_MESSAGE_MAP(CMyDialog, CDialog) ON_MESSAGE(WM_MY_USER_DEFINED_MESSAGE, OnMyUserDefinedMessage) END_MESSAGE_MAP() BOOL CMyDialog::OnInitDialog() { CDialog::OnInitDialog(); PostMessage(WM_MY_USER_DEFINED_MESSAGE); return TRUE; } LRESULT CMyDialog::OnMyUserDefinedMessage(WPARAM wParam, LPARAM lParam) { //I would imagine that if we are here, the dialog has completley drawn by now. //but this does not seem to be the case Sleep(5000); AfxMessageBox(L"ok"); return NULL; }
-
I was looking to run a function after OnInitDialog completes and has fully drawn the dialog to the screen. I am getting some good results using this method, however, not all of the dialog objects and dialog are showing up. Not to sure why either. // stdafx.h #define WM_MY_USER_DEFINED_MESSAGE WM_APP + 0x10 // MyDialog.h virtual BOOL OnInitDialog(); afx_msg LRESULT OnMyUserDefinedMessage(WPARAM wParam, LPARAM lParam); DECLARE_MESSAGE_MAP() // MyDialog.cpp BEGIN_MESSAGE_MAP(CMyDialog, CDialog) ON_MESSAGE(WM_MY_USER_DEFINED_MESSAGE, OnMyUserDefinedMessage) END_MESSAGE_MAP() BOOL CMyDialog::OnInitDialog() { CDialog::OnInitDialog(); PostMessage(WM_MY_USER_DEFINED_MESSAGE); return TRUE; } LRESULT CMyDialog::OnMyUserDefinedMessage(WPARAM wParam, LPARAM lParam) { //I would imagine that if we are here, the dialog has completley drawn by now. //but this does not seem to be the case Sleep(5000); AfxMessageBox(L"ok"); return NULL; }
aquawicket wrote:
Sleep(5000);
There is no use if you put a sleep here. Remove it. When put a sleep the application will stop all processing including the painting. Try calling the RedrawWindow() function instead of that sleep.
nave [OpenedFileFinder]
-
aquawicket wrote:
Sleep(5000);
There is no use if you put a sleep here. Remove it. When put a sleep the application will stop all processing including the painting. Try calling the RedrawWindow() function instead of that sleep.
nave [OpenedFileFinder]
Sweet.. Got it workin.. RedrawWindow() seemed to do the trick.. I didn't realize I was halting everything with Sleep(); I figured the dialog would be drawn before it ever got to that.. Thanks everyone.