|
Hi,
does anyone know if there are deprecated headers and other files in
\Microsoft Visual Studio\VC98\INCLUDE\ ?
After my project mates and I were updating code to VC++ 7.0 standards and specifically the inclusion of <fstream> and "std::ofstream" and "std::ifstream", when I compile in VC++ 6.0 I get a lot of warnings with files in the above folder.
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xmemory(39) : warning C4100: '_P' : unreferenced formal parameter
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xmemory(41) : warning C4100: '_P' : unreferenced formal parameter
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xlocale(296) : warning C4663: C++ language change: to explicitly specialize class template 'codecvt' use the following syntax:
template<> class codecvt<unsigned short,char,int=""> ...
These are only three, but all seem to come from the \VC98\INCLUDE
Can anyone help or point me to references where VC++ 6.0 and "standard C++" may have been updated?
Thank you so much.
Johnny
|
|
|
|
|
How can I use functions and member variables from one dialog's class in the message handler of another dialog (in MFC)?
For example:
I have two dialogs, with classes CDlg1 & CDlg2. CDlg1 has a tab control and some generic function. CDlg2 (modeless) has a button control.
CDlg1.h looks like:
#include "Dlg2.h"
class CDlg1 : public CDialog
{
public:
CDlg1(CWnd* pParent = NULL); // Constructor
CDlg2 m_dlg2; // To create modeless in "Dlg1.cpp"
void function(); // Generic function in "Dlg1.cpp"
// Dialog Data
//{{AFX_DATA(CDlg1)
enum { IDD = IDD_DIALOG1 };
CTabCtrl m_tab; // Tab Control member variable
//}}AFX_DATA
// Overrides
//{{AFX_VIRTUAL(CDlg1)
protected:
virtual void DoDataExchange(CDataExchange* pDX);
//}}AFX_VIRTUAL
// Implementation
protected:
HICON m_hIcon;
// Generated message map functions
//{{AFX_MSG(CDlg1)
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CDlg2.h looks like:
class CDlg2 : public CDialog
{
public:
CDlg2(CWnd* pParent = NULL); // Constructor
// Dialog Data
//{{AFX_DATA(CDlg2)
enum { IDD = IDD_DIALOG2 };
//}}AFX_DATA
// Overrides
//{{AFX_VIRTUAL(CDlg2)
protected:
virtual void DoDataExchange(CDataExchange* pDX);
//}}AFX_VIRTUAL
// Implementation
protected:
// Generated message map functions
//{{AFX_MSG(CDlg2)
afx_msg void OnButton();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
In the message handler for the 2nd dialog's button, I want to call the function from CDlg1 & get info from the 1st dialog's tab control (GetCurSel() or whatever).
**** From CDlg2::OnButton() in "Dlg2.cpp", how do I call function()???? ****
Just calling "function();" alone gives me the old "undeclared identifier" shiznat.
And what's the best way to control m_tab? The following seems to work, but it seems it bit messy to me:
CTabCtrl* m_tabPtr = (CTabCtrl*) GetParentOwner()->GetDlgItem(IDC_TAB);
int nCurTabSel = m_tabPtr->GetCurSel();
When I try to derive CDlg2 from CDlg1, all hell breaks loose (operator error, I'm certain) and I can't seem to make "friend" work either. Am I even barking up the right tree?
Thanks,
-Chris, the MFC newb
|
|
|
|
|
In CDlg2, make a constructor that also accepts a pointer to a CDlg1 object, so that if CDlg1 calls the constructor for CDlg2, do it like this:
Cdlg2 dlg(this);
have the overloaded constructor put whatever was sent in in a member variable of type CDlg1 (m_pDlg1 = pDlg);
Also remember you don't have to include CDlg1.h in your CDlg2.h file, just put a forward declaration for CDlg1 before your class definition for CDlg2 like this:
class CDlg1;
class CDlg2 : public CDialog
{
//declare class attributes
}
hope I helped, if not let me know and i'll cut and paste you an actual piece of working code like that. Also, don't forget to make the function you're calling public or put CDlg2 in CDlg2's class definition as a friend class.
If it's broken, I probably did it
bdiamond
|
|
|
|
|
Thank you for your help -- I didn't know about the forward declaration, that sheds quite a bit of light on things.
But I can't seem to get the CDlg2 constructor right. Do I replace the standard constructor:
CDlg2(CWnd* pParent = NULL);
or just add to it? (Sorry, I'm an old hand at C, but fairly new to C++.)
And in your example, where is pDlg declared?
Thanks again!
-Chris
|
|
|
|
|
Why don't you just try passing in a pointer to CDlg1 from the constructor of CDlg2. That should take care of your tab control problem as well since you'd just be able to simply reference it. int nCurSel = pDlg1->m_tab.GetCurSel ()
- monrobot13
|
|
|
|
|
monrobot13 wrote:
try passing in a pointer to CDlg1 from the constructor of CDlg2
Forgive my ignorance, but how do I do that (syntax-wise)?
Cheers
|
|
|
|
|
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
|
|
|
|
|