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:
BOOL CAM_TerraFormApp::InitInstance()
{
CWinApp::InitInstance();
return TRUE;
}
I am using this code from MSDN:
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:
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:
#include "stdafx.h"
#include "AM_TerraForm.h"
#include "AM_TerraFormDialog.h"
IMPLEMENT_DYNAMIC(AM_TerraFormDialog, CDialog)
AM_TerraFormDialog::AM_TerraFormDialog(CWnd* pParent )
: 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)
{
*pResult = 0;
}
void AM_TerraFormDialog::OnBnClickedButton1()
{
}
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.