Wednesday, August 09, 2006
Loading a color cursor in .NET 2.0
The MSDN documentation on the Cursor class says
The Cursor class does not support animated cursors (.ani files) or cursors with colors other than black and white.Consequently, if you try to display a color cursor, it appears as a black outline of the original. So, supposing that you already have a .cur file containing a color cursor, follow these steps to display it. If you don't already have a color .cur file, you can use Visual Studio 2005 to create such a file.
- Add the .cur to the project's resources using the Visual Studio 2005 resource designer by using the the "Add existing file" toolbar item. I'm going to assume that you named the resource "hand2."
-
Add a P/Invoke declaration for LoadCursorFromFile.
[DllImport("user32.dll")] static extern IntPtr LoadCursorFromFile(string lpFileName);
-
At runtime, copy the cursor resource to a temporary file, ask the Win32 API to load that file as a cursor, and create .NET Cursor object from the Win32 handle.
private Cursor LoadColorHandCursor() { string path = Path.GetTempFileName(); File.WriteAllBytes(path, Properties.Resources.hand2); Cursor hand = new Cursor(LoadCursorFromFile(path)); File.Delete(path); return hand; }
Here's a working code example.
Friday, August 04, 2006
Cramer says oil will be more expensive
Jim Cramer of Real Money, Real Money, and Mad Money, who claims to have made some pretty good money in his day by correctly betting on rising energy prices, thinks the price of oil isn't getting any cheaper. He gave a number of reasons for this.
- The US has been reluctant to build liquified natural gas receiving facilities, restricting the import of NG, and increasing demand for oil for energy generation.
- Nigeria, which ranks with Kuwait as an oil exporter, has enormous internal strife, which is beginning to drive out the foreign oil companies.
- Venezuela and Iran, the number five and four oil exporters, are posturing to make the US feel insecure about its oil supply.
- Ethanol could help moderate gas prices, but the US has a $0.54/gallon tariff, which prevents importing otherwise plentiful and cheap supplies.
- With gas prices above $3/gallon, demand is not slackening. Folks are cutting other budget items, rather than driving less.