//+------------------------------------------------------------------+
//| ControlsRadioGroup.mq5 |
//| Copyright 2000-2024, MetaQuotes Ltd. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property description "제어판 및 대화 상자. 데모 클래스 CRadioGroup"
#include <Controls\Dialog.mqh>
#include <Controls\RadioGroup.mqh>
//+------------------------------------------------------------------+
//| 정의 |
//+------------------------------------------------------------------+
//--- 틈
#define INDENT_LEFT (11) // 왼쪽에서 들여쓰기(경계 너비 허용)
#define INDENT_TOP (11) // 맨 위에서 들여쓰기(경계 너비 허용)
#define INDENT_RIGHT (11) // 오른쪽에서 들여쓰기(경계 너비 허용)
#define INDENT_BOTTOM (11) // 아래쪽에서 들여쓰기(경계 너비 허용)
#define CONTROLS_GAP_X (5) // X 좌표에 의한 차이
#define CONTROLS_GAP_Y (5) // Y 좌표에 의한 차이
//--- 버튼용
#define BUTTON_WIDTH (100) // X 좌표에 의한 크기
#define BUTTON_HEIGHT (20) // Y 좌표에 의한 크기
//--- 표시 영역용
#define EDIT_HEIGHT (20) // Y 좌표에 의한 크기
//--- 그룹 컨트롤용
#define GROUP_WIDTH (150) // X 좌표에 의한 크기
#define LIST_HEIGHT (179) // Y 좌표에 의한 크기
#define RADIO_HEIGHT (56) // Y 좌표에 의한 크기
#define CHECK_HEIGHT (93) // Y 좌표에 의한 크기
//+------------------------------------------------------------------+
//| Class CControlsDialog |
//| Usage: 제어 응용 프로그램의 주 대화 상자 |
//+------------------------------------------------------------------+
class CControlsDialog : public CAppDialog
{
private:
CRadioGroup m_radio_group; // CRadioGroup 객체
public:
CControlsDialog(void);
~CControlsDialog(void);
//--- 생성
virtual bool Create(const long chart,const string name,const int subwin,const int x1,const int y1,const int x2,const int y2);
//--- 차트 이벤트 핸들러
virtual bool OnEvent(const int id,const long &lparam,const double &dparam,const string &sparam);
protected:
//--- 종속 컨트롤 생성
bool CreateRadioGroup(void);
//--- 종속 제어 이벤트 핸들러
void OnChangeRadioGroup(void);
};
//+------------------------------------------------------------------+
//| 이벤트 처리 |
//+------------------------------------------------------------------+
EVENT_MAP_BEGIN(CControlsDialog)
ON_EVENT(ON_CHANGE,m_radio_group,OnChangeRadioGroup)
EVENT_MAP_END(CAppDialog)
//+------------------------------------------------------------------+
//| 생성자 |
//+------------------------------------------------------------------+
CControlsDialog::CControlsDialog(void)
{
}
//+------------------------------------------------------------------+
//| 소멸자 |
//+------------------------------------------------------------------+
CControlsDialog::~CControlsDialog(void)
{
}
//+------------------------------------------------------------------+
//| 생성 |
//+------------------------------------------------------------------+
bool CControlsDialog::Create(const long chart,const string name,const int subwin,const int x1,const int y1,const int x2,const int y2)
{
if(!CAppDialog::Create(chart,name,subwin,x1,y1,x2,y2))
return(false);
//--- 종속 컨트롤 생성
if(!CreateRadioGroup())
return(false);
//--- 성공
return(true);
}
//+------------------------------------------------------------------+
//| "RadioGroup" 요소를 생성 |
//+------------------------------------------------------------------+
bool CControlsDialog::CreateRadioGroup(void)
{
//--- 좌표
int x1=INDENT_LEFT;
int y1=INDENT_TOP+(EDIT_HEIGHT+CONTROLS_GAP_Y)+
(BUTTON_HEIGHT+CONTROLS_GAP_Y)+
(EDIT_HEIGHT+CONTROLS_GAP_Y)+
(EDIT_HEIGHT+CONTROLS_GAP_Y);
int x2=x1+GROUP_WIDTH;
int y2=y1+RADIO_HEIGHT;
//--- 생성
if(!m_radio_group.Create(m_chart_id,m_name+"RadioGroup",m_subwin,x1,y1,x2,y2))
return(false);
if(!Add(m_radio_group))
return(false);
//--- 문자열로 채웁니다
for(int i=0;i<3;i++)
if(!m_radio_group.AddItem("Item "+IntegerToString(i),1<<i))
return(false);
m_radio_group.Value(1<<2);
Comment(__FUNCTION__+" : Value="+IntegerToString(m_radio_group.Value()));
//--- 성공
return(true);
}
//+------------------------------------------------------------------+
//| 이벤트 핸들러 |
//+------------------------------------------------------------------+
void CControlsDialog::OnChangeRadioGroup(void)
{
Comment(__FUNCTION__+" : Value="+IntegerToString(m_radio_group.Value()));
}
//+------------------------------------------------------------------+
//| 글로벌 변수 |
//+------------------------------------------------------------------+
CControlsDialog ExtDialog;
//+------------------------------------------------------------------+
//| Expert 초기화 함수 |
//+------------------------------------------------------------------+
int OnInit()
{
//--- 응용 프로그램 대화 상자 만들기
if(!ExtDialog.Create(0,"Controls",0,40,40,380,344))
return(INIT_FAILED);
//--- 어플리케이션 실행
ExtDialog.Run();
//--- 성공
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert 초기화 해제 함수 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//--- 댓글 삭제
Comment("");
//--- 대화 상자 소멸
ExtDialog.Destroy(reason);
}
//+------------------------------------------------------------------+
//| Expert 차트 이벤트 함수 |
//+------------------------------------------------------------------+
void OnChartEvent(const int id, // 이벤트 ID
const long& lparam, // long 타입의 이벤트 매개 변수
const double& dparam, // double 타입의 이벤트 매개 변수
const string& sparam) // string 타입의 이벤트 매개 변수
{
ExtDialog.ChartEvent(id,lparam,dparam,sparam);
}
|