Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

CopyIcon (user32)
 
.
Summary

C# Signature:

[DllImport("user32.dll")]
static extern IntPtr CopyIcon(IntPtr hIcon);

VB Signature:

<DllImport("user32.dll")> _
Public Shared Function CopyIcon(ByVal hIcon As IntPtr) As IntPtr
End Function

User-Defined Types:

None.

Notes:

Need to also include the following

[DllImport("user32.dll")]

static extern IntPtr LoadCursor(IntPtr hInstance, int lpCursorName);

None.

Tips & Tricks:

CopyCursor reference will fail at runtime, according to documentation it is a macro:

#define CopyCursor(pcur) ((HCURSOR)CopyIcon((HICON)(pcur)))

That means: instead of CopyCursor use CopyIcon instead.

Please add some!

Sample Code:

private static string BusyCursorIcon { get; set; }
private static string DoneCursorIcon { get; set; }

Please add some!

private const uint OCR_NORMAL = 32512;
private const uint OCR_WAIT = 32514;

Alternative Managed API:

Do you know one? Please contribute it!

[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
private static extern IntPtr LoadCursorFromFile(string lpFileName);

Documentation
CopyIcon on MSDN

[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
private static extern IntPtr CopyIcon(IntPtr hcur);

[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
private static extern bool SetSystemCursor(IntPtr hcur, uint id);

string folderPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
BusyCursorIcon = Path.Combine(folderPath, "aero_busy_xl.ani");
DoneCursorIcon = Path.Combine(folderPath, "arrow_m.cur");

if (!File.Exists(BusyCursorIcon) || !File.Exists(DoneCursorIcon))
{
   // AB: use api only to change cursor; same call will switch cursor!
   SetSystemCursor(LoadCursor(IntPtr.Zero, OCR_WAIT), OCR_NORMAL);
}
else
{
   IntPtr cursor = (working)  
    ? LoadCursorFromFile(BusyCursorIcon)
    : LoadCursorFromFile(DoneCursorIcon);
   if (cursor != IntPtr.Zero)
     SetSystemCursor(CopyIcon(cursor), OCR_NORMAL);
   else
     SetSystemCursor(LoadCursor(IntPtr.Zero, OCR_WAIT), OCR_NORMAL);
}

Alternative Managed API:

Do you know one? Please contribute it!

Documentation
CopyIcon on MSDN

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version
Revisions