Click here to Skip to main content
15,920,217 members
Home / Discussions / Managed C++/CLI
   

Managed C++/CLI

 
QuestionHaving problems with autoscroll Pin
BuckBrown14-May-08 9:33
BuckBrown14-May-08 9:33 
Questionthreading problem Pin
Adnan Merter14-May-08 6:56
Adnan Merter14-May-08 6:56 
AnswerRe: threading problem Pin
led mike14-May-08 11:47
led mike14-May-08 11:47 
GeneralRe: threading problem Pin
Adnan Merter14-May-08 13:09
Adnan Merter14-May-08 13:09 
GeneralRe: threading problem Pin
led mike15-May-08 5:43
led mike15-May-08 5:43 
QuestionLink list Pin
Ali Rahimei14-May-08 0:10
Ali Rahimei14-May-08 0:10 
AnswerRe: Link list Pin
led mike14-May-08 4:17
led mike14-May-08 4:17 
QuestionUsing MFC class in a native application Pin
sabeeshcs13-May-08 20:20
sabeeshcs13-May-08 20:20 
Hi,
I had develop some MFC calss and that program is working properly. Now I am decided to integrate my MFC class with .NET (C++/CLI).
My requirement is that, I want to use the same MFC class in my C++/CLI Program with out any changes. I can do it like this, I create a .dll file using the same MFC calss in load that .dll file into my C++/CLI ( CLR ) project and create an object using that .dll file and it is working. But I am not satisfied in this methord. Because, through this method, we want to keep a lot of .dll file ( for each class we need to create .dll file and load that .dll file in to my new project ). So I am trying for another method. So I made changes in my mfc project settings and inherit the mfc class in my native class and create an object using the new native calss and i can load the MFC class in my native class and I can call the functions from my native object. But in my MFC class there has a function OnCreate(LPCREATESTRUCT lpCreateStruct). in that function I had do some steps. I can't call that function through the native call. Can you help me to solve this problem?
My aim is using my existing MFC class, I want to create a create a native application ( C++/CLI )

my source code is like this,

MFC class
MyTreeView.h

class CFpiTreeView : public CView
{
protected:
/////CFpiTreeView(); // Dynamische Erstellung verwendet geschützten Konstruktor //Commented by sabeesh
DECLARE_DYNCREATE(CFpiTreeView)

// Attribute
public:
CFpiTreeView(); // Dynamische Erstellung verwendet geschützten Konstruktor
virtual ~CFpiTreeView(); //Added by sabeesh

CTreeCtrl m_Tree;
CStatic m_Logo;
HBITMAP m_hBtmLogo;

void SetTreeItemText(HTREEITEM ti, CString NewText);

//// CMainFrame *m_pParent; //Commented by sabeesh

// Operationen
public:

// Überschreibungen
// Vom Klassen-Assistenten generierte virtuelle Funktionsüberschreibungen
//{{AFX_VIRTUAL(CFpiTreeView)
protected:
virtual void OnDraw(CDC* pDC); // Überschrieben zum Zeichnen dieser Ansicht
virtual BOOL OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult);
//}}AFX_VIRTUAL

void Selchanged(NMHDR* pNMHDR, LRESULT* pResult);

// Implementierung
//protected: //Commented by sabeesh
// virtual ~CFpiTreeView(); //Commented by sabeesh
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif

// Generierte Nachrichtenzuordnungsfunktionen
///protected:
public:
//{{AFX_MSG(CFpiTreeView)
void Test();
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnSize(UINT nType, int cx, int cy);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};


MyTreeView.cpp



#include "stdafx.h"
///#include "FpiTreeControl.h"
#include "FpiTreeView.h"

using namespace System;
using namespace System::Windows;
using namespace System::Windows::Forms;

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

#define TREEID 1000

/////////////////////////////////////////////////////////////////////////////
// CFpiTreeView

IMPLEMENT_DYNCREATE(CFpiTreeView, CView)

/////CFpiTreeView::CFpiTreeView():m_pParent(NULL)
CFpiTreeView::CFpiTreeView()
{
MessageBox::Show(L"Create CFpiTreeView");
//IMPLEMENT_DYNCREATE(CFpiTreeView, CView) ;

//m_Tree.InsertItem("Grafische Darstellung");

// m_Tree.Create(WS_CHILD | WS_VISIBLE | TVS_SHOWSELALWAYS | TVS_HASBUTTONS | TVS_LINESATROOT | TVS_DISABLEDRAGDROP | TVS_HASLINES, r, this, TREEID);
/* m_Tree.SetBkColor(RGB(0, 255, 0));
m_Tree.InsertItem("Grafische Darstellung");
ti = m_Tree.InsertItem("Projektstammdaten");
m_Tree.InsertItem("Eckdaten", ti);
m_Tree.InsertItem("Hinweise", ti);
ti = m_Tree.InsertItem("Kosten Bau");
m_Tree.InsertItem("Übersicht und Verteilung der Gesamtkosten", ti);
m_Tree.InsertItem("Zusammenstellung der Kosten", ti);
*/


/// m_hBtmLogo = (HBITMAP)LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BTM));
}

CFpiTreeView::~CFpiTreeView()
{
DeleteObject(m_hBtmLogo);
}


BEGIN_MESSAGE_MAP(CFpiTreeView, CView)
//{{AFX_MSG_MAP(CFpiTreeView)
ON_WM_CREATE()
ON_WM_SIZE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// Zeichnung CFpiTreeView

void CFpiTreeView::OnDraw(CDC* pDC)
{
MessageBox::Show(L"OnDraw");
RECT r, r2;
CPen *pOldPen, pen;
CBrush *pOldBrush, brush;

pen.CreatePen(PS_SOLID, 0, RGB(255, 0, 0));
brush.CreateSolidBrush(RGB(255, 0, 0));

GetClientRect(&r);
m_Logo.GetClientRect(&r2);
r.bottom = r2.bottom + 10;

pOldPen = pDC->SelectObject(&pen);
pOldBrush = pDC->SelectObject(&brush);
pDC->Rectangle(r.left, r.top, r.right, r.bottom);
pDC->SelectObject(pOldPen);
pDC->SelectObject(pOldBrush);
}

/////////////////////////////////////////////////////////////////////////////
// Diagnose CFpiTreeView

#ifdef _DEBUG
void CFpiTreeView::AssertValid() const
{
CView::AssertValid();
}

void CFpiTreeView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
#endif //_DEBUG


/////////////////////////////////////////////////////////////////////////////
// Behandlungsroutinen für Nachrichten CFpiTreeView


int CFpiTreeView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
MessageBox::Show(L"OnCreate");
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;

RECT r;
HTREEITEM ti;

r.left = r.top = 0;
r.right = 100;
r.bottom = 100;
m_Logo.Create("", WS_CHILD | WS_VISIBLE | SS_BITMAP, r, this, 18);
m_Logo.SetBitmap(m_hBtmLogo);

r.right = 100;
r.bottom = 100;
m_Tree.Create(WS_CHILD | WS_VISIBLE | TVS_SHOWSELALWAYS | TVS_HASBUTTONS | TVS_LINESATROOT | TVS_DISABLEDRAGDROP | TVS_HASLINES, r, this, TREEID);
m_Tree.SetBkColor(RGB(0, 255, 0));
m_Tree.InsertItem("Grafische Darstellung");
ti = m_Tree.InsertItem("Projektstammdaten");
m_Tree.InsertItem("Eckdaten", ti);
m_Tree.InsertItem("Hinweise", ti);
ti = m_Tree.InsertItem("Kosten Bau");
m_Tree.InsertItem("Übersicht und Verteilung der Gesamtkosten", ti);
m_Tree.InsertItem("Zusammenstellung der Kosten", ti);


return 0;
}

void CFpiTreeView::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType, cx, cy);

RECT r;

int Diff;
m_Logo.GetClientRect(&r);
Diff = r.right - r.left;
r.left = (cx - r.right + r.left) / 2;
r.right = r.left + Diff;
m_Logo.MoveWindow(&r);
r.top = r.bottom = r.bottom + 10;

r.left = 0;
r.right = cx;
if (cy > r.bottom)
r.bottom = cy;
m_Tree.MoveWindow(&r);
}

BOOL CFpiTreeView::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
if (wParam == TREEID)
{
NMHDR *pNMHDR = (NMHDR*)lParam;
if (pNMHDR->code == TVN_SELCHANGED)
Selchanged(pNMHDR, pResult);
}

return CView::OnNotify(wParam, lParam, pResult);
}

void CFpiTreeView::Selchanged(NMHDR* pNMHDR, LRESULT* pResult)
{
// m_pParent->Selchanged(((NM_TREEVIEW*)pNMHDR)->itemNew.hItem, m_Tree.GetItemText(((NM_TREEVIEW*)pNMHDR)->itemNew.hItem)); //Commented by sabeesh
//*pResult = 0; //Commented by sabeesh
}

void CFpiTreeView::SetTreeItemText(HTREEITEM ti, CString NewText)
{
m_Tree.SetItemText(ti, NewText);
}




MainForm.h

// MainFrm.h : interface of the CMainFrame class
//


#pragma once

#include "ChildView.h"
#include "FpiTreeView.h"
//#include <msclr\marshal.h>
#include "Form1.h"
//class marshal_context;
#include <vcclr.h>

#include <windows.h>
#include <vcclr.h>
#using <system.dll>



using namespace System;
using namespace System::Windows;
using namespace System::Windows::Forms;



//TreeViewT::TreeViewT()
//{
// CFpiTreeView* treeview = new CFpiTreeView() ;
//}

public ref class MClass : public TreeView
{
public:
MClass() : m_Impl( new CFpiTreeView ) {}

public:
CFpiTreeView * m_Impl;
};



public ref class MyForm : public Form
{
private:

public:
MClass^ tree;
System::ComponentModel::Container ^components;

public:
MyForm(void)
{

tree = gcnew MClass();
tree->Width = 400;
tree->Height = 300;
this->Width=450;
this->Height=400;


this->Controls->Add(tree);


}
// ~MyForm();

private:
//void InitializeComponent1();
};

class CMainFrame : public CFrameWnd
{

public:
CMainFrame();
protected:
DECLARE_DYNAMIC(CMainFrame)

// Attributes
public:
//CWinFormsControl<project3::form1> pform1;
// Operations
public:

// Overrides
public:
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
virtual BOOL OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo);

// Implementation
public:
virtual ~CMainFrame();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif

protected: // control bar embedded members
CStatusBar m_wndStatusBar;
CToolBar m_wndToolBar;
CChildView m_wndView;

// Generated message map functions
protected:
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnSetFocus(CWnd *pOldWnd);
DECLARE_MESSAGE_MAP()
};


MainForm.cpp

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
MyForm^ myfrm = gcnew MyForm();
myfrm->Show();

}


using this code, The tree view is created. But the node values, in
int CFpiTreeView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
MessageBox::Show(L"OnCreate");
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;

RECT r;
HTREEITEM ti;

r.left = r.top = 0;
r.right = 100;
r.bottom = 100;
m_Logo.Create("", WS_CHILD | WS_VISIBLE | SS_BITMAP, r, this, 18);
m_Logo.SetBitmap(m_hBtmLogo);

r.right = 100;
r.bottom = 100;
m_Tree.Create(WS_CHILD | WS_VISIBLE | TVS_SHOWSELALWAYS | TVS_HASBUTTONS | TVS_LINESATROOT | TVS_DISABLEDRAGDROP | TVS_HASLINES, r, this, TREEID);
m_Tree.SetBkColor(RGB(0, 255, 0));
m_Tree.InsertItem("Grafische Darstellung");
ti = m_Tree.InsertItem("Projektstammdaten");
m_Tree.InsertItem("Eckdaten", ti);
m_Tree.InsertItem("Hinweise", ti);
ti = m_Tree.InsertItem("Kosten Bau");
m_Tree.InsertItem("Übersicht und Verteilung der Gesamtkosten", ti);
m_Tree.InsertItem("Zusammenstellung der Kosten", ti);


return 0;
}

is not created. How can I call this function?
Please help me
Thank you in Advance

Sabi
AnswerRe: Using MFC class in a native application Pin
Mark Salsbery14-May-08 7:35
Mark Salsbery14-May-08 7:35 
GeneralRe: Using MFC class in a native application Pin
sabeeshcs14-May-08 22:52
sabeeshcs14-May-08 22:52 
QuestionHow do you reset the bounds when scaling a Matrix object Pin
BuckBrown13-May-08 10:53
BuckBrown13-May-08 10:53 
AnswerRe: How do you reset the bounds when scaling a Matrix object Pin
led mike14-May-08 4:23
led mike14-May-08 4:23 
QuestionSystem.AccessViolationException when accessing a wrapped member Pin
MikeG200013-May-08 6:40
MikeG200013-May-08 6:40 
AnswerRe: System.AccessViolationException when accessing a wrapped member Pin
MikeG200013-May-08 6:46
MikeG200013-May-08 6:46 
Questioncommon variables Pin
Adnan Merter13-May-08 4:13
Adnan Merter13-May-08 4:13 
AnswerRe: common variables Pin
leonigah13-Jun-08 0:30
leonigah13-Jun-08 0:30 
Questiontext change Pin
rose19612-May-08 20:07
rose19612-May-08 20:07 
AnswerRe: text change Pin
leonigah13-Jun-08 0:33
leonigah13-Jun-08 0:33 
QuestionTooltip with StatusStripLabel Pin
TheBerk12-May-08 8:20
TheBerk12-May-08 8:20 
QuestionRe: Tooltip with StatusStripLabel Pin
TheBerk13-May-08 3:20
TheBerk13-May-08 3:20 
Questionshockwawe flash movie Pin
Adnan Merter12-May-08 5:37
Adnan Merter12-May-08 5:37 
QuestionRe: shockwawe flash movie Pin
Mark Salsbery12-May-08 6:18
Mark Salsbery12-May-08 6:18 
AnswerRe: shockwawe flash movie Pin
Adnan Merter12-May-08 6:21
Adnan Merter12-May-08 6:21 
GeneralRe: shockwawe flash movie Pin
Mark Salsbery12-May-08 6:26
Mark Salsbery12-May-08 6:26 
Questionuse NTL package with vc++.net Pin
Member 412558412-May-08 0:27
Member 412558412-May-08 0:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.