Sunday, August 2, 2009

Are Visual C++ codes choosy when it comes to operating systems?

I underwent two different activities and found out that my program will not function properly in Windows XP but it functions properly in Windows 2000. Does this mean that there are codes in Visual C++ that will work only for a specific Operating System?





If your answer is yes, how do I know if that code is for XP or 2000 or other OS?





If your answer is no, can you suggest a possible way of making this few lines of code in MFC to work in Windows XP? (This code works in Windows 2000)





char letter = char(nChar);


HCURSOR myCursor;





if(letter == 'A')


{


myCursor = AfxGetApp()-%26gt;LoadStandardCursor(IDC_WAIT...


SetCursor(myCursor);


}

Are Visual C++ codes choosy when it comes to operating systems?
The problem is you are doing things wrong. Wrong programming can manifest different behavior on different OSs.





The best way, in MFC to display the wait cursor is to create an instance of CWaitCursor.





if(letter == 'A')


{


CWaitCursor wait;


// do your stuff


// CWaitCursor destructor restores original cursor


}





If you want to display a custom cursor, you need to do two things. One, make sure the window class does not include a class cursor. Two, handle the WM_SETCURSOR message.





e.g.


case WM_SETCURSOR:


if (use_cursor1)


SetCursor(hMyCursor1);


else


SetCursor(hMyCursor2);


return TRUE;
Reply:The fault probably lies not in Visual C++, but in what the program does and how it chooses to do it. It may be doing something that works in Windows 2000 but changed in Windows XP. Or it may just not have considered testing for the specific operating system and taking into account the differences, especially in System function calls.





I wouldn't blame the compiler (Visual C++) for the programmer's shortsightedness.





Hope that helps.


No comments:

Post a Comment