Click here to Skip to main content
15,910,981 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: XP Style Tab Control? Pin
ritz123414-May-08 0:35
ritz123414-May-08 0:35 
GeneralRe: XP Style Tab Control? Pin
Naveen14-May-08 0:45
Naveen14-May-08 0:45 
GeneralRe: XP Style Tab Control? Pin
ritz123414-May-08 1:09
ritz123414-May-08 1:09 
QuestionHow to get gdi objects associated with a CDC object? Pin
Super Hornet13-May-08 21:50
Super Hornet13-May-08 21:50 
AnswerRe: How to get gdi objects associated with a CDC object? Pin
CPallini13-May-08 22:10
mveCPallini13-May-08 22:10 
AnswerRe: How to get gdi objects associated with a CDC object? Pin
Mark Salsbery14-May-08 7:25
Mark Salsbery14-May-08 7:25 
QuestionSlow DTS package Pin
Member 290588913-May-08 21:05
Member 290588913-May-08 21:05 
QuestionUsing MFC class in a native application [modified] Pin
sabeeshcs13-May-08 20:22
sabeeshcs13-May-08 20:22 
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
#include "Form1.h"
//class marshal_context;
#include

#include
#include
#using



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 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

modified on Wednesday, May 14, 2008 6:32 AM

AnswerRe: Using MFC class in a native application Pin
Nelek13-May-08 21:32
protectorNelek13-May-08 21:32 
AnswerRe: Using MFC class in a native application Pin
Iain Clarke, Warrior Programmer13-May-08 22:00
Iain Clarke, Warrior Programmer13-May-08 22:00 
RantRe: Using MFC class in a native application Pin
toxcct13-May-08 23:24
toxcct13-May-08 23:24 
GeneralRe: Using MFC class in a native application Pin
CPallini13-May-08 23:42
mveCPallini13-May-08 23:42 
GeneralRe: Using MFC class in a native application Pin
toxcct13-May-08 23:43
toxcct13-May-08 23:43 
JokeRe: Using MFC class in a native application Pin
Rajesh R Subramanian14-May-08 1:05
professionalRajesh R Subramanian14-May-08 1:05 
QuestionRe: Using MFC class in a native application Pin
David Crow14-May-08 3:16
David Crow14-May-08 3:16 
QuestionDrawing child controls in MetaFile Pin
sv1413-May-08 20:21
sv1413-May-08 20:21 
AnswerRe: Drawing child controls in MetaFile Pin
ShilpiP13-May-08 21:27
ShilpiP13-May-08 21:27 
GeneralRe: Drawing child controls in MetaFile Pin
sv1413-May-08 23:47
sv1413-May-08 23:47 
GeneralRe: Drawing child controls in MetaFile Pin
ShilpiP14-May-08 1:01
ShilpiP14-May-08 1:01 
GeneralRe: Drawing child controls in MetaFile Pin
sv1414-May-08 18:55
sv1414-May-08 18:55 
QuestionHow Can Get SystemTime? Pin
Le@rner13-May-08 19:45
Le@rner13-May-08 19:45 
AnswerRe: How Can Get SystemTime? Pin
ShilpiP13-May-08 20:01
ShilpiP13-May-08 20:01 
GeneralRe: How Can Get SystemTime? Pin
Le@rner13-May-08 20:09
Le@rner13-May-08 20:09 
GeneralRe: How Can Get SystemTime? [modified] Pin
Le@rner13-May-08 20:18
Le@rner13-May-08 20:18 
GeneralRe: How Can Get SystemTime? Pin
ShilpiP13-May-08 20:46
ShilpiP13-May-08 20:46 

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.