我自己引入了一个光标,想用它来替代那种箭头样子的鼠标?应该如何做呢?最好具体点,谢谢!!

解决方案 »

  1.   

    HCURSOR LoadCursor(          HINSTANCE hInstance,
        LPCTSTR lpCursorName
    );HCURSOR SetCursor(          HCURSOR hCursor
    );先Load再Set
      

  2.   

    处理WM_SETCURSOR消息
    BOOL CMyDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
    {
    SetCursor(m_hCursor);//m_hCursor,自己定义的,
    return TRUE;//CDialog::OnSetCursor(pWnd, nHitTest, message);
    }
      

  3.   

    能再具体点吗,引入的资源名为IDXJ,是在OnInitDialog()里面添加吗?我刚开始接触MFC,有很多不懂得。。拜托前辈们具体一点,最好是一步一步来谢谢。
    {
      

  4.   

    弱弱的问一句, m_hCursor如何定义?
      

  5.   

    HCURSOR m_hCursor;是这样定义吗?可是怎么把m_hCursor与图标的ID联系起来的呢?
      

  6.   

    BOOL CUJNDlg::OnSetCursor(CWnd *pWnd, UINT nHitTest, UINT message)
    {   
        HCURSOR m_hCursor;
    m_hCursor=::LoadCursor(NULL,IDXJ);
    SetCursor(m_hCursor);//m_hCursor,自己定义的, 
        return TRUE;//CDialog::OnSetCursor(pWnd, nHitTest, message); 

    }楼上的大侠,我这样写的,编译的时候出现了错误。
    error C2664: 'LoadCursorA' : cannot convert parameter 2 from 'const int' to 'const char *'
            Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
    执行 cl.exe 时出错.
      

  7.   

    m_hCursor=::LoadCursor(NULL, MAKEINTRESOURCE(IDXJ));
      

  8.   

    BOOL CUJNDlg::OnSetCursor(CWnd *pWnd, UINT nHitTest, UINT message)
    {   
        HCURSOR m_hCursor;
    m_hCursor=::LoadCursor(NULL, MAKEINTRESOURCE(IDXJ));
    SetCursor(m_hCursor);//m_hCursor,自己定义的, 
        return TRUE;//CDialog::OnSetCursor(pWnd, nHitTest, message); 

    }按楼上的改法,错误时没了。可是鼠标仍然是箭头,没改成我引入的图标的样子
      

  9.   


    // UJNDlg.cpp : implementation file
    //#include "stdafx.h"
    #include "UJN.h"
    #include "UJNDlg.h"
    #include "JDlg.h"#ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif/////////////////////////////////////////////////////////////////////////////
    // CAboutDlg dialog used for App Aboutclass CAboutDlg : public CDialog
    {
    public:
    CAboutDlg();// Dialog Data
    //{{AFX_DATA(CAboutDlg)
    enum { IDD = IDD_ABOUTBOX };
    //}}AFX_DATA // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CAboutDlg)
    protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
    //}}AFX_VIRTUAL// Implementation
    protected:
    //{{AFX_MSG(CAboutDlg)
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
    };CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
    {
    //{{AFX_DATA_INIT(CAboutDlg)
    //}}AFX_DATA_INIT
    }void CAboutDlg::DoDataExchange(CDataExchange* pDX)
    {
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CAboutDlg)
    //}}AFX_DATA_MAP
    }BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
    //{{AFX_MSG_MAP(CAboutDlg)
    // No message handlers
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
    // CUJNDlg dialogCUJNDlg::CUJNDlg(CWnd* pParent /*=NULL*/)
    : CDialog(CUJNDlg::IDD, pParent)
    {
    //{{AFX_DATA_INIT(CUJNDlg)
    // NOTE: the ClassWizard will add member initialization here
    //}}AFX_DATA_INIT
    // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
    m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
    }void CUJNDlg::DoDataExchange(CDataExchange* pDX)
    {
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CUJNDlg)
    // NOTE: the ClassWizard will add DDX and DDV calls here
    //}}AFX_DATA_MAP
    }BEGIN_MESSAGE_MAP(CUJNDlg, CDialog)
    //{{AFX_MSG_MAP(CUJNDlg)
    ON_WM_SYSCOMMAND()
    ON_WM_PAINT()
    ON_WM_QUERYDRAGICON()
    ON_BN_CLICKED(ID1, On1)
    ON_BN_CLICKED(ID2, On2)
    ON_BN_CLICKED(ID3, On3)
    ON_BN_CLICKED(ID4, On4)
    ON_BN_CLICKED(ID5, On5)
    ON_BN_CLICKED(ID6, On6)
    ON_BN_CLICKED(ID7, On7)
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
    // CUJNDlg message handlers
    CBitmapButton   m_aBmpBtn1 ,m_aBmpBtn2,m_aBmpBtn3,m_aBmpBtn4,m_aBmpBtn5,m_aBmpBtn6,m_aBmpBtn7;
    //LoadCursorA(
       // HINSTANCE hInstance,
       // LPCSTR IDXJ);
    BOOL CUJNDlg::OnInitDialog()
    {
    CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range.
    ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
    ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE);
    if (pSysMenu != NULL)
    {
    CString strAboutMenu;
    strAboutMenu.LoadString(IDS_ABOUTBOX);
    if (!strAboutMenu.IsEmpty())
    {
    pSysMenu->AppendMenu(MF_SEPARATOR);
    pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
    }
    } // Set the icon for this dialog.  The framework does this automatically
    //  when the application's main window is not a dialog
    SetIcon(m_hIcon, TRUE); // Set big icon
    SetIcon(m_hIcon, FALSE); // Set small icon
    // HCURSOR LoadCursor(HINSTANCE hInstance, LPCTSTR lpCursorName ); 
       // HCURSOR SetCursor(HCURSOR hCursor );    // HCURSOR m_hCursor;
    //m_hCursor=::LoadCursor(NULL, MAKEINTRESOURCE(IDXJ));
    //SetCursor(m_hCursor);//m_hCursor,自己定义的, 
      //  return TRUE;//CDialog::OnSetCursor(pWnd, nHitTest, message); 
    // TODO: Add extra initialization here
    PlaySound((LPCTSTR)IDR_WAVE1, AfxGetInstanceHandle(), SND_RESOURCE | SND_ASYNC);


    m_aBmpBtn1.   AutoLoad(ID1,this); 
    m_aBmpBtn2.   AutoLoad(ID2,this);
    m_aBmpBtn3.   AutoLoad(ID3,this);
    m_aBmpBtn4.   AutoLoad(ID4,this);
    m_aBmpBtn5.   AutoLoad(ID5,this);
    m_aBmpBtn6.   AutoLoad(ID6,this);
    m_aBmpBtn7.   AutoLoad(ID7,this);  
    ////////////////////////////////////////////////////////////////////
      /*   屏幕dc初始化*/   
      HDC   screenDC;   
      int   colorBits,   xRes,   yRes;  
      screenDC  =  CreateDC("DISPLAY",   NULL,   NULL,   NULL);  
      /*   检索设备   */   
      colorBits   =   GetDeviceCaps(screenDC,   BITSPIXEL);//颜色深度   
      xRes  =   GetDeviceCaps(screenDC,   HORZRES);//宽   
      yRes   =   GetDeviceCaps(screenDC,   VERTRES);//高   
      /*   清除   */   
    //  DeleteDC(dc);   
      ShowWindow(SW_SHOWMAXIMIZED);//对话框全屏
       SetWindowLong(m_hWnd,   GWL_STYLE,     
                      GetWindowLong(m_hWnd,   GWL_STYLE)   &     
              (~(WS_CAPTION   |   WS_BORDER)));  //取消标题栏  
      
    ////////////////////////////////////////////////////////////////////
        CWnd *pWnd;
        pWnd = GetDlgItem(IDC_STATIC);    //图片全屏    
        pWnd->MoveWindow( CRect(0,0,xRes,yRes) );
        
      CWnd *pWnd1,*pWnd2,*pWnd3,*pWnd4,*pWnd5,*pWnd6,*pWnd7;
       pWnd1 = GetDlgItem(ID2);    // 
       pWnd1->MoveWindow( CRect(xRes*0.42,yRes*0.16,xRes*0.42+127,yRes*0.16+47) );
       pWnd2 = GetDlgItem(ID1);    // 
       pWnd2->MoveWindow( CRect(xRes*0.15,yRes*0.16,xRes*0.15+127,yRes*0.16+47) );
       pWnd3 = GetDlgItem(ID3);    // 
       pWnd3->MoveWindow( CRect(xRes*0.25,yRes*0.35,xRes*0.25+127,yRes*0.35+47) );
       pWnd4 = GetDlgItem(ID4);    // 
       pWnd4->MoveWindow( CRect(xRes*0.10,yRes*0.53,xRes*0.10+127,yRes*0.53+47) );
       pWnd5 = GetDlgItem(ID5);    // 
       pWnd5->MoveWindow( CRect(xRes*0.04,yRes*0.76,xRes*0.04+84,yRes*0.76+47) );
       pWnd6 = GetDlgItem(ID6);    // 
       pWnd6->MoveWindow( CRect(xRes*0.22,yRes*0.83,xRes*0.22+84,yRes*0.83+47) );
       pWnd7 = GetDlgItem(ID7);    // 
       pWnd7->MoveWindow( CRect(xRes*0.79,yRes*0.27,xRes*0.79+127,yRes*0.27+47) );

    return TRUE;  // return TRUE  unless you set the focus to a control
    }void CUJNDlg::OnSysCommand(UINT nID, LPARAM lParam)
    {
    if ((nID & 0xFFF0) == IDM_ABOUTBOX)
    {
    CAboutDlg dlgAbout;
    dlgAbout.DoModal();
    }
    else
    {
    CDialog::OnSysCommand(nID, lParam);
    }
    }// If you add a minimize button to your dialog, you will need the code below
    //  to draw the icon.  For MFC applications using the document/view model,
    //  this is automatically done for you by the framework.void CUJNDlg::OnPaint() 
    {
    if (IsIconic())
    {
    CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle
    int cxIcon = GetSystemMetrics(SM_CXICON);
    int cyIcon = GetSystemMetrics(SM_CYICON);
    CRect rect;
    GetClientRect(&rect);
    int x = (rect.Width() - cxIcon + 1) / 2;
    int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon
    dc.DrawIcon(x, y, m_hIcon);
    }
    else
    {
    CDialog::OnPaint();
    }
    }// The system calls this to obtain the cursor to display while the user drags
    //  the minimized window.
    //HCURSOR m_hCursor;
     //m_hCursor = AfxGetApp()->LoadCursor(IDXJ);
     //m_hCursor = LoadCursorFromFile(".\\res\\IDXJ.cur");
    //SetCursor(AfxGetApp()->LoadStandardCursor(IDC_CROSS));
               
        //m_cursor = LoadCursorFromFile(".\\res\\IDXJ.cur");BOOL CUJNDlg::OnSetCursor(CWnd *pWnd, UINT nHitTest, UINT message)
    {   //m_cursor = LoadCursorFromFile(".\\res\\IDXJ.cur");
       // m_cursor = AfxGetApp()->LoadCursor(IDC_CURSOR1);
    HCURSOR m_hCursor;
    m_hCursor=::LoadCursor(NULL, MAKEINTRESOURCE(IDC_CURSOR2));
    SetCursor(m_hCursor);//m_hCursor,自己定义的, 
       // ::SetCursor(m_cursor);    return TRUE;//CDialog::OnSetCursor(pWnd, nHitTest, message); 

    }
    HCURSOR CUJNDlg::OnQueryDragIcon()
    {
    return (HCURSOR) m_hIcon;
    }
    void CUJNDlg::On1() 
    {
    // TODO: Add your control notification handler code here

    }void CUJNDlg::On2() 
    {
    // TODO: Add your control notification handler code here

    }void CUJNDlg::On3() 
    {
    // TODO: Add your control notification handler code here

    }void CUJNDlg::On4() 
    {
    // TODO: Add your control notification handler code here
    CJDlg dlg;
    dlg.DoModal();

    }void CUJNDlg::On5() 
    {
    // TODO: Add your control notification handler code here

    }void CUJNDlg::On6() 
    {
    // TODO: Add your control notification handler code here
    CDialog::OnOK();

    }void CUJNDlg::On7() 
    {
    // TODO: Add your control notification handler code here

    }
    我要崩溃了!!!这是整个CUJNDlg.CPP的源代码,麻烦高手给看看吧,没辙了~
      

  10.   

    HCURSOR m_hCursor;  这个好像不能定义为局部变量吧,把它放在头文件中定义.
      

  11.   

    把m_hCursor定义到.文件中,OnInitDialog中
    m_hCursor=::LoadCursor(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDC_CURSOR1));
    然后
    BOOL CUJNDlg::OnSetCursor(CWnd *pWnd, UINT nHitTest, UINT message) 
    {  
        SetCursor(m_hCursor);//m_hCursor,自己定义的, 
        return TRUE;//CDialog::OnSetCursor(pWnd, nHitTest, message); }