Prev: strsafe.lib
Next: OnAccept() in CAsyncSocket
From: jc on 8 Apr 2010 20:02 Hello, I am trying to display an animated cursor. I found several examples, but none of the examples seem to work in my SDI app. When I use the anmiated cursor, the cursor completely vanishes. How can I display an animated cursor in an SDI app? VS2008 MFC BOOL CMyFormView::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) { // ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT)) ; //this works ::SetCursor(LoadAnimatedCursor(IDR_HOURGLASS)); //this fails return true; } HCURSOR CMyFormView::LoadAnimatedCursor(UINT nResID) { HRSRC hRes=FindResource(AfxGetInstanceHandle(),MAKEINTRESOURCE(nResID),"ANICURSORS"); DWORD dwSize=SizeofResource(AfxGetInstanceHandle(),hRes); HGLOBAL hGlob=LoadResource(AfxGetInstanceHandle(),hRes); LPBYTE pBytes=(LPBYTE)LockResource(hGlob); HCURSOR hCur=(HCURSOR)CreateIconFromResource(pBytes,dwSize,FALSE,0x00030000); return hCur; } TIA, -jc
From: AliR on 9 Apr 2010 08:58 On which line of LoadAnimatedCursor does it fail on? We can't really guess, but you have the tool in front of you to find the problem. Step through the code and check the retun value of the functions called to see which one is failing! AliR. "jc" <jc(a)discussions.microsoft.com> wrote in message news:52FCD892-6035-4632-A971-42C43D27CBBA(a)microsoft.com... > Hello, > > I am trying to display an animated cursor. > I found several examples, but none of the > examples seem to work in my SDI app. > When I use the anmiated cursor, the cursor > completely vanishes. > > How can I display an animated cursor in an > SDI app? VS2008 MFC > > BOOL CMyFormView::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) > { > > // ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT)) ; //this > works > ::SetCursor(LoadAnimatedCursor(IDR_HOURGLASS)); //this fails > > return true; > } > > HCURSOR CMyFormView::LoadAnimatedCursor(UINT nResID) > { > HRSRC > hRes=FindResource(AfxGetInstanceHandle(),MAKEINTRESOURCE(nResID),"ANICURSORS"); > DWORD dwSize=SizeofResource(AfxGetInstanceHandle(),hRes); > HGLOBAL hGlob=LoadResource(AfxGetInstanceHandle(),hRes); > LPBYTE pBytes=(LPBYTE)LockResource(hGlob); > HCURSOR > hCur=(HCURSOR)CreateIconFromResource(pBytes,dwSize,FALSE,0x00030000); > return hCur; > } > > TIA, > -jc
From: jc on 9 Apr 2010 11:19 Hello, Thank you for replying to my posting. I apologize for not providing more information. Yes, I did step through the code, and the value of hCur is NULL (last line). That's my question. Why is the value returned for CreateIconFromResource(...) NULL? TIA, -jc
From: Joseph M. Newcomer on 9 Apr 2010 11:19 My first reaction was "Do you know it is a valid animated cursor?" because if everything otherwise works but it isn't the right format, then it may not play. But you just said "didn't work" which could mean 1. I get no cursor 2. I get a cursor, but it is not the one I expect 3. I get the first frame of the animated cursor, but it doesn't animate You have to be precise. But after I read your code, I have more questions See below... On Thu, 8 Apr 2010 17:02:01 -0700, jc <jc(a)discussions.microsoft.com> wrote: >Hello, > >I am trying to display an animated cursor. >I found several examples, but none of the >examples seem to work in my SDI app. >When I use the anmiated cursor, the cursor >completely vanishes. > >How can I display an animated cursor in an >SDI app? VS2008 MFC > >BOOL CMyFormView::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) >{ > >// ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT)) ; //this works > ::SetCursor(LoadAnimatedCursor(IDR_HOURGLASS)); //this fails > > return true; >} > >HCURSOR CMyFormView::LoadAnimatedCursor(UINT nResID) >{ > HRSRC >hRes=FindResource(AfxGetInstanceHandle(),MAKEINTRESOURCE(nResID),"ANICURSORS"); **** ASSERT(hRes != NULL); *** > DWORD dwSize=SizeofResource(AfxGetInstanceHandle(),hRes); **** ASSERT(dwSize != 0); TRACE(_T("SizeofResource(%p, %p) = %u), AfxGetInstanceHandle, hRes, dwSize); **** > HGLOBAL hGlob=LoadResource(AfxGetInstanceHandle(),hRes); **** ASSERT(hGlob != NULL); *** > LPBYTE pBytes=(LPBYTE)LockResource(hGlob); **** ASSERT(pBytes != NULL); **** > HCURSOR >hCur=(HCURSOR)CreateIconFromResource(pBytes,dwSize,FALSE,0x00030000); **** ASSERT(hCur != NULL); Note it the TOTAL ABSENCE OF ANY ERROR CHCKING you have NO IDEA what is going on here,and you did not tell us that by examination with the debugger that every API succeeded! I admit, the ASSERTs are pretty primitive error checking, and I would have done if(...) return NULL; type of tests at every stage, but a supreme confidence in the correctness of code in the absence of any information proving such is part of being a programmer joe **** > return hCur; >} > >TIA, >-jc Joseph M. Newcomer [MVP] email: newcomer(a)flounder.com Web: http://www.flounder.com MVP Tips: http://www.flounder.com/mvp_tips.htm
From: jc on 9 Apr 2010 12:13
Hello Joe, Thank you for taking the time to reply to my posting. Perhaps, it was confusing, when I initially stated that the animated cursor vanishes. Maybe, I should have stated that there is no visible cursor. I tried replacing my animated cursor with a animated cursor, from a sample app, that works. Also, I used an animated cursor tool, and my animated cursor worked OK. Any ideas? TIA, jc |