|
This should be a little clearer:
CDlg2::CDlg2(CDlg1* pDlg,CWnd* pParent /*= NULL*/)
: CDialog(CDlg2::IDD, pParent),m_pDlg1(pDlg)
{
//other initialization
}
this way you're also initializing the pointer without even having to have it within the actual constructor. The only thing you should have to worry about now is making sure your member variable (m_pDlg1) is declared as a pointer to a CDlg1 object, with the forward declaration, make sure the function you're calling is public (or the Tab control object variable), and you should be set.
hope this helps, let me know
If it's broken, I probably did it
bdiamond
|
|
|
|
|
Ok, almost there.
Here's what I've done (changes in blue)....
In "Dlg2.h":
<font color=blue>class CDlg1;</font> <font color=gray>
<font color=brown>class CDlg2 : public CDialog
{
public:</font>
<font color=gray>
<font color=blue>CDlg2(CDlg1* pDlg, CWnd* pParent = NULL);</font> <font color=gray>
<font color=blue>CDlg1* m_pDlg1;</font> <font color=gray>
<font color=brown>...
}</font>
And in "Dlg2.cpp":
<font color=gray>
<font color=blue>CDlg2::CDlg2(CDlg1* pDlg, CWnd* pParent</font> <font color=gray></font><font color=blue>)
: CDialog(CDlg2::IDD, pParent), m_pDlg1(pDlg)</font> <font color=gray>
<font color=brown>{</font>
<font color=gray>
<font color=brown>}</font>
Now when I compile, I receive the following error:
Dlg1.cpp(67) : error C2512: 'CDlg2' : no appropriate default constructor available
Lines 65 thru 72 of "Dlg1.cpp" are:
<font color=brown>CDlg1::CDlg1(CWnd* pParent</font> <font color=gray></font><font color=brown>)
: CDialog(CDlg1::IDD, pParent)
{</font>
<font color=gray>
<font color=brown>m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}</font>
Why is CDlg1 being affected by changes made "Dlg2.h" & "Dlg2.cpp"?? What am I doing wrong?
|
|
|
|
|
that's my fault. try changing this to this and see if it works.
CHANGE THIS:
CDlg2::CDlg2(CDlg1* pDlg, CWnd* pParent /*=NULL*/) : CDialog(CDlg2::IDD, pParent), m_pDlg1(pDlg) // New
{
//{{AFX_DATA_INIT(CDlg2)
//}}AFX_DATA_INIT
}
TO THIS:
CDlg2::CDlg2(CDlg1* pDlg, CWnd* pParent /*=NULL*/) : CDialog(CDlg2::IDD, pParent)
{
m_pDlg = pDlg;
//{{AFX_DATA_INIT(CDlg2)
//}}AFX_DATA_INIT
}
sorry about that!
I made my own test project real quick to make sure I had it right, so just in case you need that one let me know and I'll send it to you
If it's broken, I probably did it
bdiamond
|
|
|
|
|
Sorry to keep this thread running so long.
I made the changes you suggested and I get the exact same error.
Any other suggestions?
Chris
|
|
|
|
|
I don't mind at all-- I just recently got access to the internet, and before I was WISHING I had anybody to ask about anything. Before I didn't have anyone to ask, because I taught myself and nobody else where I was knew anything about C++
here is the actual files:(Replace my CDlgtestDlg with your CDlg1)
this is two header files and two .cpp files (still willing to help if this doesn't do it)
********************************************************************
// dlgtestDlg.h : header file
//
#if !defined(AFX_DLGTESTDLG_H__B42E61F1_E754_4EAD_B51A_EF1DC2AE9DA8__INCLUDED_)
#define AFX_DLGTESTDLG_H__B42E61F1_E754_4EAD_B51A_EF1DC2AE9DA8__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
/////////////////////////////////////////////////////////////////////////////
// CDlgtestDlg dialog
class CDlgtestDlg : public CDialog
{
// Construction
public:
CDlgtestDlg(CWnd* pParent = NULL); // standard constructor
// Dialog Data
//{{AFX_DATA(CDlgtestDlg)
enum { IDD = IDD_DLGTEST_DIALOG };
// NOTE: the ClassWizard will add data members here
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CDlgtestDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
HICON m_hIcon;
// Generated message map functions
//{{AFX_MSG(CDlgtestDlg)
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
afx_msg void OnButton1();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_DLGTESTDLG_H__B42E61F1_E754_4EAD_B51A_EF1DC2AE9DA8__INCLUDED_)
**************************************************************
// dlgtestDlg.cpp : implementation file
//
#include "stdafx.h"
#include "dlgtest.h"
#include "dlgtestDlg.h"
#include "dlg2.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDlgtestDlg dialog
CDlgtestDlg::CDlgtestDlg(CWnd* pParent /*=NULL*/)
: CDialog(CDlgtestDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CDlgtestDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CDlgtestDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDlgtestDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDlgtestDlg, CDialog)
//{{AFX_MSG_MAP(CDlgtestDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDlgtestDlg message handlers
BOOL CDlgtestDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CDlgtestDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CDlgtestDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CDlgtestDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CDlgtestDlg::OnButton1()
{
CDlg2 dlg(this);
dlg.DoModal();
}
***************************************************************
#if !defined(AFX_DLG2_H__11E9112B_9C78_4698_9C02_403F39EEE0FA__INCLUDED_)
#define AFX_DLG2_H__11E9112B_9C78_4698_9C02_403F39EEE0FA__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// Dlg2.h : header file
//
/////////////////////////////////////////////////////////////////////////////
// CDlg2 dialog
class CDlgtestDlg;
class CDlg2 : public CDialog
{
// Construction
public:
CDlg2(CWnd* pParent = NULL); // standard constructor
CDlg2(CDlgtestDlg* pDlg, CWnd* pParent = NULL); // standard constructor
// Dialog Data
//{{AFX_DATA(CDlg2)
enum { IDD = IDD_DIALOG1 };
// NOTE: the ClassWizard will add data members here
//}}AFX_DATA
CDlgtestDlg* m_pDlg1;
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CDlg2)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
// Generated message map functions
//{{AFX_MSG(CDlg2)
// NOTE: the ClassWizard will add member functions here
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_DLG2_H__11E9112B_9C78_4698_9C02_403F39EEE0FA__INCLUDED_)
****************************************************************
// Dlg2.cpp : implementation file
//
#include "stdafx.h"
#include "dlgtest.h"
#include "Dlg2.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDlg2 dialog
CDlg2::CDlg2(CWnd* pParent /*=NULL*/)
: CDialog(CDlg2::IDD, pParent)
{
//{{AFX_DATA_INIT(CDlg2)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
CDlg2::CDlg2(CDlgtestDlg* pDlg, CWnd* pParent /*=NULL*/)
:CDialog(CDlg2::IDD,pParent)
{
m_pDlg1 = pDlg;
}
void CDlg2::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDlg2)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDlg2, CDialog)
//{{AFX_MSG_MAP(CDlg2)
// NOTE: the ClassWizard will add message map macros here
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDlg2 message handlers
If it's broken, I probably did it
bdiamond
|
|
|
|
|
Ok, I went over your code line-by-line and my problem was this:
I had commented-out the old "Standard Constructor" in Dlg2.h instead of leaving it as overloaded.
So now my code is like yours, and the program compiles fine, UNTIL......
When I add my OnButton1() message handler in Dlg2.cpp, it doesn't recognize m_pDlg1.
When I try (in OnButton1()):
int nCurTabSel = m_pDlg1->m_tab.GetCurSel();
I get the error:
Dlg2.cpp(55) : error C2027: use of undefined type 'CDlg1'.
When I try:
m_pDlg1->function();
I get the error:
Dlg2.cpp(57) : error C2065: 'm_pDlg1' : undeclared identifier.
CTabCtrl m_tab & void function() are both defined under the "public:" section of the CDlg1 class.
I checked thoroughly for typos and found none. The message handler just doesn't seem to recognize m_pDlg1 even though it was just defined in the same Dlg2.cpp file:
CDlg2::CDlg2(CWnd* pParent )
: CDialog(CDlg2::IDD, pParent)
{
}
CDlg2::CDlg2(CDlg1* pDlg, CWnd* pParent )
: CDialog(CDlg2::IDD, pParent)
{
m_pDlg1 = pDlg;
}
void CDlg2::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CDlg2, CDialog)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
END_MESSAGE_MAP()
void CDlg2::OnButton1()
{
m_pDlg1->m_tab.GetCurSel();
m_pDlg1->function();
}
I'm getting closer, I can feel it!!!!
Thanks so much for your help.
-Chris
|
|
|
|
|
Make sure you have
#include "CDlg1.h"
at the top of your Dlg2.cpp file
If it's broken, I probably did it
bdiamond
|
|
|
|
|
*sigh*
I added the include, and it still compiles okay, but the program crashes and the debug directs me to an "ASSERT(::IsWindow(m_hWnd))" expression deep in MFC.
Is it okay to have "circular" #includes? As per your suggestion, I am including Dlg1.h in Dlg2.cpp, but the fact that I'm embedding Dlg2 into Dlg1 requires me to include Dlg2.h in Dlg1.h.
Tell me when your sick of this thread & I'll quit bugging you. Thanks tho.
Chris
|
|
|
|
|
Ok, how bout this....
I took the code you supplied, & started an MFC project. The only thing I changed (at first) was to add a button to Dialog #2 with a message handler that would hide the button in Dialog #1:
void CDlg2::OnButton2()
{
m_pDlg1->m_button1.ShowWindow(SW_HIDE);
} It compiled and ran fine.
But then I changed the 2nd dialog to be modeless (like my original project). I.e. I got rid of the OnButton1() - DoModal() message handler in dlgtestDlg.cpp and instead used m_dlg2.Create() & m_dlg2.SetWindowPos() in OnInitDialog (CDlg2 m_dlg2 declared in dlgtestDlg.h).
Now the program crashes, but runs fine if I comment-out "m_pDlg1->m_button1.ShowWindow(SW_HIDE);" in CDlg2's message handler.
????
I'm baffled.
-Chris
|
|
|
|
|
I'm assuming that m_button1 is a CEdit object? If so, is it declared publicly? what's the error message you're getting now? Also, in your constructor you should have something like this just to check later down the line:
m_pDlg1 = 0;
m_pDlg1 = pDlg;
if you put a breakpoint on your ShowWindow line if it's still crashing you can make sure that m_pDlg1 has a valid value
glad to help, don't worry about bugging me, just remember to let me know when you get it working right!;)
If it's broken, I probably did it
bdiamond
|
|
|
|
|
Thanks, I'll screw around w/ it s'more this weekend. Out of the office 'til Monday tho, so I'll get back to you then.
Thanks again for all of your help. Have a good weekend!
Chris
P.S. I don't really know what a breakpoint is, but it does certainly appear as though m_pDlg1 is invalid. That's where it crashes and from my limited experience with the debug tool, it doesn't like the m_hWnd object passed to ShowWindow -- I'm assuming that is m_pDlg1??
P.P.S. (m_button1 is a CButton object, but for my purposes it doesn't really matter what it is, so long as I can modify it from Dialog 2)
|
|
|
|
|
Here's your sample program, modified to function like mine. To recap -- from the embedded child dialog, I want Button2 to hide Button1 and to call "function()" (declared in CDlg1). In the Button2 message handler:
"m_pDlg1->funtion();" yields "Dlg2.cpp(53) : error C2039: 'funtion' : is not a member of 'CDlgtestDlg'" compile-time.
"m_pDlg1->m_button1.ShowWindow(SW_HIDE);" causes a "memory could not be read" run-time crash.
Here's the code, please take a look when you have time:
dlgtestDlg.cpp
#include "stdafx.h"
#include "dlgtest.h"
#include "dlgtestDlg.h"
#include "dlg2.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
enum { IDD = IDD_ABOUTBOX };
protected:
virtual void DoDataExchange(CDataExchange* pDX);
protected:
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
END_MESSAGE_MAP()
CDlgtestDlg::CDlgtestDlg(CWnd* pParent )
: CDialog(CDlgtestDlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CDlgtestDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_BUTTON1, m_button1);
}
BEGIN_MESSAGE_MAP(CDlgtestDlg, CDialog)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
END_MESSAGE_MAP()
BOOL CDlgtestDlg::OnInitDialog()
{
CDialog::OnInitDialog();
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
SetIcon(m_hIcon, TRUE);
SetIcon(m_hIcon, FALSE);
m_dlg2.Create(CDlg2::IDD, this);
CRect wRect; GetWindowRect(wRect);
m_dlg2.SetWindowPos(GetDlgItem(IDD_DLGTEST_DIALOG), wRect.left, wRect.top, 0, 0, SWP_SHOWWINDOW|SWP_NOSIZE);
return TRUE;
}
void CDlgtestDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
void CDlgtestDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this);
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
HCURSOR CDlgtestDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CDlgtestDlg::function()
{
AfxMessageBox("Generic function called.");
}
dlgtestDlg.h
#if !defined(AFX_DLGTESTDLG_H__B42E61F1_E754_4EAD_B51A_EF1DC2AE9DA8__INCLUDED_)
#define AFX_DLGTESTDLG_H__B42E61F1_E754_4EAD_B51A_EF1DC2AE9DA8__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "Dlg2.h"
class CDlgtestDlg : public CDialog
{
public:
CDlgtestDlg(CWnd* pParent = NULL);
CDlg2 m_dlg2;
void function();
enum { IDD = IDD_DLGTEST_DIALOG };
CButton m_button1;
protected:
virtual void DoDataExchange(CDataExchange* pDX);
protected:
HICON m_hIcon;
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
DECLARE_MESSAGE_MAP()
};
#endif // !defined(AFX_DLGTESTDLG_H__B42E61F1_E754_4EAD_B51A_EF1DC2AE9DA8__INCLUDED_)
Dlg2.cpp
#include "stdafx.h"
#include "dlgtest.h"
#include "Dlg2.h"
#include "DlgtestDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CDlg2::CDlg2(CWnd* pParent )
: CDialog(CDlg2::IDD, pParent)
{
}
CDlg2::CDlg2(CDlgtestDlg* pDlg, CWnd* pParent )
:CDialog(CDlg2::IDD,pParent)
{
m_pDlg1 = 0;
m_pDlg1 = pDlg;
}
void CDlg2::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CDlg2, CDialog)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
END_MESSAGE_MAP()
void CDlg2::OnButton2()
{
}
Dlg2.h
#if !defined(AFX_DLG2_H__11E9112B_9C78_4698_9C02_403F39EEE0FA__INCLUDED_)
#define AFX_DLG2_H__11E9112B_9C78_4698_9C02_403F39EEE0FA__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class CDlgtestDlg;
class CDlg2 : public CDialog
{
public:
CDlg2(CWnd* pParent = NULL);
CDlg2(CDlgtestDlg* pDlg, CWnd* pParent = NULL);
enum { IDD = IDD_DIALOG1 };
CDlgtestDlg* m_pDlg1;
protected:
virtual void DoDataExchange(CDataExchange* pDX);
protected:
afx_msg void OnButton2();
DECLARE_MESSAGE_MAP()
};
#endif // !defined(AFX_DLG2_H__11E9112B_9C78_4698_9C02_403F39EEE0FA__INCLUDED_)
|
|
|
|
|
As in my previous post I'm working on an MDI project with two document types. Both have been registered in the CMultiDocTemplate successfully and can have new instances opened.
I've read an article by Roger Allen
http://www.codeproject.com/useritems/DocViewEnhancements.asp
which suggests deriving from the CDocManager class in order to be able to instantiate documents of a specfic type dynamically, but I'd rather avoid this.
Can anyone suggest another method by which I can take data from one copy of one document type & use it to instantiate two copies of another document type??
Sorry for the wordiness of the last bit :/ ....
Thanks in advance for any suggestions. I've hunted around but this area of the document/view architecture seems to be little documented
Dave
|
|
|
|
|
If you call OpenDocumentFile(NULL) on the document templates for the new document types, this will return CDocument* object to you. You can then cast these pointers to the correct document types and use an overridden operator=(COtherDocType&) function to copy the data across.
Something like this:
void CDoc1Type::CreateCopies()
{
CDocTemplate *pDocTemplate = ?;
CDoc2Type *pDoc2 = static_cast<CDoc2Type>(pDocTemplate->OpenDocumentFile(NULL));
*pDoc2 = this;
...
}
const CDoc2Type& CDoc2Type::Operator=(const CDoc1Type& doc1)
{
}
The coed and the idea is a bit rough. Hopefully it makes sense!
Roger Allen - Sonork 100.10016
Roger Wright: Remember to buckle up, please, and encourage your friends to do the same. It's not just about saving your life, but saving the quality of life for those you may leave behind...
|
|
|
|
|
Hi,
This is my first proper MFC app so please bear with me a little, I've got a feeling I have overcomplicated things for myself :/.
I've presently got one document type which maintains a frame grabber, two cameras and their capture (all in one instance) and another type for DIBs. These are intended as the result of any image processing carried out & will have multiple instances.....
As soon as I write this I see the error of my ways I should just have the main frame own & control the cameras then pass the captured pixel-array to any DIB documents from there.
Shouldn't this simplify maintaining my data? as I'll only ever need the one document type, or is it just as complicated to associate data owned by the main frame with a CView and CMDIChildWnd? (without an accompanying document)
Thanks for the prompt reply btw, if nothing else I'm a little more educated on the workings of the DocManager & DocTemplates
Dave
|
|
|
|
|
Hi,
When I try to debug a program with microsoft visual studio and use the "step into" command, it gets into library functions (like for example the function "new") and asks me for the path, while I would like of course to debug only the functions I wrote and that are part of the project.
How can I avoid this?
Thank you
Alex
|
|
|
|
|
|
Simple: Don't "Step In". Use "Step Over".
|
|
|
|
|
It's not so simple. If I have something like this:
ptr = new Myclass();
I want to get into the constructor of Myclass and see what happens, I don't want to debug the code of "new". If I use "step over" I don't see what happens inside the constructor.
Anyway, the Borland 4.52 worked differently. By the way, I tried to run it on windows 2000 and it tells me it cannot find the 32 bit compiler (I set the path). Any idea what's wrong?
Alex
|
|
|
|
|
cnd12001 wrote:
I don't want to debug the code of "new". If I use "step over" I don't see what happens inside the constructor.
Put a breakpoint inside the constructor. Duh.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
I was about to write "put the breakpoint in the constructor" but you beat me too it.
Programmers often forget that "contruction" involves more than just calling MyObject::MyObject() . Stepping into new MyObject() may take you to any number of places before you get to the object constructor. If one isn't careful, clean, and clear on this you can introduce bugs through side effects.
Instead of second guessing the runtime, just put break points on the parts you want to inspect.
|
|
|
|
|
|
Hi People!
I’m trying to start an Anti-spam community project. The general purpose of it is to protect and prevent spam from getting in side of users mailboxes; also I want to be able to trace an original spammer, so it can be punished in one way or in another. If things will work out I also would want to change the identification methods for POP/SMTP science I found that most of the email servers have no identification for sending mail (so you can send spam from any user account on the server, and stay undetected)
So if any of you would like to help me please email me or send a post to this treat, thanks.
Also send any ideas if you have!
Alex,
tech@lrcommunications.net
|
|
|
|
|
tempgp wrote:
I also would want to change the identification methods for POP/SMTP science I found that most of the email servers have no identification for sending mail (so you can send spam from any user account on the server, and stay undetected)
This must be solved, if the server cannot identify itself during the mime transfer then refuse the mime.
Yeah its a good idea....
|
|
|
|
|
Is it a server id?
I don’t think so; it is more user identification process for access… If the server is on MS Server OS w/ Exchange than you can just use firewall like ISA to block any one who is not on AD…
|
|
|
|
|