Solved

ActiveX control and CWnd

Posted on 1998-10-19
8
775 Views
Last Modified: 2013-11-20
I know the steps to insert an ActiveX control to a dialog

base app,but how can i programly create an ActiveX control

in CWnd object?
0
Comment
Question by:zxw
  • 5
  • 2
8 Comments
 
LVL 7

Expert Comment

by:psdavis
ID: 1323541
I have it at work and will check back if no-one answers.

Remember, the ActiveX control is derived from CWnd and you can just create the control with CWnd::Create just like you would do it with an edit box or a button.

Phillip
0
 

Accepted Solution

by:
linyf earned 50 total points
ID: 1323542
To create an ActiveX control in CWnd object,just call CWnd member function:

BOOL CWnd::CreateControl( LPCTSTR lpszClass, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CFile* pPersist = NULL, BOOL bStorage = FALSE, BSTR bstrLicKey = NULL );

BOOL CWnd::CreateControl( REFCLSID clsid, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CFile* pPersist = NULL, BOOL bStorage = FALSE, BSTR bstrLicKey = NULL );


0
 
LVL 7

Expert Comment

by:psdavis
ID: 1323543
Thanks linyf. I've been using Create all this time and CreateControl is definitely more correct.  

zxw, Create the control inside your CView::OnInitialUpdate.

Phillip
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 7

Expert Comment

by:psdavis
ID: 1323544
Ahhh.. The confusion is gone!

When you add the control to your project, the control will create a header file for you.  The CreateControl function is called by the Create function.  So we're both right!

virtual BOOL Create(LPCTSTR lpszClassName,
  LPCTSTR lpszWindowName, DWORD dwStyle,
  const RECT& rect,
  CWnd* pParentWnd, UINT nID,
  CCreateContext* pContext = NULL)
{
  return CreateControl(GetClsid(), lpszWindowName, dwStyle, rect, pParentWnd, nID); }

// And how I do my create function!

m_pMyControl->Create( NULL, NULL, WS_VISIBLE, rcClient, pWnd, IDC_MY_CONTROL );

Phillip
0
 

Author Comment

by:zxw
ID: 1323545
I did as Mr. Phillip said, and complied with no error, but when i run the program there still is no

control on the CWnd object, why?
0
 
LVL 7

Expert Comment

by:psdavis
ID: 1323546
Gotta show the code!
0
 

Author Comment

by:zxw
ID: 1323547
I have an ActiveX control named GVBox that shows gif files, i want to put it into the MFC Sample project provided by VC5.0 named saver(screen saver example), and following
the codes i added,

CGvbox* m_pGIFBox;

int CDrawWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
      if (CWnd::OnCreate(lpCreateStruct) == -1)
            return -1;
      
      int nSpeed = AfxGetApp()->GetProfileInt("Config", "Speed", 1);
      if (nSpeed < 0)
            nSpeed = 0;      
      SetSpeed(nSpeed);

      CRect r(10,10,100,100);
      m_pGIFBox = new CGvbox;
                      ASSRT(m_pGIFBox->Create(_T(""),WS_CHILD|WS_VISIBLE,r,this,IDC_GVBOXCTRL1));
                  m_pGIFBox->Set_FileName(_T("d:\\temp\\mail.gif"));
                  m_pGIFBox->SetEnabled(TRUE);

      return 0;
}
0
 
LVL 7

Expert Comment

by:psdavis
ID: 1323548
Remeber my first comment, put it in OnInitialUpdate...

Why are you bothering with the pointer and the new?

Go ahead and make life easy on ya...

Add to your CDrawWnd header file:

CGVBox m_GIFBox;

and put in your OnInitialUpdate

m_GIFBox.Create( _T( "" ), WS_CHILD | WS_VISIBLE, CRect( 10, 10, 100, 100 ), this, IDC_GVBOXCTRL1 ));

MUCH cleaner and you won't have to worry about the deleting!

Phillip



0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question