Help!!! How to change Cursor Permanent ???
-
Hi I want to change the default cursor in my app. I tried following code. bool m_bcursor; BOOL CTestDlg::OnInitDialog() { CDialog::OnInitDialog(); // TODO: Add extra initialization here lhCursor = AfxGetApp()->LoadCursor(IDC_CURSOR); SetCursor(lhCursor); m_bcursor = true; //set to true return TRUE; // return TRUE unless you set the focus to a control } BOOL CTestDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) { // TODO: Add your message handler code here and/or call default if(m_bcursor) return true; else return CDialog::OnSetCursor(pWnd, nHitTest, message); } But whenever I open About Dialog, cursor it changed to default cursor. What should I do to change cursor the moment my main dialog gets focus?
-
Hi I want to change the default cursor in my app. I tried following code. bool m_bcursor; BOOL CTestDlg::OnInitDialog() { CDialog::OnInitDialog(); // TODO: Add extra initialization here lhCursor = AfxGetApp()->LoadCursor(IDC_CURSOR); SetCursor(lhCursor); m_bcursor = true; //set to true return TRUE; // return TRUE unless you set the focus to a control } BOOL CTestDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) { // TODO: Add your message handler code here and/or call default if(m_bcursor) return true; else return CDialog::OnSetCursor(pWnd, nHitTest, message); } But whenever I open About Dialog, cursor it changed to default cursor. What should I do to change cursor the moment my main dialog gets focus?
You need to set the cursor each time the OnSetCursor message is triggered. Dump the boolean member variable, and make the handle to the cursor a member variable of the dialog box: HCURSOR m_hCursor; Initialize it in the constructor: CMyDialog::CMyDialog() : m_hCursor(NULL) { m_hCursor = AfxGetApp()->LoadCursor(IDC_MYCURSOR); } and in OnSetCursor()... if (m_hCursor != NULL) { SetCursor(m_hCursor); return TRUE; } // default stuff here
:cool: Pssst. You see that little light on your monitor? That's actually a government installed spy camera. Smile and wave to big brother!
-
You need to set the cursor each time the OnSetCursor message is triggered. Dump the boolean member variable, and make the handle to the cursor a member variable of the dialog box: HCURSOR m_hCursor; Initialize it in the constructor: CMyDialog::CMyDialog() : m_hCursor(NULL) { m_hCursor = AfxGetApp()->LoadCursor(IDC_MYCURSOR); } and in OnSetCursor()... if (m_hCursor != NULL) { SetCursor(m_hCursor); return TRUE; } // default stuff here
:cool: Pssst. You see that little light on your monitor? That's actually a government installed spy camera. Smile and wave to big brother!
Good advice! But you do not need to maintain a copy of the cursor handle. From MSDN: "The LoadCursor function loads the cursor resource only if it has not been loaded; otherwise, it retrieves the handle to the existing resource." In other words, the system maintains a copy of the cursor handle for you. SetCursor(AfxGetApp()->LoadCursor(IDC_MYCURSOR)); The cursor is a resource included in the .exe (or sytem resoruces). Therefore, you do not need to test the handle. If the handle returned is not valid then there is a much bigger problem involved (and the program has locked up or crashed, do to lack of memory). INTP
-
You need to set the cursor each time the OnSetCursor message is triggered. Dump the boolean member variable, and make the handle to the cursor a member variable of the dialog box: HCURSOR m_hCursor; Initialize it in the constructor: CMyDialog::CMyDialog() : m_hCursor(NULL) { m_hCursor = AfxGetApp()->LoadCursor(IDC_MYCURSOR); } and in OnSetCursor()... if (m_hCursor != NULL) { SetCursor(m_hCursor); return TRUE; } // default stuff here
:cool: Pssst. You see that little light on your monitor? That's actually a government installed spy camera. Smile and wave to big brother!
-
You need to set the cursor each time the OnSetCursor message is triggered. Dump the boolean member variable, and make the handle to the cursor a member variable of the dialog box: HCURSOR m_hCursor; Initialize it in the constructor: CMyDialog::CMyDialog() : m_hCursor(NULL) { m_hCursor = AfxGetApp()->LoadCursor(IDC_MYCURSOR); } and in OnSetCursor()... if (m_hCursor != NULL) { SetCursor(m_hCursor); return TRUE; } // default stuff here
:cool: Pssst. You see that little light on your monitor? That's actually a government installed spy camera. Smile and wave to big brother!
hi Jack Rabbit:rose: thanks a lot. it worked for me.:)