游标MFC问题(消失) [英] cursor MFC problem (disappear)

查看:94
本文介绍了游标MFC问题(消失)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习MFC,但是游标出现了问题
我创建了一个图像控制程序,该程序可以缩放,旋转,平移和交换图像
我尝试为程序的每个功能更改光标的形状,但是当单元格中没有图像时,它才起作用!当单元格中有图像时,光标就会消失.
谁能帮我吗. (对不起,我的Eng :()
这是我的代码的一部分

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 :( )
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));
    }
}

推荐答案

If this parameter is NULL, the cursor is removed from the screen[^] :)

Try to map and hold your cursors in the resources:
SetCursor(AfxGetApp()->LoadCursor(ID_MOVING_VIEW));


yourApp.rc:


yourApp.rc :

ID_MOVING_VIEW  CURSOR  "res\\MoveView.CUR"


还请考虑::ShowCursor(..)的必要性:)


Please think also about the necessity of ::ShowCursor(..) :)


您还应该将WM_SETCURSOR消息映射到实际选择光标资源的位置.

当前所拥有的内容将导致光标在所需的内容和视图默认光标之间不断闪烁.
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.


您还应该映射WM_SETCURSOR消息,在其中应该真正选择光标资源.

当前拥有的内容将导致光标在所需的内容和视图的默认光标之间不断闪烁.
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.


这篇关于游标MFC问题(消失)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆