Solved

Accessing windows controls and ActiveX with ATL

Posted on 2002-05-13
5
912 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
  • 2
  • 2
5 Comments
 
LVL 49

Expert Comment

by:DanRollins
Comment Utility
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
Comment Utility
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
Comment Utility
are you calling AtlAxWinInit () ??
0
 
LVL 49

Accepted Solution

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

-- Dan
0
 

Author Comment

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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
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 viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now