This commit is contained in:
344
HLStockWindow/HLStockWindowDlg.cpp
Normal file
344
HLStockWindow/HLStockWindowDlg.cpp
Normal file
@@ -0,0 +1,344 @@
|
||||
// HLStockWindowDlg.cpp : implementation file
|
||||
//
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "HLStockWindow.h"
|
||||
#include "HLStockWindowDlg.h"
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define new DEBUG_NEW
|
||||
#undef THIS_FILE
|
||||
static char THIS_FILE[] = __FILE__;
|
||||
#endif
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CHLStockWindowDlg dialog
|
||||
|
||||
CHLStockWindowDlg::CHLStockWindowDlg(CWnd* pParent /*=NULL*/)
|
||||
: CDialog(CHLStockWindowDlg::IDD, pParent)
|
||||
{
|
||||
//{{AFX_DATA_INIT(CHLStockWindowDlg)
|
||||
// NOTE: the ClassWizard will add member initialization here
|
||||
//}}AFX_DATA_INIT
|
||||
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
|
||||
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
|
||||
|
||||
m_bBkColorStat = TRUE;
|
||||
memset( &m_cpData, NULL, sizeof(m_cpData) );
|
||||
}
|
||||
|
||||
void CHLStockWindowDlg::DoDataExchange(CDataExchange* pDX)
|
||||
{
|
||||
CDialog::DoDataExchange(pDX);
|
||||
//{{AFX_DATA_MAP(CHLStockWindowDlg)
|
||||
DDX_Control(pDX, IDC_EDIT_INFOMATION, m_hInfomation);
|
||||
//}}AFX_DATA_MAP
|
||||
}
|
||||
|
||||
BEGIN_MESSAGE_MAP(CHLStockWindowDlg, CDialog)
|
||||
//{{AFX_MSG_MAP(CHLStockWindowDlg)
|
||||
ON_WM_PAINT()
|
||||
ON_WM_QUERYDRAGICON()
|
||||
ON_WM_SIZE()
|
||||
ON_WM_CTLCOLOR()
|
||||
ON_WM_ERASEBKGND()
|
||||
ON_WM_COPYDATA()
|
||||
ON_WM_CLOSE()
|
||||
ON_WM_WINDOWPOSCHANGING()
|
||||
//}}AFX_MSG_MAP
|
||||
ON_WM_SYSCOMMAND()
|
||||
END_MESSAGE_MAP()
|
||||
|
||||
BOOL CHLStockWindowDlg::OnCopyData(CWnd* pWnd, COPYDATASTRUCT* pCopyDataStruct)
|
||||
{
|
||||
if( pCopyDataStruct->dwData == TYPEOF_HLStockWindow )
|
||||
{
|
||||
memcpy(&m_cpData, (HLSTOCKWINDOWDATA*)pCopyDataStruct->lpData, sizeof(HLSTOCKWINDOWDATA)); // transfer data to internal variable
|
||||
|
||||
PostMessage(WM_COMMAND, ID_HLSTOCKWINDOWDIALOG_SHOW, 0);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return CDialog::OnCopyData(pWnd, pCopyDataStruct);
|
||||
}
|
||||
|
||||
void CHLStockWindowDlg::OnSysCommand(UINT nID, LPARAM lParam)
|
||||
{
|
||||
switch( nID )
|
||||
{
|
||||
// case SC_RESTORE:
|
||||
// ShowWindow( SW_SHOW );
|
||||
// break;
|
||||
case SC_CLOSE:
|
||||
{
|
||||
g_theApp.m_Hide = FALSE;
|
||||
ShowWindow( SW_HIDE );
|
||||
return;
|
||||
}
|
||||
case ID_APP_EXIT:
|
||||
PostMessage(WM_CLOSE);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
CDialog::OnSysCommand(nID, lParam);
|
||||
}
|
||||
|
||||
BOOL CHLStockWindowDlg::OnCommand(WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
switch( (UINT)wParam )
|
||||
{
|
||||
case ID_HLSTOCKWINDOWDIALOG_SHOW :
|
||||
{
|
||||
if( Running() )
|
||||
{
|
||||
g_theApp.m_Hide = FALSE;
|
||||
ShowWindow(SW_SHOW);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return CDialog::OnCommand(wParam, lParam);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CHLStockWindowDlg message handlers
|
||||
void CHLStockWindowDlg::OnOK()
|
||||
{
|
||||
// SaveWindowPlacement();
|
||||
// DestroyWindow ();
|
||||
}
|
||||
void CHLStockWindowDlg::OnCancel()
|
||||
{
|
||||
SaveWindowPlacement();
|
||||
|
||||
g_theApp.m_Hide = FALSE;
|
||||
ShowWindow( SW_HIDE );
|
||||
}
|
||||
void CHLStockWindowDlg::OnClose()
|
||||
{
|
||||
// TODO: Add your message handler code here and/or call default
|
||||
SaveWindowPlacement();
|
||||
PostQuitMessage(0);
|
||||
CDialog::OnClose();
|
||||
}
|
||||
|
||||
BOOL CHLStockWindowDlg::OnInitDialog()
|
||||
{
|
||||
CDialog::OnInitDialog();
|
||||
|
||||
// Set the icon for this dialog. The framework does this automatically
|
||||
// when the application's main window is not a dialog
|
||||
SetIcon(m_hIcon, TRUE); // Set big icon
|
||||
SetIcon(m_hIcon, FALSE); // Set small icon
|
||||
|
||||
CMenu* pSysMenu = GetSystemMenu(FALSE);
|
||||
if (pSysMenu != NULL)
|
||||
{
|
||||
pSysMenu->AppendMenu(MF_SEPARATOR);
|
||||
pSysMenu->AppendMenu(MF_STRING, ID_APP_EXIT, "프로그램 종료");
|
||||
}
|
||||
|
||||
// TODO: Add extra initialization here
|
||||
m_brushRed.CreateSolidBrush(RGB(255, 50, 50));
|
||||
m_brushBlue.CreateSolidBrush(RGB(50, 50, 255));
|
||||
|
||||
m_hInfomation.SetWindowText("\r\n상/하한가 입력방지창입니다.\r\n"
|
||||
"위치조정후 닫아주세요.\r\n\r\n"
|
||||
"HookMsg.exe 연동프로세스입니다.");
|
||||
|
||||
RestoreWindowPlacement();
|
||||
SetWindowPos(&wndTopMost, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
|
||||
|
||||
return TRUE; // return TRUE unless you set the focus to a control
|
||||
}
|
||||
|
||||
void CHLStockWindowDlg::OnWindowPosChanging(WINDOWPOS FAR* lpwndpos)
|
||||
{
|
||||
if(g_theApp.m_Hide)
|
||||
{
|
||||
lpwndpos->flags &= ~SWP_SHOWWINDOW;
|
||||
}
|
||||
|
||||
CDialog::OnWindowPosChanging(lpwndpos);
|
||||
}
|
||||
|
||||
|
||||
// If you add a minimize button to your dialog, you will need the code below
|
||||
// to draw the icon. For MFC applications using the document/view model,
|
||||
// this is automatically done for you by the framework.
|
||||
|
||||
void CHLStockWindowDlg::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
|
||||
{
|
||||
CDialog::OnPaint();
|
||||
}
|
||||
}
|
||||
|
||||
// The system calls this to obtain the cursor to display while the user drags
|
||||
// the minimized window.
|
||||
HCURSOR CHLStockWindowDlg::OnQueryDragIcon()
|
||||
{
|
||||
return (HCURSOR) m_hIcon;
|
||||
}
|
||||
|
||||
void CHLStockWindowDlg::OnSize(UINT nType, int cx, int cy)
|
||||
{
|
||||
CDialog::OnSize(nType, cx, cy);
|
||||
|
||||
if( ::IsWindow(m_hInfomation.m_hWnd) )
|
||||
{
|
||||
CRect rc( 2, 5, cx-2, cy-2);
|
||||
m_hInfomation.MoveWindow( &rc );
|
||||
}
|
||||
}
|
||||
|
||||
HBRUSH CHLStockWindowDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
|
||||
{
|
||||
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
|
||||
|
||||
if (nCtlColor == CTLCOLOR_STATIC || nCtlColor == CTLCOLOR_EDIT ) //( pWnd->GetDlgCtrlID() == IDC_MYSTATIC)
|
||||
{
|
||||
pDC->SetBkMode(TRANSPARENT);
|
||||
|
||||
if(m_bBkColorStat)
|
||||
hbr = m_brushRed;
|
||||
else
|
||||
hbr = m_brushBlue;
|
||||
}
|
||||
|
||||
return hbr;
|
||||
}
|
||||
|
||||
BOOL CHLStockWindowDlg::OnEraseBkgnd(CDC* pDC)
|
||||
{
|
||||
CRect rc;
|
||||
GetWindowRect(rc);
|
||||
ScreenToClient(rc);
|
||||
if(m_bBkColorStat)
|
||||
pDC->FillSolidRect( &rc, RGB(255, 50, 50) );
|
||||
else
|
||||
pDC->FillSolidRect( &rc, RGB(50, 50, 255) );
|
||||
|
||||
return TRUE;
|
||||
// return CDialog::OnEraseBkgnd(pDC);
|
||||
}
|
||||
|
||||
void CHLStockWindowDlg::SaveWindowPlacement()
|
||||
{
|
||||
WINDOWPLACEMENT wp;
|
||||
GetWindowPlacement(&wp);
|
||||
g_theApp.WriteProfileBinary("Settings", "CHLStockWindowDlgWindowPos", (LPBYTE)&wp, sizeof(wp));
|
||||
}
|
||||
|
||||
void CHLStockWindowDlg::RestoreWindowPlacement()
|
||||
{
|
||||
WINDOWPLACEMENT *lwp;
|
||||
UINT nl;
|
||||
|
||||
if(g_theApp.GetProfileBinary("Settings", "CHLStockWindowDlgWindowPos", (LPBYTE*)&lwp, &nl))
|
||||
{
|
||||
SetWindowPlacement(lwp);
|
||||
delete [] lwp;
|
||||
}
|
||||
else {
|
||||
CenterWindow(GetDesktopWindow());
|
||||
}
|
||||
}
|
||||
|
||||
BOOL CHLStockWindowDlg::Running()
|
||||
{
|
||||
HRESULT hr;
|
||||
IDibPtr objStockJpbid2;
|
||||
ICpStockCodePtr objStockCode;
|
||||
|
||||
BOOL bRet = FALSE;
|
||||
try
|
||||
{
|
||||
CString strJCode = m_cpData.szJCode;
|
||||
if( strJCode.GetLength() == 7 )
|
||||
{
|
||||
hr = objStockJpbid2.CreateInstance( CLSID_StockJpbid2 ); // 호가정보처리.
|
||||
if (SUCCEEDED(hr))
|
||||
hr = objStockCode.CreateInstance( CLSID_CpStockCode ); // 종목코드변환.
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
objStockJpbid2->SetInputValue( 0, (LPCSTR)strJCode );
|
||||
objStockJpbid2->BlockRequest();
|
||||
long lStockPrice = objStockJpbid2->GetDataValue(0, (long)1 ); // n차 매도호가.
|
||||
long _lLowCheck = objStockJpbid2->GetDataValue(1, (long)1); // 2차 매수호가.(하한가 체크).
|
||||
|
||||
if( _lLowCheck==0 || lStockPrice==0 )
|
||||
{
|
||||
if( lStockPrice == 0 )
|
||||
m_bBkColorStat = TRUE; // 상한가.
|
||||
else if( _lLowCheck == 0 )
|
||||
m_bBkColorStat = FALSE; // 하한가.
|
||||
|
||||
CString strValue, strInfo;
|
||||
CString strJName = (LPCSTR)objStockCode->CodeToName( (LPCSTR)strJCode );
|
||||
strValue.Format( "\r\n매수 호가: %d \r\n매도 호가: %d\r\n", _lLowCheck, lStockPrice );
|
||||
|
||||
strInfo += strJName + ", " + strJCode + "\r\n\r\n시각: " + CTime::GetCurrentTime().Format("%H:%M:%S");
|
||||
strInfo += strValue + "\r\n" + m_cpData.ExtraData;
|
||||
|
||||
if( ::IsWindow(m_hInfomation.m_hWnd) )
|
||||
m_hInfomation.SetWindowText(strInfo);
|
||||
|
||||
if( m_bBkColorStat )
|
||||
SetWindowText( "[상한가 알림]" );
|
||||
else
|
||||
SetWindowText( "[하한가 알림]" );
|
||||
|
||||
m_hInfomation.SetFocus();
|
||||
Invalidate();
|
||||
UpdateData(FALSE);
|
||||
|
||||
bRet = TRUE;
|
||||
}
|
||||
|
||||
objStockJpbid2.Release();
|
||||
objStockCode.Release();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch( _com_error e )
|
||||
{
|
||||
::MessageBox( NULL, "상하한가 검사중 문제가 발생하였습니다. \n에러코드:001", "CHLStockWindowDlg::Running()", MB_ICONERROR|MB_TOPMOST );
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
::MessageBox( NULL, "상하한가 검사중 문제가 발생하였습니다. \n에러코드:002", "CHLStockWindowDlg::Running()", MB_ICONERROR|MB_TOPMOST );
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
CString str;
|
||||
str = bRet ? "Running retrn TRUE":"Running return FALSE";
|
||||
AfxMessageBox(str);
|
||||
#endif
|
||||
|
||||
return bRet;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user