?
Solved

Accessing windows controls and ActiveX with ATL

Posted on 2002-05-13
5
Medium Priority
?
922 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 1000 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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
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 viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

770 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