Author Topic: ARX and MFC  (Read 7387 times)

0 Members and 1 Guest are viewing this topic.

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 7033
  • AKA Daniel
ARX and MFC
« on: January 09, 2010, 06:35:28 AM »
Create a new ARX project using the ARX wizard, In the wizard, select using MFC, everything else leave as default

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 7033
  • AKA Daniel
Re: ARX and MFC
« Reply #1 on: January 09, 2010, 06:45:32 AM »
In the ARX toolbar, add a new command by selecting the little a> and add your new command name

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 7033
  • AKA Daniel
Re: ARX and MFC
« Reply #2 on: January 09, 2010, 06:46:20 AM »
Open the class explorer, and right click on the root level item and add a ARX MFC class


It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 7033
  • AKA Daniel
Re: ARX and MFC
« Reply #3 on: January 09, 2010, 06:50:19 AM »
Enter the name of your new class, and set the base class as CAcUiDialog.


It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 7033
  • AKA Daniel
Re: ARX and MFC
« Reply #4 on: January 09, 2010, 07:03:23 AM »
You should have a new class that looks like this

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 7033
  • AKA Daniel
Re: ARX and MFC
« Reply #5 on: January 09, 2010, 07:04:01 AM »
You should also have a new dialog in the project resource

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 7033
  • AKA Daniel
Re: ARX and MFC
« Reply #6 on: January 09, 2010, 07:16:40 AM »
From the toolbox drag a new button to the dialog

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 7033
  • AKA Daniel
Re: ARX and MFC
« Reply #7 on: January 09, 2010, 07:18:23 AM »
Right Click on the new button and choose add variable

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 7033
  • AKA Daniel
Re: ARX and MFC
« Reply #8 on: January 09, 2010, 07:19:40 AM »
Right Click on the new button again and choose add event handler

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 7033
  • AKA Daniel
Re: ARX and MFC
« Reply #9 on: January 09, 2010, 07:22:53 AM »
Now, go into the code (MyDialog.h) and change the button type from CButton to CAcUiPickButton

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 7033
  • AKA Daniel
Re: ARX and MFC
« Reply #10 on: January 09, 2010, 07:29:02 AM »
next we need to add an a OnInitDialog() method and inside the method call the button's autoload function

.h
Code: [Select]
#pragma once

//-----------------------------------------------------------------------------
#include "acui.h"
#include "afxwin.h"

//-----------------------------------------------------------------------------
class MyDialog : public CAcUiDialog {
DECLARE_DYNAMIC (MyDialog)

public:
MyDialog (CWnd *pParent =NULL, HINSTANCE hInstance =NULL) ;

enum { IDD = IDD_MYDIALOG} ;

protected:
virtual void DoDataExchange (CDataExchange *pDX) ;
  virtual BOOL OnInitDialog();

afx_msg LRESULT OnAcadKeepFocus (WPARAM, LPARAM) ;

DECLARE_MESSAGE_MAP()
public:
  afx_msg void OnBnClickedButtonpickitem();
  CAcUiPickButton m_buttonPick;
} ;


.cpp
Code: [Select]
#include "StdAfx.h"
#include "resource.h"
#include "MyDialog.h"

//-----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC (MyDialog, CAcUiDialog)

BEGIN_MESSAGE_MAP(MyDialog, CAcUiDialog)
ON_MESSAGE(WM_ACAD_KEEPFOCUS, OnAcadKeepFocus)
  ON_BN_CLICKED(IDC_BUTTONPICKITEM, &MyDialog::OnBnClickedButtonpickitem)
END_MESSAGE_MAP()

//-----------------------------------------------------------------------------
MyDialog::MyDialog (CWnd *pParent /*=NULL*/, HINSTANCE hInstance /*=NULL*/) :
                            CAcUiDialog (MyDialog::IDD, pParent, hInstance) {
}

//-----------------------------------------------------------------------------
void MyDialog::DoDataExchange (CDataExchange *pDX) {
  CAcUiDialog::DoDataExchange (pDX) ;
  DDX_Control(pDX, IDC_BUTTONPICKITEM, m_buttonPick);
}

//-----------------------------------------------------------------------------
//----- Needed for modeless dialogs to keep focus.
//----- Return FALSE to not keep the focus, return TRUE to keep the focus
LRESULT MyDialog::OnAcadKeepFocus (WPARAM, LPARAM) {
return (TRUE) ;
}

void MyDialog::OnBnClickedButtonpickitem()
{
  // TODO: Add your control notification handler code here
}

BOOL MyDialog::OnInitDialog()
{
  SetDialogName(_T("ArxMFC:MyDialog")); //
  CAcUiDialog::OnInitDialog(); //
  m_buttonPick.AutoLoad(); //
  return TRUE;
}

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 7033
  • AKA Daniel
Re: ARX and MFC
« Reply #11 on: January 09, 2010, 07:36:59 AM »
Next add a edit control to the dialog, Right click on the new control and add a variable

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 7033
  • AKA Daniel
Re: ARX and MFC
« Reply #12 on: January 09, 2010, 07:39:34 AM »
change the type of the new edit control from CEdit to CAcUiNumericEdit

.h
Code: [Select]
#pragma once

//-----------------------------------------------------------------------------
#include "acui.h"
#include "afxwin.h"

//-----------------------------------------------------------------------------
class MyDialog : public CAcUiDialog {
DECLARE_DYNAMIC (MyDialog)

public:
MyDialog (CWnd *pParent =NULL, HINSTANCE hInstance =NULL) ;

enum { IDD = IDD_MYDIALOG} ;

protected:
virtual void DoDataExchange (CDataExchange *pDX) ;
  virtual BOOL OnInitDialog();

afx_msg LRESULT OnAcadKeepFocus (WPARAM, LPARAM) ;

DECLARE_MESSAGE_MAP()
public:
  afx_msg void OnBnClickedButtonpickitem();
  CAcUiPickButton m_buttonPick;
  CAcUiNumericEdit m_TextBoxWidth; // <-----------------------------
} ;


It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 7033
  • AKA Daniel
Re: ARX and MFC
« Reply #13 on: January 09, 2010, 07:42:06 AM »
Right click on the new edit control and an event


It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 7033
  • AKA Daniel
Re: ARX and MFC
« Reply #14 on: January 09, 2010, 07:58:11 AM »
Oops forgot something, highlight the pick button and set Owner draw to True  :laugh: