Solved

Accessing windows controls and ActiveX with ATL

Posted on 2002-05-13
5
919 Views
Last Modified: 2013-11-25
Hi,

I have an ATL control, with on dialog of CAxDialogImpl template.

in this dialog i have a static control (label) and a OCX progressbar from the mscomctl.ocx

i have an ATL object with only one public function that we can call Process.

When i call process, i the ATL object do some stuff. During this stuff i want to display the CAxDialogImpl to show the progress of the ATL object work.

The problem is that i really don't know how to make the progressbar work. I don't know how to access the progressbar and make it progress.

here is the code of the dialog:

.cpp

// ProgressDlg.cpp : Implementation of ProgressDlg
#include "stdafx.h"
#include "ProgressDlg.h"

/////////////////////////////////////////////////////////////////////////////
// ProgressDlg

void CProgressDlg::SetMessage(CString str){
     CWindow message(GetDlgItem(IDC_STATICCTRL));
     message.SetWindowText(str);
}

void CProgressDlg::SetProgressValue(float value){
     m_pbptr->put_Value(value);
}

header file

// ProgressDlg.h : Declaration of the CProgressDlg

#ifndef __PROGRESSDLG_H_
#define __PROGRESSDLG_H_

#include "resource.h"       // main symbols
#include <atlhost.h>

/////////////////////////////////////////////////////////////////////////////
// CProgressDlg
class CProgressDlg :
     public CAxDialogImpl<CProgressDlg>
{
public:
     CProgressDlg()
     {
     }

     ~CProgressDlg()
     {
     }
     IProgressBarPtr m_pbptr;
     HWND m_pbwnd;
     enum { IDD = IDD_PROGRESSDLG };
     void SetMessage(CString str);
     void SetProgressValue(float value);

BEGIN_MSG_MAP(CProgressDlg)
     MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
     MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
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)
     {
          HRESULT hr = E_FAIL;
          // Cache the pointer to shape control.
          m_pbwnd = GetDlgItem (IDC_PROGCTRL1);
          // Get the unknown pointer.
          AtlAxGetControl (m_pbwnd, (IUnknown **) &m_pbptr);
          return 1;  // Let the system set the focus
     }

     LRESULT OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
     {
          return 0;
     }
};

#endif //__PROGRESSDLG_H_


With this code i succeed in changing the static text. but when i try to modify the progressbar position, it crashes.

Does anyone have an idea of what the problem is. Thanks!

0
Comment
Question by:FMayis
[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
  • 2
  • 2
5 Comments
 
LVL 49

Expert Comment

by:DanRollins
ID: 7005493
You will need to call the SetMin, SetMax, and SetValue members of the progress control.  I use the ClassWizard to generate a wrapper for the control, but I am using MFC.  You will use ATL variations.

Is there any real reason to use an ActiveX control here?  Why not just use the standard Progress control -- it should be on the dialog editor control palette.  You just send it simple messages:  PBM_SETRANGE and PBM_SETPOS

-- Dan
0
 

Author Comment

by:FMayis
ID: 7005498
When i use the standard Progress control i can't display the dialog, it crashes when i create it.

I have tested all that, but i think there is some Atl macros to call before accessing the controls, like AtlAdvise, AtlWinInit but i don't know what they do so if someone know that it would be helpful.
0
 
LVL 22

Expert Comment

by:ambience
ID: 7005552
are you calling AtlAxWinInit () ??
0
 
LVL 49

Accepted Solution

by:
DanRollins earned 250 total points
ID: 7005595
Call
      InitCommonControls()
That should fix you right up.

-- Dan
0
 

Author Comment

by:FMayis
ID: 7005750
I have test with the common control progress bar and it works fine thanks!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

696 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