Click here to Skip to main content
16,021,430 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I'm trying to port an app from VB.NET to VC++.NET 2005. It is actually going to be a plug in. I have written the code that will open the window in the host app. Obviously, I need to start adding controls and their associated code.

I have a Tab Control that I need to create tabs for. The Tab control is named IDC_PREVIEW and I have attchaed a variable named m_Preview. It seems to me that the place to create the tabs would be here in AM_TerraForm.cpp:

C++
// CAM_TerraFormApp initialization

BOOL CAM_TerraFormApp::InitInstance()
{
    CWinApp::InitInstance();

    return TRUE;
}


I am using this code from MSDN:

C++
TCITEM tcItem;
tcItem.mask = TCIF_TEXT;
tcItem.pszText = _T("Topographic Map");
m_Preview.InsertItem(0, &tcItem);


This is the only place I can find that seems to indicate any kind of initilization but the code doesn't work because it doesn't recognize m_Preview, the variable attached to the Tab control. However, if I use the same code in a button's OnBnClicked() event it works.

Where am I going off course?

UPDATE 9/1:
Ok, after some searching in the SDK there is a file called Misc.h. Here is a snippet that I think may solve the problem:

C++
class CPluginDialog : public CDialog
{
public:
   CPluginDialog() {}
	CPluginDialog(UINT nIDTemplate, CWnd* pParentWnd = NULL) : CDialog( nIDTemplate, pParentWnd ) {}
   virtual ~CPluginDialog() {}

	virtual void PreSubclassWindow() { CDialog::PreSubclassWindow(); }
	virtual WNDPROC* GetSuperWndProcAddr() { return CDialog::GetSuperWndProcAddr(); }
	virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam) { return CDialog::WindowProc( message, wParam, lParam ); }
	virtual BOOL OnWndMsg(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pResult) { return CDialog::OnWndMsg( message,  wParam,  lParam, pResult ); }
	virtual LRESULT DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam) { return CDialog::DefWindowProc( message, wParam, lParam ); }
	virtual void PreInitDialog() { CDialog::PreInitDialog(); }
	virtual CRuntimeClass* GetRuntimeClass() const { return CDialog::GetRuntimeClass(); }
	virtual BOOL OnInitDialog() { return CDialog::OnInitDialog(); }
	virtual BOOL OnCommand(WPARAM wParam, LPARAM lParam) { return CDialog::OnCommand( wParam, lParam ); }
	virtual BOOL OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult) { return CDialog::OnNotify( wParam, lParam, pResult ); }
	virtual BOOL CheckAutoCenter() { return CDialog::CheckAutoCenter(); }
	virtual BOOL OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo) { return CDialog::OnCmdMsg( nID, nCode, pExtra, pHandlerInfo); }
	virtual BOOL PreTranslateMessage(MSG* pMsg) { return CDialog::PreTranslateMessage( pMsg ); }
	virtual BOOL ContinueModal() { return CDialog::ContinueModal(); }
	virtual void EndModalLoop(int nResult) { CDialog::EndModalLoop( nResult ); }
	virtual BOOL IsFrameWnd() const { return CDialog::IsFrameWnd(); }
	virtual BOOL DestroyWindow() { return CDialog::DestroyWindow(); }
	virtual void PostNcDestroy() { CDialog::PostNcDestroy(); }
	virtual void DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange( pDX ); }
	virtual void OnOK() { CDialog::OnOK(); }
	virtual void OnCancel() { CDialog::OnCancel(); }
};


I can see that there is an OnInitDialog(). I think it I probably need to use it in this file:

C++
// AM_TerraFormDialog.cpp : implementation file
//

#include "stdafx.h"
#include "AM_TerraForm.h"
#include "AM_TerraFormDialog.h"


// AM_TerraFormDialog dialog

IMPLEMENT_DYNAMIC(AM_TerraFormDialog, CDialog)

AM_TerraFormDialog::AM_TerraFormDialog(CWnd* pParent /*=NULL*/)
	: CDialog(AM_TerraFormDialog::IDD, pParent)
{

}

AM_TerraFormDialog::~AM_TerraFormDialog()
{

}

void AM_TerraFormDialog::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_PREVIEW, m_Preview);
}


BEGIN_MESSAGE_MAP(AM_TerraFormDialog, CDialog)

	ON_NOTIFY(TCN_SELCHANGE, IDC_PREVIEW, &AM_TerraFormDialog::OnTcnSelchangeTab1)
	ON_BN_CLICKED(IDC_BUTTON1, &AM_TerraFormDialog::OnBnClickedButton1)

END_MESSAGE_MAP()

void AM_TerraFormDialog::OnTcnSelchangeTab1(NMHDR *pNMHDR, LRESULT *pResult)
{
	// TODO: Add your control notification handler code here
	*pResult = 0;
}

void AM_TerraFormDialog::OnBnClickedButton1()
{
	// TODO: Add your control notification handler code here
}


What I can't figure out is how to use it. If I try BOOL CPluginDialog::OnInitDialog() I get an error saying that that a body already exists and if I use BOOL OnInitDialog() it doesn't give me an error but it also does nothing. For example, if I try to display a message box it doesn't appear.
Posted
Updated 2-Sep-12 12:15pm
v3
Comments
[no name] 29-Aug-12 4:28am    
Where is m_Preview defined?
AlphaScorpious 30-Aug-12 1:01am    
There is no CreateWindow() or InitDialog() function in any of the files.

The form of the MFC app? It's an MFC DLL for a plugin for a 3D Animation app. Here is a link to the tutorial I created a few years ago for creating a plugin called Empty:

http://www.tachyonthunder.com/tutorials/am/sdk/empty/

Essentially, all it does is open a windows dialog via a plugin selection menu from the 3D app's modeling window. All I have done at this point is create the "empty" shell and called it AM TerraForm instead of Empty and I'm trying to place and initialize all the controls.

This line in the code posted above (m_Preview.InsertItem(0, &tcItem);) was giving me build errors because m_Preview was not recognized.

Changing the line to: AM_TerraFormDialog().m_Preview.InsertItem(0, &tcItem); did not give build errors but did give me an assertion error when the 3D app tried to load the plugin.


A link to screen shots of the stand alone VB.NET version is here:
http://www.tachyonthunder.com/software/amterraform/

1 solution

The app class is the wrong place to setup window controls.

You haven;t provided any information as to the form that your MFC app is in but I can still give some general advice.

If your app has a dialog frame, then put the initialization in InitDialog()

If instead your app has a main window, then put it in CreateWindow() near the return statement.

And I think this is what Richard is getting at. The initialization needs to be done in the window that owns the control.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900