Windows/MFC

expand dialog

aucd29 2013. 10. 2. 18:17
Explorer option 창과 같이 오류 메시지를 폴딩 치트 하는 식에 윈도우를 생성해보자.

void CExpandDlg::OnBnClickedButton1()
{
    static bool bExpand = true;
    Expanding(IDSTC_XXX, bExpand);
    bExpand = !bExpand;
}

따로 해당 윈도우 클래스를 만들어서 다중 상속해도 재미가 있을 듯 하다.

void CExpandDlg::Expanding(int nResourceID, bool bExpand)
{
    static CRect rcLarge;
    static CRect rcSmall;
    CString strExpand;

    if (rcLarge.IsRectNull())
    {
        CRect rcLandMark;
        CWnd *pWndLandMark = GetDlgItem(nResourceID);    
        ASSERT(pWndLandMark);
        GetWindowRect(rcLarge);
        pWndLandMark->GetWindowRect(rcLandMark);

        //
        // static control 에 top 값을 윈도우에 bottom
        // 값으로 전달해달라고 하는 것.
        //
        rcSmall            = rcLarge;
        rcSmall.bottom = rcLandMark.top;
    }

    if (bExpand)
    {
        SetWindowPos(NULL, 0 , 0, rcLarge.Width(), rcLarge.Height(),
            SWP_NOMOVE | SWP_NOZORDER);
        strExpand = " << Test ";
    }
    else
    {
        SetWindowPos(NULL, 0, 0, rcSmall.Width(), rcSmall.Height(),
            SWP_NOMOVE | SWP_NOZORDER);
        strExpand = " Test >>";
    }

    SetDlgItemText(IDSTC_XXX, strExpand);
}

마지막으로 init 부분에 해당 맴버 함수를 호출해서 +_+ 적용 시키면 끝이다.
OnBnClickedButton1();