Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

Instantiate NI-Controls inside application

I want to instantiate NI Measurement Studio controls (such as CNiButton) inside my application inside a class which shall be comoon for all controls (MFC and NI), thus being derived from CWnd.

 

Inside this class I am in fact able to instantiate such a control by calling

 

   CreateControl("{D940E4BE-6079-11CE-88CB-0020AF6845F6}", "*",
       WS_VISIBLE | WS_CHILD | WS_BORDER,
       CRect(10, 10, 50, 30),
       m_pParent,
       7654);

where m_pParent is a dialog window. This will display a CNiButton inside the dialog.

 

The problem is now that I cannot access any methods of CNiButton.

 

Attempts like CNiButton *button = dynamic_cast<CNiButton *>(this) fail.

Further attempts with SubclassDlgItem fail, too.

 

Probably GetControlUnknown() could solve the problem but I do not know how to handle this and don't know which parameters to pass to QueryInterface().

 

What can I do? Any hint is welcome.

 

Thank you in advance.

 

Michael

 

 

0 Kudos
Message 1 of 4
(6,783 Views)
Some more information about my problem (btw, I build my application using MSDEV 6.0 SP6) I tried this (inside a class which is derived from CWnd): (...) _DCWButton_CI *p = NULL; CreateControl("{D940E4BE-6079-11CE-88CB-0020AF6845F6}", // CLSID for CWButton "*", WS_VISIBLE | WS_CHILD | WS_BORDER, CRect(10, 10, 50, 30), m_pParent, 7654); LPUNKNOWN lu = this->GetControlUnknown(); // this works and gets a reasonable pointer HRESULT result= lu->QueryInterface(IID__DCWButton_CI, (void **)&p); // THIS FAILS! p is always NULL Any idea? What is wrong. Thank you, best regards, Michael
0 Kudos
Message 2 of 4
(6,775 Views)

Again, so that everyone can read it:

Some more information about my problem (btw, I build my application using MSDEV 6.0 SP6)

 

I tried this (inside a class which is derived from CWnd):

 

(...)

_DCWButton_CI *p = NULL;

 

CreateControl("{D940E4BE-6079-11CE-88CB-0020AF6845F6}", // CLSID for CWButton
  "*",
  WS_VISIBLE | WS_CHILD | WS_BORDER,
  CRect(10, 10, 50, 30),
  m_pParent,
  7654);


 LPUNKNOWN lu = this->GetControlUnknown(); // this works and gets a reasonable pointer

 

 HRESULT result= lu->QueryInterface(IID__DCWButton_CI, (void **)&p); // THIS FAILS! p is always NULL

 

Any idea? What is wrong.

 

Thank you, best regards,

Michael

0 Kudos
Message 3 of 4
(6,774 Views)

Hi Michael,

 

here are a few links that you may find helpful. It seems that they are trying to do about the same thing there.

 

Can I create instances of CWxxx objects?

http://forums.ni.com/ni/board/message?board.id=230&message.id=1886&requireLogin=False

Dynamically Creating/Destroying ComponentWorks Controls in Visual Basic

http://digital.ni.com/public.nsf/websearch/BFF489FE87875A3986256403006F5ECD?OpenDocument

 

How to create a CW control in Visual Studio .NET at run-time (dynamic creation)

http://sine.ni.com/devzone/cda/epd/p/id/3788

 

 I hope that this helps.

 

Best regards,

0 Kudos
Message 4 of 4
(6,726 Views)