티스토리 뷰

190717-3
 

 
 
스크롤은 별도의 커맨드 메세지가 발생되지 않는다.
 
 
void CScrollDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
    switch (nSBCode) {
        case SB_LINELEFT:
            m_nR = max(0, m_nR - 1); // 구간설정 시 팁 max,min을 사용한다.
            break;
        case SB_LINERIGHT:
            m_nR = min(255, m_nR + 1);
 
            break;
        case SB_PAGELEFT:
            m_nR -= max(0, m_nR - 5);
 
            break;
        case SB_PAGERIGHT:
            m_nR += min(255, m_nR + 5);
 
            break;
        case SB_THUMBTRACK://잡고 드래그
            m_nR = nPos; // nPos : 똇을 때의 위치
            break;
    }
 
    m_ctrlR.SetScrollPos(m_nR);
    CDialogEx::OnHScroll(nSBCode, nPos, pScrollBar);
}
- 스크롤시 값 설정
 
void CScrollDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
    UINT nT;
    if(&m_ctrlR==pScrollBar)
        nT = m_nR;
    else if (&m_ctrlB == pScrollBar)
        nT = m_nB;
    else if (&m_ctrlG == pScrollBar)
        nT = m_nG;
 
    switch (nSBCode) {
    case SB_LINELEFT:
        nT = max(0, nT - 1); // 구간설정 시 팁 max,min을 사용한다.
        break;
    case SB_LINERIGHT:
        nT = min(255, nT + 1);
 
        break;
    case SB_PAGELEFT:
        nT = max(0, nT - 5);
 
        break;
    case SB_PAGERIGHT:
        nT = min(255, nT + 5);
 
        break;
    case SB_THUMBTRACK://잡고 드래그
        nT = nPos; // nPos : 똇을 때의 위치
        break;
    }
    if (&m_ctrlR == pScrollBar)
        m_nR = nT;
    else if (&m_ctrlB == pScrollBar)
        m_nB = nT;
    else if (&m_ctrlG == pScrollBar)
        m_nG = nT;
    pScrollBar->SetScrollPos(nT);
    CDialogEx::OnHScroll(nSBCode, nPos, pScrollBar);
}
- 스크롤 이동시 값 설정
 
 
void CScrollDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
    int nT = 0;
 
    if(&m_ctrlR==pScrollBar)
        nT = m_nR;
    else if (&m_ctrlG == pScrollBar)
        nT = m_nG;
    else if (&m_ctrlB == pScrollBar)
        nT = m_nB;
 
    switch (nSBCode) {
        case SB_LINELEFT:
            nT = max(0, nT - 1); // 구간설정 시 팁 max,min을 사용한다.
            break;
        case SB_LINERIGHT:
            nT = min(255, nT + 1);
            break;
        case SB_PAGELEFT:
            nT = max(0, nT - 5);
            break;
        case SB_PAGERIGHT:
            nT = min(255, nT + 5);
            break;
        case SB_THUMBTRACK://잡고 드래그
            nT = nPos; // nPos : 똇을 때의 위치
            break;
    }
 
    if (&m_ctrlR == pScrollBar) {
        m_nR = nT;
        m_nER = nT;
    }
    else if (&m_ctrlG == pScrollBar) {
        m_nG = nT;
        m_nEG = nT;
    }
    else if (&m_ctrlB == pScrollBar) {
        m_nB = nT;
        m_nEB = nT;
    }
    UpdateData(FALSE); //변수의 값을 컨트롤로 전송
 
    pScrollBar->SetScrollPos(nT);
 
    CDialogEx::OnHScroll(nSBCode, nPos, pScrollBar);
}
 
- 스크롤시 각각의 스크롤 바가 움직이며 값이 변경되게함 
 
void CCBView::OnPaint()
{
    CPaintDC dc(this); // device context for painting
                     // TODO: 여기에 메시지 처리기 코드를 추가합니다.
                     // 그리기 메시지에 대해서는 CView::OnPaint()을(를) 호출하지 마십시오.
 
    CCBDoc* pDoc = GetDocument();
    CList<CRect>& lt = pDoc->m_rtList;
    POSITION pos = lt.GetHeadPosition(); // cf. MFC : 이터레이터를 쓰지 않음. (이중연결리스트)
 
    while (pos) { // if pos is not NULL
        const CRect& rt = lt.GetNext(pos); // and pos++
        dc.Rectangle(rt);
    }
}
- DC로 그림 그리기 리스트에 있는 사각형 전부 그리기
 

 
다이얼로그는 생성자가 이미 정해져있어서 원하는 인수를 넘기지 못함
초기화 함수를 작성하자.
 
우리 예제에서 프레임의 자식은 뷰다.
 
void CMainFrame::OnModalless()
{
    CCBView* pView = (CCBView*)this->GetActiveView(); // 자식을 얻어옴 (in this example)
    // if 이미 객체가 있다면 포커스 else 없다면 생성
    if (m_pDlg == NULL){
        m_pDlg = new CScrollDlg;
        m_pDlg->InitDialog(pView->m_brush);
        m_pDlg->Create(IDD_DIALOG2, this); // this : parent setting
        m_pDlg->ShowWindow(SW_SHOW);
    }
    else {
        m_pDlg->SetFocus();
    }
}
 
[이후 업데이트한 코드]
void CMainFrame::OnModalless()
{
    CCBView* pView = (CCBView*)this->GetActiveView(); // 자식을 얻어옴 (in this example)
    // if 이미 객체가 있다면 포커스 else 없다면 생성
    if (m_pDlg == NULL){
        m_pDlg = new CScrollDlg;
        m_pDlg->InitDialog(pView);
        m_pDlg->Create(IDD_DIALOG2, this); // this : parent setting
        m_pDlg->ShowWindow(SW_SHOW);
    }
    else {
        m_pDlg->SetFocus();
    }
}
pView를 통채로 넘겨서 Brush를 갱신한다.
 
[CScrollDlg.cpp]
void CScrollDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
    int nT = 0;
 
    if(&m_ctrlR==pScrollBar)
        nT = m_nR;
    else if (&m_ctrlG == pScrollBar)
        nT = m_nG;
    else if (&m_ctrlB == pScrollBar)
        nT = m_nB;
 
    switch (nSBCode) {
        case SB_LINELEFT:
            nT = max(0, nT - 1); // 구간설정 시 팁 max,min을 사용한다.
            break;
        case SB_LINERIGHT:
            nT = min(255, nT + 1);
            break;
        case SB_PAGELEFT:
            nT = max(0, nT - 5);
            break;
        case SB_PAGERIGHT:
            nT = min(255, nT + 5);
            break;
        case SB_THUMBTRACK://잡고 드래그
            nT = nPos; // nPos : 똇을 때의 위치
            break;
    }
 
    if (&m_ctrlR == pScrollBar) {
        m_nR = nT;
        m_nER = nT;
    }
    else if (&m_ctrlG == pScrollBar) {
        m_nG = nT;
        m_nEG = nT;
    }
    else if (&m_ctrlB == pScrollBar) {
        m_nB = nT;
        m_nEB = nT;
    }
    UpdateData(FALSE);
 
    pScrollBar->SetScrollPos(nT);
 
    m_pView->UpdateBrushColor(RGB(m_nR, m_nG, m_nB));
 
    CDialogEx::OnHScroll(nSBCode, nPos, pScrollBar);
}
 
[CBView.cpp]
void CCBView::UpdateBrushColor(COLORREF brush)
{
    m_brush = brush;
    Invalidate();
}
- 프레임에서 View를 사용
댓글
최근에 올라온 글
최근에 달린 댓글
네이버 이웃추가
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함