This commit is contained in:
445
HookMsg/DlgEditTool.cpp
Normal file
445
HookMsg/DlgEditTool.cpp
Normal file
@@ -0,0 +1,445 @@
|
||||
// DlgEditTool.cpp : implementation file
|
||||
//
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "HookMsg.h"
|
||||
#include "DlgEditTool.h"
|
||||
#include "ConfigINI.h"
|
||||
#include "HookMsgDlg.h"
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define new DEBUG_NEW
|
||||
#undef THIS_FILE
|
||||
static char THIS_FILE[] = __FILE__;
|
||||
#endif
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CDlgEditTool dialog
|
||||
|
||||
WINDOWPLACEMENT wndplCDlgEditTool = { 0, };
|
||||
|
||||
CDlgEditTool::CDlgEditTool(CWnd* pParent /*=NULL*/)
|
||||
: CDialog(CDlgEditTool::IDD, pParent)
|
||||
{
|
||||
//{{AFX_DATA_INIT(CDlgEditTool)
|
||||
// NOTE: the ClassWizard will add member initialization here
|
||||
//}}AFX_DATA_INIT
|
||||
m_pParent = pParent;
|
||||
}
|
||||
|
||||
void CDlgEditTool::DoDataExchange(CDataExchange* pDX)
|
||||
{
|
||||
CDialog::DoDataExchange(pDX);
|
||||
//{{AFX_DATA_MAP(CDlgEditTool)
|
||||
DDX_Control(pDX, IDC_VALUE_LIST, m_ctrlList);
|
||||
DDX_Control(pDX, IDC_VALUE, m_ctrlEdit);
|
||||
//}}AFX_DATA_MAP
|
||||
}
|
||||
|
||||
|
||||
BEGIN_MESSAGE_MAP(CDlgEditTool, CDialog)
|
||||
//{{AFX_MSG_MAP(CDlgEditTool)
|
||||
ON_BN_CLICKED(IDOK, OnOk)
|
||||
ON_BN_CLICKED(IDC_BUTTON_INSERT, OnButtonInsert)
|
||||
ON_BN_CLICKED(IDC_BUTTON_DELETE, OnButtonDelete)
|
||||
ON_BN_CLICKED(IDC_BUTTON_DELETEALL, OnButtonDeleteall)
|
||||
ON_WM_PAINT()
|
||||
ON_WM_SIZE()
|
||||
ON_WM_GETMINMAXINFO()
|
||||
ON_WM_DESTROY()
|
||||
//}}AFX_MSG_MAP
|
||||
END_MESSAGE_MAP()
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CDlgEditTool message handlers
|
||||
|
||||
void CDlgEditTool::SetData(CString strSecName)
|
||||
{
|
||||
m_strSecName = strSecName;
|
||||
}
|
||||
|
||||
BOOL CDlgEditTool::OnInitDialog()
|
||||
{
|
||||
CDialog::OnInitDialog();
|
||||
|
||||
CString strTitle = m_strSecName;
|
||||
if(m_strSecName == "거부리스트1")
|
||||
strTitle += "(Registry)";
|
||||
else if(m_strSecName == "거부리스트2")
|
||||
strTitle += "(File)";
|
||||
SetWindowText( (LPSTR)(LPCTSTR)strTitle );
|
||||
|
||||
m_ctrlEdit.LimitText(100);
|
||||
|
||||
if(wndplCDlgEditTool.length == sizeof(wndplCDlgEditTool))
|
||||
::SetWindowPlacement( m_hWnd, &wndplCDlgEditTool);
|
||||
|
||||
try
|
||||
{
|
||||
HRESULT hr;
|
||||
hr = m_objStockCode.CreateInstance( CLSID_CpStockCode ); // 종목코드변환.
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
}
|
||||
}
|
||||
catch( _com_error e )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
LoadDataList();
|
||||
|
||||
return TRUE; // return TRUE unless you set the focus to a control
|
||||
// EXCEPTION: OCX Property Pages should return FALSE
|
||||
}
|
||||
|
||||
void CDlgEditTool::OnPaint()
|
||||
{
|
||||
if (IsIconic())
|
||||
{
|
||||
CPaintDC dc(this); // device context for painting
|
||||
|
||||
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
|
||||
|
||||
// Center icon in client rectangle
|
||||
int cxIcon = GetSystemMetrics(SM_CXICON);
|
||||
int cyIcon = GetSystemMetrics(SM_CYICON);
|
||||
CRect rect;
|
||||
GetClientRect(&rect);
|
||||
int x = (rect.Width() - cxIcon + 1) / 2;
|
||||
int y = (rect.Height() - cyIcon + 1) / 2;
|
||||
|
||||
// Draw the icon
|
||||
// dc.DrawIcon(x, y, m_hIcon);
|
||||
}
|
||||
else
|
||||
{
|
||||
CPaintDC dc(this); // device context for painting
|
||||
CRect rc;
|
||||
GetClientRect(&rc);
|
||||
|
||||
rc.left = rc.right - ::GetSystemMetrics(SM_CXHSCROLL);
|
||||
rc.top = rc.bottom - ::GetSystemMetrics(SM_CYVSCROLL);
|
||||
dc.DrawFrameControl( rc, DFC_SCROLL, DFCS_SCROLLSIZEGRIP );
|
||||
|
||||
CDialog::OnPaint();
|
||||
}
|
||||
}
|
||||
|
||||
BOOL CDlgEditTool::OnCommand(WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
if (IDOK == wParam) // Enter key pressed
|
||||
{
|
||||
if (GetFocus() == &m_ctrlEdit) // Focus on Editctrl
|
||||
{
|
||||
OnButtonInsert();
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return CDialog::OnCommand(wParam, lParam);
|
||||
}
|
||||
|
||||
void CDlgEditTool::OnOk()
|
||||
{
|
||||
SaveDataList();
|
||||
|
||||
CDialog::OnOK();
|
||||
}
|
||||
|
||||
void CDlgEditTool::OnCancel()
|
||||
{
|
||||
CDialog::OnCancel();
|
||||
}
|
||||
|
||||
void CDlgEditTool::OnButtonInsert()
|
||||
{
|
||||
UpdateData();
|
||||
|
||||
CString str;
|
||||
m_ctrlEdit.GetWindowText(str);
|
||||
|
||||
CString strAdd = AddCodeString(str);
|
||||
if( strAdd == "" )
|
||||
{
|
||||
AfxMessageBox("종목코드(6자리)나 회사명을 입력해주세요.");
|
||||
return;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
int nRet;
|
||||
nRet = SearchString(-1, strAdd.Left(6), FALSE ); // m_ctrlList.FindString(-1, strAdd.Left(7)))
|
||||
if (LB_ERR != nRet )
|
||||
{
|
||||
AfxMessageBox("이미 리스트에 등록되어 있습니다.");
|
||||
m_ctrlList.SetCurSel(nRet);
|
||||
return;
|
||||
}
|
||||
|
||||
nRet = m_ctrlList.AddString( strAdd );
|
||||
if( LB_ERR != nRet )
|
||||
m_ctrlList.SetCurSel(nRet);
|
||||
|
||||
CStatic *pStatic = (CStatic*)GetDlgItem(IDC_DLGEDIT_TOTAL_STATIC);
|
||||
char szCount[10]={0,}; sprintf( szCount, "%d", m_ctrlList.GetCount() );
|
||||
pStatic->SetWindowText( szCount );
|
||||
m_ctrlEdit.SetWindowText("");
|
||||
}
|
||||
|
||||
int CDlgEditTool::SearchString(int nStartAfter, LPCTSTR lpszItem, BOOL bExact) const
|
||||
{
|
||||
if (!::IsWindow(m_ctrlList.m_hWnd))
|
||||
{
|
||||
ASSERT(FALSE);
|
||||
return LB_ERR;
|
||||
}
|
||||
|
||||
// start the search after specified index
|
||||
int nIndex = nStartAfter + 1;
|
||||
int nCount = m_ctrlList.GetCount();
|
||||
if (nCount == LB_ERR)
|
||||
return LB_ERR;
|
||||
|
||||
// convert string to search for to lower case
|
||||
CString strItem;
|
||||
strItem = lpszItem;
|
||||
strItem.MakeLower();
|
||||
int nItemSize = strItem.GetLength();
|
||||
|
||||
CString strText;
|
||||
|
||||
// search until end
|
||||
for ( ; nIndex < nCount; nIndex++)
|
||||
{
|
||||
m_ctrlList.GetText(nIndex, strText);
|
||||
strText.MakeLower();
|
||||
if (!bExact)
|
||||
strText = strText.Left(nItemSize);
|
||||
if (strText == strItem)
|
||||
return nIndex;
|
||||
}
|
||||
|
||||
// if we started at beginning there is no more to do, search failed
|
||||
if (nStartAfter == -1)
|
||||
return LB_ERR;
|
||||
|
||||
// search until we reach beginning index
|
||||
for (nIndex = 0; (nIndex <= nStartAfter) && (nIndex < nCount); nIndex++)
|
||||
{
|
||||
m_ctrlList.GetText(nIndex, strText);
|
||||
strText.MakeLower();
|
||||
if (!bExact)
|
||||
strText = strText.Left(nItemSize);
|
||||
if (strText == strItem)
|
||||
return nIndex;
|
||||
}
|
||||
|
||||
return LB_ERR;
|
||||
}
|
||||
|
||||
void CDlgEditTool::OnButtonDelete()
|
||||
{
|
||||
int nSel = m_ctrlList.GetCurSel();
|
||||
|
||||
if (LB_ERR == nSel)
|
||||
{
|
||||
AfxMessageBox("제거할 항목을 선택하세요");
|
||||
return;
|
||||
}
|
||||
|
||||
m_ctrlList.DeleteString(nSel);
|
||||
|
||||
CStatic *pStatic = (CStatic*)GetDlgItem(IDC_DLGEDIT_TOTAL_STATIC);
|
||||
char szCount[10]={0,}; sprintf( szCount, "%d", m_ctrlList.GetCount() );
|
||||
pStatic->SetWindowText( szCount );
|
||||
}
|
||||
|
||||
void CDlgEditTool::OnButtonDeleteall()
|
||||
{
|
||||
int nID = MessageBox( "모든 데이터를 삭제합니다.",
|
||||
"모두삭제", MB_YESNO|MB_ICONQUESTION );
|
||||
if( nID == IDYES )
|
||||
{
|
||||
m_ctrlList.ResetContent();
|
||||
}
|
||||
|
||||
CStatic *pStatic = (CStatic*)GetDlgItem(IDC_DLGEDIT_TOTAL_STATIC);
|
||||
char szCount[10]={0,}; sprintf( szCount, "%d", m_ctrlList.GetCount() );
|
||||
pStatic->SetWindowText( szCount );
|
||||
}
|
||||
|
||||
void CDlgEditTool::LoadDataList()
|
||||
{
|
||||
m_ctrlList.ResetContent();
|
||||
|
||||
CString strKeyValue, strFullString, strLineNum;
|
||||
int nLineNum = 0;
|
||||
|
||||
if(m_strSecName == "거부리스트1")
|
||||
{
|
||||
// 종거부리스트는 레지스트리에서 읽어온다.
|
||||
CHookMsgApp* pApp = (CHookMsgApp*)AfxGetApp();
|
||||
|
||||
CString strCodes;
|
||||
strCodes = pApp->RegReadString(HKEY_CURRENT_USER,
|
||||
"SOFTWARE\\LimmSoft\\TKRRDR\\RejectList\\",
|
||||
"Codes");
|
||||
|
||||
int i = 0;
|
||||
while (i + 5 < strCodes.GetLength())
|
||||
{
|
||||
m_ctrlList.AddString( AddCodeString(strCodes.Mid(i, 6)) );
|
||||
i += 6;
|
||||
}
|
||||
}
|
||||
else if(m_strSecName == "거부리스트2")
|
||||
{
|
||||
g_pStockData->ListBoxLoad_ExclusionCode( &m_ctrlList );
|
||||
}
|
||||
else if(m_strSecName == "중복리스트")
|
||||
{
|
||||
g_pStockData->ListBoxLoad_RepeatedCode( &m_ctrlList );
|
||||
}
|
||||
else if(m_strSecName == "특별종목리스트")
|
||||
{
|
||||
g_pStockData->ListBoxLoad_SpecialCode( &m_ctrlList );
|
||||
}
|
||||
else if(m_strSecName == "수동종목리스트")
|
||||
{
|
||||
g_pStockData->ListBoxLoad_ManualInputCode( &m_ctrlList );
|
||||
}
|
||||
|
||||
CStatic *pStatic = (CStatic*)GetDlgItem(IDC_DLGEDIT_TOTAL_STATIC);
|
||||
char szCount[10]={0,}; sprintf( szCount, "%d", m_ctrlList.GetCount() );
|
||||
pStatic->SetWindowText( szCount );
|
||||
}
|
||||
|
||||
void CDlgEditTool::SaveDataList()
|
||||
{
|
||||
CString strKeyValue, strValueList = "";
|
||||
|
||||
if(m_strSecName == "거부리스트1")
|
||||
{
|
||||
CString strCode;
|
||||
for (int i = 0; i < m_ctrlList.GetCount(); i++)
|
||||
{
|
||||
m_ctrlList.GetText(i, strKeyValue);
|
||||
strCode = strKeyValue.Left(6);
|
||||
|
||||
if(strCode != "")
|
||||
strValueList += strCode;
|
||||
}
|
||||
|
||||
CHookMsgApp* pApp = (CHookMsgApp*)AfxGetApp();
|
||||
|
||||
pApp->RegWriteString(HKEY_CURRENT_USER,
|
||||
"SOFTWARE\\LimmSoft\\TKRRDR\\RejectList\\",
|
||||
"Codes", strValueList);
|
||||
}
|
||||
else if(m_strSecName == "거부리스트2")
|
||||
{
|
||||
g_pStockData->ListBoxSave_ExclusionCode( &m_ctrlList );
|
||||
}
|
||||
else if(m_strSecName == "중복리스트")
|
||||
{
|
||||
g_pStockData->ListBoxSave_RepeatedCode( &m_ctrlList );
|
||||
}
|
||||
else if(m_strSecName == "특별종목리스트")
|
||||
{
|
||||
g_pStockData->ListBoxSave_SpecialCode( &m_ctrlList );
|
||||
}
|
||||
else if(m_strSecName == "수동종목리스트")
|
||||
{
|
||||
g_pStockData->ListBoxSave_ManualInputCode( &m_ctrlList );
|
||||
}
|
||||
}
|
||||
|
||||
void CDlgEditTool::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
|
||||
{
|
||||
CDialog::OnGetMinMaxInfo(lpMMI);
|
||||
lpMMI->ptMinTrackSize.x = 200;
|
||||
lpMMI->ptMinTrackSize.y = 200;
|
||||
lpMMI->ptMaxTrackSize.x= ::GetSystemMetrics(SM_CXSCREEN);
|
||||
lpMMI->ptMaxTrackSize.y= ::GetSystemMetrics(SM_CYSCREEN);
|
||||
}
|
||||
|
||||
void CDlgEditTool::OnSize(UINT nType, int cx, int cy)
|
||||
{
|
||||
CDialog::OnSize(nType, cx, cy);
|
||||
|
||||
SetDlgCtrlPosition( cx, cy );
|
||||
RedrawWindow();
|
||||
}
|
||||
|
||||
void CDlgEditTool::SetDlgCtrlPosition(int cx, int cy)
|
||||
{
|
||||
CWnd *pWnd;
|
||||
if( pWnd = (CWnd*)GetDlgItem(IDC_VALUE) )
|
||||
pWnd->MoveWindow( 5, 5, cx-100, 22 );
|
||||
if( pWnd = (CWnd*)GetDlgItem(IDC_VALUE_LIST) )
|
||||
pWnd->MoveWindow( 5, 30, cx-100, cy - 34 );
|
||||
|
||||
if( pWnd = (CWnd*)GetDlgItem(IDC_BUTTON_INSERT) )
|
||||
pWnd->MoveWindow( cx-90, 5, 85, 22 );
|
||||
if( pWnd = (CWnd*)GetDlgItem(IDC_BUTTON_DELETE) )
|
||||
pWnd->MoveWindow( cx-90, 30, 85, 22 );
|
||||
if( pWnd = (CWnd*)GetDlgItem(IDC_BUTTON_DELETEALL) )
|
||||
pWnd->MoveWindow( cx-90, 55, 85, 22 );
|
||||
|
||||
if( pWnd = (CWnd*)GetDlgItem(IDC_SP_STATIC) )
|
||||
pWnd->MoveWindow( cx-90, 85, 85, 2 );
|
||||
|
||||
if( pWnd = (CWnd*)GetDlgItem(IDC_DLGEDIT_TOTAL_ST1_STATIC) )
|
||||
pWnd->MoveWindow( cx-90, 88, 30, 20 );
|
||||
if( pWnd = (CWnd*)GetDlgItem(IDC_DLGEDIT_TOTAL_STATIC) )
|
||||
pWnd->MoveWindow( cx-60, 88, 30, 20 );
|
||||
if( pWnd = (CWnd*)GetDlgItem(IDC_DLGEDIT_TOTAL_ST2_STATIC) )
|
||||
pWnd->MoveWindow( cx-27, 88, 10, 20 );
|
||||
|
||||
if( pWnd = (CWnd*)GetDlgItem(IDOK) )
|
||||
pWnd->MoveWindow( cx-90, cy-55, 85, 22 );
|
||||
if( pWnd = (CWnd*)GetDlgItem(IDCANCEL) )
|
||||
pWnd->MoveWindow( cx-90, cy-30, 85, 22 );
|
||||
}
|
||||
|
||||
void CDlgEditTool::OnDestroy()
|
||||
{
|
||||
wndplCDlgEditTool.length = sizeof(WINDOWPLACEMENT);
|
||||
::GetWindowPlacement( m_hWnd, &wndplCDlgEditTool);
|
||||
|
||||
m_objStockCode.Release();
|
||||
|
||||
CDialog::OnDestroy();
|
||||
}
|
||||
|
||||
CString CDlgEditTool::AddCodeString(CString strInput)
|
||||
{
|
||||
CString strRet="", strCode="", strName="";
|
||||
|
||||
strName = (LPCSTR)m_objStockCode->CodeToName( (LPCSTR)strInput );
|
||||
if( strName == "" )
|
||||
{
|
||||
CString str = "A" + strInput;
|
||||
strName = (LPCSTR)m_objStockCode->CodeToName( (LPCSTR)str );
|
||||
if( strName != "" )
|
||||
{
|
||||
strRet.Format( "%s: %s", strInput, strName );
|
||||
return strRet;
|
||||
}
|
||||
}
|
||||
|
||||
strCode = (LPCSTR)m_objStockCode->NameToCode( (LPCSTR)strInput );
|
||||
if( strCode != "" )
|
||||
{
|
||||
strCode.Replace(" ", "");
|
||||
strCode.TrimLeft("A");
|
||||
strRet.Format( "%s: %s", strCode, strInput );
|
||||
return strRet;
|
||||
}
|
||||
|
||||
return strRet;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user