Progress Indicator called from other class fails
I have a simple dialog app which includes a progress indicator (CProgressCtrl). I have previously successfully managed to get this working by having a decoding program doing everything from the same class (dlg class).
The difference now is that Im doing the decoding from other standard ANSI C++ classes. As I dont want to mess around with those as they need to be compiled for different platforms, I though that I could update the decoding progress by a simple method call, e.g.
From other class:
CMainDialogDlg dlg;
dlg.SetProgress(iPercent);
In main dialog class:
void CMainDialogDlg::SetProgress(int progress)
{
m_progress.SetPos(progress);
UpdateData(FALSE);
}
But it seems like I lose the m_hWnd as I get Asserts, i.e.
_AFXCMN_INLINE int CProgressCtrl::SetPos(int nPos)
{ ASSERT(::IsWindow(m_hWnd)); return (int) ::SendMessage(m_hWnd, PBM_SETPOS, nPos, 0L); }
BOOL CWnd::UpdateData(BOOL bSaveAndValidate)
{
ASSERT(::IsWindow(m_hWnd)); // calling UpdateData before DoModal?
Is there a easy way to fix this or have I approached this problem completely wrong?
BR /// Rob
[1199 byte] By [
robalo] at [2007-11-20 11:58:47]

# 1 Re: Progress Indicator called from other class fails
Is the decoding performed in the other class run from a separate thread?
If so, check out the Simple Thread: Part I ( http://www.dev-archive.com/cpp/misc/misc/threadsprocesses/article.php/c14105/) article for a technique to update a progress bar from a secondary thread.
Arjay at 2007-11-11 4:01:48 >

# 2 Re: Progress Indicator called from other class fails
In your other class, the lineCMainDialogDlg dlg;
creates a completely new instance of the CMainDialogDlg - this is not the one that already exists. Additionally, no windows for this new instance have been created - thus no hWnd.
To solve this, from your main dialog when you create this second class you can pass a pointer to the main dialog.
In the main dialog class (CMainDialogDlg)CMyOtherDialog dlg;
dlg.m_pMainDialog = this;
dlg.DoModal();
You must of course have that member variable in the CMyOtherDialog.
Hope that helps.
krmed at 2007-11-11 4:02:48 >

# 3 Re: Progress Indicator called from other class fails
In your other class, the lineCMainDialogDlg dlg;
creates a completely new instance of the CMainDialogDlg - this is not the one that already exists. Additionally, no windows for this new instance have been created - thus no hWnd.
To solve this, from your main dialog when you create this second class you can pass a pointer to the main dialog.
In the main dialog class (CMainDialogDlg)CMyOtherDialog dlg;
dlg.m_pMainDialog = this;
dlg.DoModal();
You must of course have that member variable in the CMyOtherDialog.
Hope that helps.
Thanks for the reply! Now I understand why it doesn't work. But I'm unsure how to implement your suggested solution.
My main dialog never calls the "my other dialog" directly. The main dialog creates a Gradientclass. Here I can drop a file which in turns calls another class called Decode. Here is where all the decoding takes place. So I'm a bit unsure where to pass the pointer.
I've tried the following:
In "MainDialogDlg.h"#include "decode.h"
decode dialog;
Then before the return in the "MainDialogDlg.::OnInitDialog()"dialog.m_pMainDialog = this;In the "decode.h"HANDLE m_pMainDialog;Is this correctly defined?
If it is now in "decode.cpp" where I do the method call "dlg.SetProgress(<some int>);" how will I actually do that? Once I'm in the MainDialogDlg method "SetProgress", what do I need to do to update the handle before the "UpdateData"?
BR /// Rob
robalo at 2007-11-11 4:03:47 >
