Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

How to use CNiGraph without using resources to create of object

Hello,
I'm using Measurement Studio 6.0 for Visual C++  (Component Works)
I would like to use a CNiGraph object in my MFC application (Visual 6) and i would like to manipulate this object as an usual window (CWnd).
I'm not using dialog based windows. The parent window of the CNiGraph Window will be a usual CWnd.
So I think I need to create the right object using the right CLSID and CoCreateInstance( ) and then query the right interface using right IID with QueryInterface( ) to finaly cast resulting pointer to CNiGraph class.
Then I can use methods and properties of CNiGraph.
 
1) Is this possible ? (to not use resources mecanisme)
 
2) What is the CLSID of the object (Is it the coclass CWGraph from OLE/COM Object Viewer ?)
 
3) What is the IID of CNiGraph Interface (Is it _DCWGraph one from OLE/COM Object Viewer ? , what means dispinterface ?)
 
4) Where can I found code doing all that
 
5) Where can I found code using events (As I don't know so much about this last one, Must I use _DCWGraphEvents Interface ?)
 
Please Help .....
 
0 Kudos
Message 1 of 2
(6,594 Views)

Okay, as finally I managed myself to find the answer I publish it in case it finally interests someone.

 

1) Yes it is possible to create NI object ActiveX programmatically without using visual resource editor. However the most appropriate way of doing that is not directly using underlying COM Api but OLE support within MFC and in particular CWnd class. Actually  CNiGraph class is rather integrated is such way. Therefore  here are the very few magic code lines:


int CChildView::OnCreate(LPCREATESTRUCT lpCreateStruct)

{

   if (CWnd ::OnCreate(lpCreateStruct) == -1)

      return -1;

 

   CLSID clsid = CNiGraph::GetClsid();

   if (!m_NiGraph.CreateControl(clsid, NULL, WS_VISIBLE, CRect(0,0,300,300), this, 1))

      return -1;

 

   return 0;

}

where m_NiGrah is a CNiGraph member of CChildView

 

NOTE: online reference documentation is incorrect as CNiGraph::GetClsid( ) and CNiGraph::CreateControl( ) are documented as protected method while they are public.

 

2) Yes the CLSID is the coclass CWGraph from OLE/COM Object Viewer. However the most appropriate way to get it is using static function CNiGraph::GetClsid(); As described in 1)

 

NOTE: online reference documentation is incorrect as CNiGraph::GetClsid( ) and CNiGraph::CreateControl( ) are documented as protected method while they are public.

 

3) Lets say that underlying interface is _DCWGraph implementing the COM standard IDispatch interface. Actually it is not required to have this information as CNiGraph wrapper do the job (see 1) code sample, QueryInterface( ) is not required)

 

4) See 1)

 

5) Event are used quite like usual MFC controls notifications excepted it uses underlying COM EventSink mecanisms. But once again all necessary standard wrappers and macros to ease implementation are available.  The equivalent of the usual MESSAGE_MAP is the EVENTSINK_MAP. The most appropriate way to get the related needed information (like event dispatch Ids (equivalent of notification Ids), handler function prototype and parameter type descriprions) is to create a dummy dialog based project and to insert the control in the dialog box resources. Then using Visual studio facility to add message map handlers (through class wizard for example), the skeleton code with all necessary information to handle the event is automatically produced in h and cpp file of the dialog box. Finally just copy past it in the real project parent class window to get same behaviour.

That's it

 

0 Kudos
Message 2 of 2
(6,570 Views)