Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ MFC
hi, i'm studying MFC and had a problem with cursor
I create an image control program which can zoom, rotate, panning and swapping images
I tried to change the cursor's shape for each function of my program, but it just work when no image in cell! when there are image in cell, the cursor just disappear.
Can anyone help me out. (sorry for my Eng Frown | :( )
Here is part of my code
void CImageEdittingView::SwapMouseDown(int fMouseX, int fMouseY)
{
    
 
    CImageEdittingDoc* pDoc = GetDocument();
    ASSERT_VALID(pDoc);
    if (!pDoc)
        return;
 
    if (fMouseX > pDoc->m_layout->GetInitX()&& 
        fMouseX < (pDoc->m_layout->GetInitX() + pDoc->m_layout->GetWidth()))
 
        if (fMouseY > pDoc->m_layout->GetInitY() &&
            fMouseY < (pDoc->m_layout->GetInitY() + pDoc->m_layout->GetHeigh()))
        {
            HCURSOR hSwapClose = LoadCursorFromFile("res\\cursor_drag_hand.ico");
            ::SetCursor(hSwapClose);
                    
            //SetClassLong(m_hWnd, GCL_HCURSOR,(LONG)hZoomOut);
            ShowCursor(TRUE);
        }
}
 
void CImageEdittingView::SwapMouseUp(int fMouseX, int fMouseY)
{
    //lay ra layout
    CImageEdittingDoc* pDoc = GetDocument();
    ASSERT_VALID(pDoc);
    if (!pDoc)
        return;
    
    if (fMouseX > pDoc->m_layout->GetInitX()&& 
        fMouseX < (pDoc->m_layout->GetInitX() + pDoc->m_layout->GetWidth()))
 
        if (fMouseY > pDoc->m_layout->GetInitY() &&
            fMouseY < (pDoc->m_layout->GetInitY() + pDoc->m_layout->GetHeigh()))
        {
            HCURSOR hSwapOpen = LoadCursorFromFile("res\\cursor_hand.ico");
            ::SetCursor(hSwapOpen);
                    
            //SetClassLong(m_hWnd, GCL_HCURSOR,(LONG)hZoomOut);
            ShowCursor(TRUE);
        }
 
    Graphics gr(this->GetDC()->m_hDC);
    
    CLayout* layout = pDoc->m_layout;
    int newIndex = layout->GetCellIndexFromPosition(fMouseX, fMouseY);
 
    if(newIndex >= 0)
    {
        int oldIndex = layout->GetCurrCellIndex();
 
        layout->Swap(oldIndex, newIndex);
 
        layout->GetCell(newIndex)->Draw(&gr, GetScrollPos(SB_HORZ), GetScrollPos(SB_VERT));
 
        layout->GetCell(oldIndex)->Draw(&gr, GetScrollPos(SB_HORZ), GetScrollPos(SB_VERT));
 
        layout->GetCurrCell()->DrawCellBorder(&gr, CUltil::clActiveBorderColor, GetScrollPos(SB_HORZ), GetScrollPos(SB_VERT));
    }
}
Posted 5-Jul-12 0:51am
thanh15453
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

If this parameter is NULL, the cursor is removed from the screen[^] Smile | :)
 
Try to map and hold your cursors in the resources:
SetCursor(AfxGetApp()->LoadCursor(ID_MOVING_VIEW));
yourApp.rc :
ID_MOVING_VIEW  CURSOR  "res\\MoveView.CUR"
Please think also about the necessity of ::ShowCursor(..) Smile | :)
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

You should also be mapping the WM_SETCURSOR message where you should do the real selection of the cursor resource.
 
What you currently have will cause the cursor to flicker constantly between what you want and the views default cursor.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

You should also be mapping the WM_SETCURSOR message where you should do the real selection of the cursor resource.
 
What you currently have will cause the cursor to flicker constantly between what you want and the views default cursor.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Your example is incomplete but I assume that you are trying to create your own custom control and implement some kind of dragging operation inside it. If this is the case, then you should establish mouse capture for the time of the drag operation, and then release the mouse capture at the end of dragging. While your control has the mouse capture you can set a cursor and it wont change till you have the capture even if the cursor is outside of your control because during active mouse capture the operating system wont send any WM_SETCURSOR messages to windows under the cursor. For a complete example check out this tip in which you can find a short and complete example to using mouse capture:
Using SetCapture() and ReleaseCapture() correctly (usually during a drag n' drop operation).[^]
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 CPallini 375
1 Sergey Alexandrovich Kryukov 370
2 BillWoodruff 314
3 George Jonsson 279
4 OriginalGriff 257
0 OriginalGriff 5,030
1 CPallini 4,115
2 Sergey Alexandrovich Kryukov 3,554
3 George Jonsson 2,826
4 Gihan Liyanage 2,386


Advertise | Privacy | Mobile
Web02 | 2.8.140916.1 | Last Updated 5 Jul 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100