Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

HI Problem With ActiveX control In WIN32 Applications

Posted on 2000-04-28
6
Medium Priority
?
292 Views
Last Modified: 2013-12-03
Hi all,
     I have the same problem as user sudhaom. When a dialog box with  an activex control is called it is not being shown.
How activex controls are used with WIN32 applications.

0
Comment
Question by:austin123
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 2

Expert Comment

by:WDB
ID: 2759593
The following outline describes the steps that need to be taken to create a Non-MFC C++ application that can contain ActiveX/COM controls and how to go about accessing those controls.

Add following lines to stdafx.h:
  #include <atlbase.h>
  extern CComModule _Module;
  #include <atlcom.h>
  #include <atlhost.h>

Add Following logic to main .cpp file:
At top:
  CComModule _Module;

At beginning of WinMain:
  _Module.Init(NULL,hInstance);
  AtlAxWinInit();

At the end of WinMain:
   _Module.Term()

#import the proper .dll,.ocx for the control you want to access and make sure to include the following options for the #import - raw_interfaces_only, raw_native_types, no_namespace, named_guids

// To Access An Object
1. Use the ATL CComPtr<> Template Class to Create An Instance Of The Interface.
      CComPtr<ISomething> pObject;
NOTE: ISomething is the interface we want access to. "Something" will be the actual name of the COM interface.

2. Use the GetDlgControl() API to obtain a handle to the control you have placed in your dialog and fill pObject with it's contents.
GetDlgControl(IDC_SOMETHING,IID_ISomething, (void **)&pObject);
NOTE: IDC_SOMETHING will be the control ID defined in your dialog, IID_ISomething will be the named guid of the interface we are obtaining.

3. Use the interface.
   pObject->SomeMethod1();
   pObject->SomeMethod2();
    ...


Here is an example of a Class that we could use to access an ACTIVEX/COM object from within a dialog. All classes that we create to do this should resemble this format:

#ifndef __NEWDLG_H_
#define __NEWDLG_H_

#include "resource.h"       // main symbols
#include <atlhost.h> // ALLOWS HOSTING OF COM/ACTIVEX CONTROLS IN DIALOG
#import "SomeDllOrOcx" raw_interfaces_only, raw_native_types, no_namespace, named_guids  

/////////////////////////////////////////////////////////////////////////////
// CNewDlg
class CNewDlg :
public CAxDialogImpl<CNewDlg> // USE THE ATL CAxDialogImpl Template Class
{
public:
CNewDlg() // Constructer()
{
}

~CNewDlg() // Destructer()
{
}

BEGIN_MSG_MAP(CNewDlg)
MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
COMMAND_ID_HANDLER(IDOK, OnOK)
COMMAND_ID_HANDLER(IDCANCEL, OnCancel)
      ...
      // CUSTOM CONTROL HANDLERS
COMMAND_HANDLER(IDC_MYBUTTON, BN_CLICKED, OnClickedMybutton)
      ...
END_MSG_MAP()

// Handler prototypes:
//  LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);

//  LRESULT CommandHandler(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);

//  LRESULT NotifyHandler(int idCtrl, LPNMHDR pnmh, BOOL& bHandled);

    LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
return 1;  // Let the system set the focus
}

LRESULT OnOK(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
EndDialog(wID);
return 0;
}

LRESULT OnCancel(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
EndDialog(wID);
return 0;
}
public :

BEGIN_SINK_MAP(CNewDlg)
//Make sure the Event Handlers have __stdcall calling convention
END_SINK_MAP()

      // EXAMPLE OF ACCESSING OF A CONTROL
LRESULT OnClickedMybutton(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
CComPtr<ISomething> pObject;
GetDlgControl(IDC_SOMEID,IID_ISomething, (void **)&pObject);
pObject->SomeMethod1();
pObject->SomeMethod2();
pObject->SomeMethod3();
return 0;
}
};

#endif //__NEWDLG_H_
0
 
LVL 2

Expert Comment

by:WDB
ID: 2759601
Sorry,
  I meant to originally post this as an answer.

The following outline describes the steps that need to be taken to create a Non-MFC C++ application that can contain ActiveX/COM controls and how to go about accessing those controls.

Add following lines to stdafx.h:
  #include <atlbase.h>
  extern CComModule _Module;
  #include <atlcom.h>
  #include <atlhost.h>

Add Following logic to main .cpp file:
At top:
  CComModule _Module;

At beginning of WinMain:
  _Module.Init(NULL,hInstance);
  AtlAxWinInit();

At the end of WinMain:
   _Module.Term()

#import the proper .dll,.ocx for the control you want to access and make sure to include the following options for the #import - raw_interfaces_only, raw_native_types, no_namespace, named_guids

// To Access An Object
1. Use the ATL CComPtr<> Template Class to Create An Instance Of The Interface.
      CComPtr<ISomething> pObject;
NOTE: ISomething is the interface we want access to. "Something" will be the actual name of the COM interface.

2. Use the GetDlgControl() API to obtain a handle to the control you have placed in your dialog and fill pObject with it's contents.
GetDlgControl(IDC_SOMETHING,IID_ISomething, (void **)&pObject);
NOTE: IDC_SOMETHING will be the control ID defined in your dialog, IID_ISomething will be the named guid of the interface we are obtaining.

3. Use the interface.
   pObject->SomeMethod1();
   pObject->SomeMethod2();
    ...


Here is an example of a Class that we could use to access an ACTIVEX/COM object from within a dialog. All classes that we create to do this should resemble this format:

#ifndef __NEWDLG_H_
#define __NEWDLG_H_

#include "resource.h"       // main symbols
#include <atlhost.h> // ALLOWS HOSTING OF COM/ACTIVEX CONTROLS IN DIALOG
#import "SomeDllOrOcx" raw_interfaces_only, raw_native_types, no_namespace, named_guids  

/////////////////////////////////////////////////////////////////////////////
// CNewDlg
class CNewDlg :
public CAxDialogImpl<CNewDlg> // USE THE ATL CAxDialogImpl Template Class
{
public:
CNewDlg() // Constructer()
{
}

~CNewDlg() // Destructer()
{
}

BEGIN_MSG_MAP(CNewDlg)
MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
COMMAND_ID_HANDLER(IDOK, OnOK)
COMMAND_ID_HANDLER(IDCANCEL, OnCancel)
      ...
      // CUSTOM CONTROL HANDLERS
COMMAND_HANDLER(IDC_MYBUTTON, BN_CLICKED, OnClickedMybutton)
      ...
END_MSG_MAP()

// Handler prototypes:
//  LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);

//  LRESULT CommandHandler(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);

//  LRESULT NotifyHandler(int idCtrl, LPNMHDR pnmh, BOOL& bHandled);

    LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
return 1;  // Let the system set the focus
}

LRESULT OnOK(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
EndDialog(wID);
return 0;
}

LRESULT OnCancel(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
EndDialog(wID);
return 0;
}
public :

BEGIN_SINK_MAP(CNewDlg)
//Make sure the Event Handlers have __stdcall calling convention
END_SINK_MAP()

      // EXAMPLE OF ACCESSING OF A CONTROL
LRESULT OnClickedMybutton(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
CComPtr<ISomething> pObject;
GetDlgControl(IDC_SOMEID,IID_ISomething, (void **)&pObject);
pObject->SomeMethod1();
pObject->SomeMethod2();
pObject->SomeMethod3();
return 0;
}
};

#endif //__NEWDLG_H_
0
 
LVL 2

Expert Comment

by:WDB
ID: 2931974
Why was this answer rejected? I have no problem with having my answer rejected but please comment as to why you have done so. The answer I have proposed is a clear and complete answer to your question, at least it appears that way to me.
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
LVL 2

Accepted Solution

by:
WDB earned 100 total points
ID: 3319813
Once again, Why was this answer rejected? I have no problem with having my answer rejected but please comment as to why you have done so. The answer I have proposed is a clear and complete answer to your question, at least it appears that way to me. I have reported this thread to EE.

0
 
LVL 3

Expert Comment

by:darinw
ID: 3321784
austin123 - Please post a comment and advise the Expert of your intentions.

darinw
Customer Service
0
 
LVL 3

Expert Comment

by:darinw
ID: 3354973
austin123 - You there?

darinw
Customer Service
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

598 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