Solved

Accessing windows controls and ActiveX with ATL

Posted on 2002-05-13
5
916 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
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

Suggested Solutions

Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
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…
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…
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…

831 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