Solved

Accessing windows controls and ActiveX with ATL

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Title # Comments Views Activity
How can i Install a new Data Source on Visual Studio 2 117
FMX TCameraComponent Problem 2 93
Mobile apps - web/native or hybrid? 1 77
Shared files and folders migration 2 31
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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…

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