본문 바로가기

Windows/MFC

ExecStatic

[code]// ExecStatic.cpp : implementation file
//

// DATE        : September 22, 2006
// CODER    : aucd29 (aucd29@gmail.com)
//
// -----------------------------------------------------------------------
// September 22, 2006
// -----------------------------------------------------------------------
// * 프로그램 인스톨을 위해서는 필요한 static 컨트롤을 생성하기 위해서
// 작성한 것
//

#include "stdafx.h"
#include "PressCD.h"
#include "ExecStatic.h"


// CExecStatic

IMPLEMENT_DYNAMIC(CExecStatic, CStatic)

CExecStatic::CExecStatic()
: m_crHoverColor(RGB(46,119,209))
, m_crDefaultColor(RGB(0,0,0))
, m_bMouseOver(false)
, m_szCommand(_T(""))
, m_pParant(NULL)
, m_bClicked(false)
{

}

CExecStatic::~CExecStatic()
{
}


BEGIN_MESSAGE_MAP(CExecStatic, CStatic)
    ON_WM_LBUTTONDOWN()
    ON_CONTROL_REFLECT(STN_CLICKED, &CExecStatic::OnStnClicked)
    ON_WM_MOUSEMOVE()
    ON_WM_SETCURSOR()
    ON_WM_CTLCOLOR_REFLECT()
END_MESSAGE_MAP()

// CExecStatic message handlers
void CExecStatic::SetDefaultColor(COLORREF crColor)
{
    m_crDefaultColor = crColor;
}

void CExecStatic::SetHoverColor(COLORREF crColor)
{
    m_crHoverColor = crColor;
}

void CExecStatic::OnLButtonDown(UINT nFlags, CPoint point)
{
    CStatic::OnLButtonDown(nFlags, point);
}

void CExecStatic::OnStnClicked()
{
    m_bClicked = true;

    if (m_pParant)
    {
        if (m_szCommand == _T("close"))
        {
            exit(1);
//            m_pParant->OnCancel();
        }
    }

    // onClick시 생성할 이벤트
    if (m_szCommand)
    {
        // 유니코드와 아스키 간에 차이를 둔다.
#ifdef _UNICODE
        int nLen = m_szCommand.GetLength();
        char pDest[MAX_PATH+20] = {0,};
        WideCharToMultiByte(CP_ACP, 0, m_szCommand, -1, pDest, nLen, NULL, NULL);
        WinExec(pDest, SW_SHOW);
#else
        WinExec(m_szCommand, SW_SHOW);
#endif
    }
}

void CExecStatic::PreSubclassWindow()
{
    // 기본적인 스타일 옵션을 가져온 뒤에
    DWORD dwStyle = GetStyle();
    SetWindowLong(GetSafeHwnd(), GWL_STYLE, dwStyle | SS_NOTIFY);

    // 커서를 가져오기 위해서 준비
    TCHAR szWindowsDir[MAX_PATH*2]={0,};
    GetWindowsDirectory(szWindowsDir ,MAX_PATH*2);
    wcscat_s(szWindowsDir,_T("\\Winhlp32.exe"));
    HMODULE hModule = LoadLibrary(szWindowsDir);

    // 커서를 가져오고
    if (hModule){
        m_hHyperCursor = ::LoadCursor(hModule, MAKEINTRESOURCE(106));
    }
    SetCursor(m_hHyperCursor);
    
    //free the module
    if (hModule)
        FreeLibrary(hModule);

    CStatic::PreSubclassWindow();
}

BOOL CExecStatic::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
    NMHDR* pMsgHeader;
    pMsgHeader = (NMHDR*)lParam;

    switch(pMsgHeader->code)
    {
    case NM_RCLICK:
        break;
    default:;
    }

    return CStatic::OnNotify(wParam, lParam, pResult);
}

void CExecStatic::OnMouseMove(UINT nFlags, CPoint point)
{
    /*if (m_bMouseOver)
    {
        CRect oRect;
        GetClientRect(&oRect);

        if (oRect.PtInRect(point) == false)
        {
            m_bMouseOver = false;
            ReleaseCapture();
            RedrawWindow();
            //return;
        }
    }
    else
    {
        m_bMouseOver = true;
        RedrawWindow();
        SetCapture();
    }*/

    CStatic::OnMouseMove(nFlags, point);
}

BOOL CExecStatic::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
    ::SetCursor(m_hHyperCursor);
    return true;
}

HBRUSH CExecStatic::CtlColor(CDC* pDC, UINT nCtlColor)
{
    if (m_bMouseOver)
    {
        pDC->SetTextColor(m_crHoverColor);
    }
    else
    {
        pDC->SetTextColor(m_crDefaultColor);
    }
    pDC->SetBkMode(TRANSPARENT);
    return((HBRUSH)GetStockObject(NULL_BRUSH));
}

void CExecStatic::SetBold(bool bType)
{
    LOGFONT sLogFont;
    GetFont()->GetLogFont(&sLogFont);
    sLogFont.lfWeight = FW_SEMIBOLD;
    m_oTextFont.CreateFontIndirect(&sLogFont);
    this->SetFont(&m_oTextFont, true);
}

void CExecStatic::SetCommand(CString szCommand)
{
    m_szCommand = szCommand;
}


void CExecStatic::SetWnd(CWnd* pWnd)
{
    m_pParant = pWnd;
}
[/code]