策略为王源代码扩展系列-主菜单-扩展自定义主菜单基本资料和行情选股对话框CDialog(CustomSelectStockDlg.cpp)

Published

摘要:

1.新建对话框资源。ID_TOOL_SELECTSTOCK

2.新建一个和对话框相关的类

调用基类CDialog的构造函数,IDD为对话框资源的ID

说明:

模态对话框的创建函数:CDialog::DoModal()

非模态对话框的创建函数:BOOL  CDialog::Create(ID号,父窗口指针);

 

Changed 

Come from:主菜单基本资料和行情选股对话框 
Changed history:FilterInfoDlg.cpp->SelectStockDlg.cpp->CustomSelectStockDlg.cpp

 

第一部分 在主菜单中添加菜单

step 1:添加菜单ID,ID_TOOL_SELECTSTOCK

G:\stock\TskingVS2019\src\Client\StkUI\resource.h

/*************custom extend 工具条 by freema*******/


#define ID_VIEW_PMIN1                   34592
#define ID_VIEW_REPLAYREALTIME          34593
#define ID_VIEW_HISTORYREALTIME         34594

#define ID_VIEW_CUSTOMSELECTOR          34595
#define ID_TOOL_SELECTSTOCK             34596


#define ID_PLAYBACK_BEGIN               35779
#define ID_PLAYBACK_REV                 35780
#define ID_PLAYBACK_FASTREV             35781
#define ID_PLAYBACK_PAUSE               35782
#define ID_PLAYBACK_FORWARD             35783
#define ID_PLAYBACK_FASTFW              35784
#define ID_PLAYBACK_END                 35785
#define ID_PLAYBACK_STOP                35786
/*****************************************/

step2:添加菜单项

G:\stock\TskingVS2019\src\Client\StkUI\StkUI.rc

    POPUP "工具(T)"
    BEGIN
        MENUITEM "交易(&T)...\tF12",              ID_TOOL_TRADER
        MENUITEM SEPARATOR
        MENUITEM "计算器(&C)...",                  ID_TOOL_CALCULATOR
        MENUITEM "记事本(&N)...",                  ID_TOOL_NOTE
        MENUITEM "自定义画线工具",                 ID_TOOL_DRAWLINE   //custom extend 画线工具 by freeman
        MENUITEM SEPARATOR
        MENUITEM "基本资料和行情选股(&F)...",            ID_TOOL_FILTERINFO
       
        
        MENUITEM "预警系统(&A)...",                 ID_TOOL_ALARM
        MENUITEM SEPARATOR
        MENUITEM "自定义条件选股", ID_TOOL_SELECTSTOCK
        MENUITEM "自定义智能选股器", ID_VIEW_CUSTOMSELECTOR
        MENUITEM SEPARATOR
        MENUITEM "自定义历史行情",                     ID_VIEW_HISTORYREALTIME
        MENUITEM "自定义行情回放",                     ID_VIEW_REPLAYREALTIME
        MENUITEM "自定义系统设置",                     ID_OPTION_SETSYSTEM
    END

 

第二部分  新增加一个对话框资源 

step 1:资源ID IDD_SELECTSTOCK

G:\stock\TskingVS2019\src\Client\StkUI\resource.h

/*************custom extend 工具条 by freema*******/
#define IDD_SETSYSTEMSET1               300
#define IDR_REPLAY                      301
#define IDD_CUSTOMSELECTOR_FORM         302   //自定义智能选股
#define IDD_SELECTOR                    303
/*****************************************/

 

step 2:定义对话框样式

/*****************custom extend by freeman*********************/
IDD_SELECTSTOCK DIALOGEX 0, 0, 365, 255
STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION
CAPTION "基本资料和行情选股"
FONT 9, "宋体", 0, 0, 0x1
BEGIN
LISTBOX         IDC_LISTINFO, 8, 23, 93, 92, LBS_NOINTEGRALHEIGHT | NOT WS_BORDER | WS_VSCROLL | WS_HSCROLL | WS_TABSTOP, WS_EX_STATICEDGE
EDITTEXT        IDC_EDITMORETHAN, 169, 25, 49, 12, ES_AUTOHSCROLL | NOT WS_BORDER, WS_EX_STATICEDGE
EDITTEXT        IDC_EDITLESSTHAN, 169, 43, 49, 12, ES_AUTOHSCROLL | NOT WS_BORDER, WS_EX_STATICEDGE
PUSHBUTTON      "加入条件>>", IDC_ADD, 168, 63, 50, 14, BS_FLAT
PUSHBUTTON      "移除条件<<", IDC_REMOVE, 168, 80, 50, 14, BS_FLAT
CONTROL         "满足全部条件", IDC_RADIOAND, "Button", BS_AUTORADIOBUTTON | BS_FLAT, 111, 97, 64, 10
CONTROL         "满足任一条件", IDC_RADIOOR, "Button", BS_AUTORADIOBUTTON | BS_FLAT, 111, 110, 64, 10
LISTBOX         IDC_LISTCOND, 227, 23, 127, 93, LBS_NOINTEGRALHEIGHT | NOT WS_BORDER | WS_VSCROLL | WS_HSCROLL | WS_TABSTOP, WS_EX_STATICEDGE
CONTROL         "全部股票", IDC_ALL, "Button", BS_AUTOCHECKBOX | BS_FLAT | WS_TABSTOP, 29, 139, 48, 10
CONTROL         "上证A股", IDC_SHAA, "Button", BS_AUTOCHECKBOX | BS_FLAT | WS_TABSTOP, 29, 154, 44, 10
CONTROL         "上证B股", IDC_SHAB, "Button", BS_AUTOCHECKBOX | BS_FLAT | WS_TABSTOP, 29, 169, 44, 10
CONTROL         "深证A股", IDC_SZNA, "Button", BS_AUTOCHECKBOX | BS_FLAT | WS_TABSTOP, 29, 184, 44, 10
CONTROL         "深证B股", IDC_SZNB, "Button", BS_AUTOCHECKBOX | BS_FLAT | WS_TABSTOP, 29, 199, 44, 10
LISTBOX         IDC_LISTRESULT, 120, 127, 234, 80, LBS_NOINTEGRALHEIGHT | LBS_MULTICOLUMN | LBS_DISABLENOSCROLL | NOT WS_BORDER | WS_HSCROLL | WS_TABSTOP, WS_EX_STATICEDGE
PUSHBUTTON      "开始", IDC_START, 245, 211, 50, 14, BS_FLAT
PUSHBUTTON      "加入分组...", IDC_ADDTOGROUP, 305, 211, 50, 14, BS_FLAT
PUSHBUTTON      "关闭", IDCANCEL, 276, 235, 50, 14, BS_FLAT
LTEXT           "", IDC_STATICTIME, 10, 11, 101, 8
LTEXT           "选中条件:", IDC_STATIC, 232, 11, 41, 8
RTEXT           "大于等于", IDC_STATIC, 111, 27, 52, 8
RTEXT           "并且小于等于", IDC_STATIC, 111, 45, 52, 8
GROUPBOX        "选股范围", IDC_STATIC, 7, 122, 95, 96
CONTROL         "Progress1", IDC_PROGRESS, "msctls_progress32", PBS_SMOOTH, 116, 214, 122, 8, WS_EX_STATICEDGE
CONTROL         "", IDC_STATIC, "Static", SS_BLACKFRAME, 0, 230, 371, 1, WS_EX_STATICEDGE
END

/**************************************************************/

 

/*********extend by freeman***********/
	IDD_SELECTSTOCK, DIALOG
	BEGIN
		LEFTMARGIN, 7
		RIGHTMARGIN, 358
		TOPMARGIN, 7
		BOTTOMMARGIN, 248
	END

  /**********************/

 

第三部分 新建对话框类

此类对IDD_SELECTSTOCK进行处理。

step 3:实现对对话框的处理

G:\stock\TskingVS2019\src\Client\StkUI\Dialog\SelectStockDlg.cpp

 

第四部分 启用对话框

添加IDD_SELECTSTOCK的消息处理

step 1:在MainFrm.cpp中添加对SelectorDlg.h类的引用

/**** extend 系统设置、行情回放菜单项 by freeman ****/
#include "Dialog/SetSystemSet1.h"
#include "View/RePlayRealTimeView.h"
#include "View/HistoryRealtimeView.h"
#include "View/CustomSelectorView.h"
#include "Dialog/SelectorDlg.h"
/**************************************/

step 2:在MainFrm.h中定义消息映射关系

G:\stock\TskingVS2019\src\Client\StkUI\MainFrm.h

/**** extend 系统设置、行情回放、历史行情菜单项 by freeman ****/
	afx_msg void OnOptionSystemset();
	afx_msg void OnToolSelectStock();

	afx_msg void OnViewRePlayRealtime();
	afx_msg void OnUpdateViewRePlayRealtime(CCmdUI* pCmdUI);
	
	afx_msg void OnViewHistoryRealtime();
	afx_msg void OnUpdateViewHistoryRealtime(CCmdUI* pCmdUI);
	afx_msg void OnViewCustomSelector();
	afx_msg void OnUpdateViewCustomSelector(CCmdUI* pCmdUI);
	
	/**************************************/

 

在主程序中添加点击菜单后生成的消息和对应的消息处理函数

/**** extend 系统设置菜单项 by freeman ****/
	ON_COMMAND(ID_OPTION_SETSYSTEM, OnOptionSystemset)	
	ON_COMMAND(ID_TOOL_SELECTSTOCK, OnToolSelectStock) 
	/**************************************/

实现消息函数

void CMainFrame::OnToolSelectStock()
{
	CSelectStockDlg	dlg;
	dlg.DoModal();
}