CButton

CButton은 "Button" 차트 객체에 기반한 단순 제어의 클래스입니다.

Description

CButton 클래스는 단순 버튼을 만들기 위한 것입니다.

Declaration

   class CButton : public CWndObj

Title

   #include <Controls\Button.mqh>

상속 계층

  CObject

      CWnd

          CWndObj

              CButton

아래에 제시된 코드의 결과:

ControlsButton

그룹별 클래스 메서드

Create

 

Create

컨트롤 생성

State

 

Pressed

"Pressed" 속성을 가져오거나 설정합니다.

Locking

"Locking" 속성을 가져오거나 설정합니다.

속성 변경 이벤트 핸들러

 

OnSetText

"SetText" 이벤트 핸들러

OnSetColor

"SetColor" 이벤트 핸들러

OnSetColorBackground

"SetColorBackground" 이벤트 핸들러

OnSetColorBorder

"SetColorBorder" 이벤트 핸들러

OnSetFont

"SetFont" 이벤트 핸들러

OnSetFontSize

"SetFontSize" 이벤트 핸들러

내부 이벤트 핸들러

 

OnCreate

내부 이벤트 핸들러 "생성"

OnShow

내부 이벤트 핸들러 "Show"

OnHide

내부 이벤트 핸들러 "Hide"

OnMove

내부 이벤트 핸들러 "Move"

OnResize

"Resize" 내부 이벤트 핸들러

OnMouseDown

내부 이벤트 핸들러 "MouseDown"

OnOnMouseUp

내부 이벤트 핸들러 "MouseUp"

클래스 CObject에서 상속된 메서드

Prev, Prev, Next, Next, Save, Load, Type, Compare

클래스 CWnd에서 상속된 메서드

Destroy, OnMouseEvent, Name, ControlsTotal, Control, ControlFind, Rect, Left, Left, Top, Top, Right, Right, Bottom, Bottom, Width, Width, Height, Height, Size, Size, Size, Move, Move, Shift, Contains, Contains, Alignment, Align, Id, Id, IsEnabled, Enable, Disable, IsVisible, Visible, Show, Hide, IsActive, Activate, Deactivate, StateFlags, StateFlags, StateFlagsSet, StateFlagsReset, PropFlags, PropFlags, PropFlagsSet, PropFlagsReset, MouseX, MouseX, MouseY, MouseY, MouseFlags, MouseFlags, MouseFocusKill, BringToTop

클래스 CWndObj에서 상속된 메서드

OnEvent, Text, Text, Color, Color, ColorBackground, ColorBackground, ColorBorder, ColorBorder, Font, Font, FontSize, FontSize, ZOrder, ZOrder

Example of creating a panel with button:

//+------------------------------------------------------------------+
//|                                               ControlsButton.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 "제어판 및 대화 상자. 데모 클래스 CButton"
#include <Controls\Dialog.mqh>
#include <Controls\Button.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:
   CButton           m_button1;                       // 버튼 객체
   CButton           m_button2;                       // 버튼 객체
   CButton           m_button3;                       // 고정 버튼 객체
 
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              CreateButton1(void);
   bool              CreateButton2(void);
   bool              CreateButton3(void);
   //--- 종속 제어 이벤트 핸들러
   void              OnClickButton1(void);
   void              OnClickButton2(void);
   void              OnClickButton3(void);
  };
//+------------------------------------------------------------------+
//| 이벤트 처리                                                   |
//+------------------------------------------------------------------+
EVENT_MAP_BEGIN(CControlsDialog)
ON_EVENT(ON_CLICK,m_button1,OnClickButton1)
ON_EVENT(ON_CLICK,m_button2,OnClickButton2)
ON_EVENT(ON_CLICK,m_button3,OnClickButton3)
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(!CreateButton1())
      return(false);
   if(!CreateButton2())
      return(false);
   if(!CreateButton3())
      return(false);
//--- 성공
   return(true);
  }
//+------------------------------------------------------------------+
//| "Button1" 버튼 생성                                      |
//+------------------------------------------------------------------+
bool CControlsDialog::CreateButton1(void)
  {
//--- 좌표
   int x1=INDENT_LEFT;
   int y1=INDENT_TOP+(EDIT_HEIGHT+CONTROLS_GAP_Y);
   int x2=x1+BUTTON_WIDTH;
   int y2=y1+BUTTON_HEIGHT;
//--- 생성
   if(!m_button1.Create(m_chart_id,m_name+"Button1",m_subwin,x1,y1,x2,y2))
      return(false);
   if(!m_button1.Text("Button1"))
      return(false);
   if(!Add(m_button1))
      return(false);
//--- 성공
   return(true);
  }
//+------------------------------------------------------------------+
//| "Button2" 버튼 생성                                      |
//+------------------------------------------------------------------+
bool CControlsDialog::CreateButton2(void)
  {
//--- 좌표
   int x1=INDENT_LEFT+(BUTTON_WIDTH+CONTROLS_GAP_X);
   int y1=INDENT_TOP+(EDIT_HEIGHT+CONTROLS_GAP_Y);
   int x2=x1+BUTTON_WIDTH;
   int y2=y1+BUTTON_HEIGHT;
//--- 생성
   if(!m_button2.Create(m_chart_id,m_name+"Button2",m_subwin,x1,y1,x2,y2))
      return(false);
   if(!m_button2.Text("Button2"))
      return(false);
   if(!Add(m_button2))
      return(false);
//--- 성공
   return(true);
  }
//+------------------------------------------------------------------+
//| "Button3" 고정 버튼 생성                                |
//+------------------------------------------------------------------+
bool CControlsDialog::CreateButton3(void)
  {
//--- 좌표
   int x1=INDENT_LEFT+2*(BUTTON_WIDTH+CONTROLS_GAP_X);
   int y1=INDENT_TOP+(EDIT_HEIGHT+CONTROLS_GAP_Y);
   int x2=x1+BUTTON_WIDTH;
   int y2=y1+BUTTON_HEIGHT;
//--- 생성
   if(!m_button3.Create(m_chart_id,m_name+"Button3",m_subwin,x1,y1,x2,y2))
      return(false);
   if(!m_button3.Text("Locked"))
      return(false);
   if(!Add(m_button3))
      return(false);
   m_button3.Locking(true);
//--- 성공
   return(true);
  }
//+------------------------------------------------------------------+
//| 이벤트 핸들러                                                    |
//+------------------------------------------------------------------+
void CControlsDialog::OnClickButton1(void)
  {
   Comment(__FUNCTION__);
  }
//+------------------------------------------------------------------+
//| 이벤트 핸들러                                                    |
//+------------------------------------------------------------------+
void CControlsDialog::OnClickButton2(void)
  {
   Comment(__FUNCTION__);
  }
//+------------------------------------------------------------------+
//| 이벤트 핸들러                                                    |
//+------------------------------------------------------------------+
void CControlsDialog::OnClickButton3(void)
  {
   if(m_button3.Pressed())
      Comment(__FUNCTION__+" 컨트롤 상태: On");
   else
      Comment(__FUNCTION__+" 컨트롤 상태: Off");
  }
//+------------------------------------------------------------------+
//| 글로벌 변수                                                 |
//+------------------------------------------------------------------+
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);
  }