Type a page name and press Enter. You'll jump to the page if it exists, or you can create it if it doesn't.
To create a page in a module other than cards, prefix the name with the module name and a period.
CardsWrapper (cards)
.
using System;
using System.Drawing;
using System.Runtime.InteropServices;
namespace Cards
{
/// <summary>
/// Class wrapper to Cards.dll
/// </summary>
public sealed class Card
{
#region API Declares
[DllImport("C:\\WINDOWS\\system32\\cards.dll")]
private static extern bool cdtInit([In] ref int width, [In] ref int height);
[DllImport("C:\\WINDOWS\\system32\\cards.dll")]
private static extern int cdtDrawExt(IntPtr hDC, int x, int y, int dx, int dy,
int ecsCard, int ectDraw, int clr);
[DllImport("C:\\WINDOWS\\system32\\cards.dll")]
private static extern int cdtDraw(IntPtr hDC, int x, int y, int ecsCard,
int ectDraw, int clr);
[DllImport("C:\\WINDOWS\\system32\\cards.dll")]
private static extern int cdtAnimate(IntPtr hDC, int ecbCardBack, int x, int y, int iState);
#endregion
#region fields
private static int _standardWidth;
private static int _standardHeight;
#endregion
#region Constructor
static Card()
{
bool ret = Card.cdtInit(ref _standardWidth, ref _standardHeight);
if (!ret)
throw new ApplicationException("Can't load cards.dll !");
// free up library when process exits
AppDomain.CurrentDomain.ProcessExit += new EventHandler(CurrentDomain_ProcessExit);
}
#endregion
#region Public Static Members
public static void DrawFace(Graphics g, int x, int y, int width, int height, int faceValue, CardSuit suit, Color invertedColor)
{
if (faceValue<0 || faceValue>12)
throw new ArgumentOutOfRangeException("FaceValue", faceValue, "faceValue must be in the range 0 - 12.");
int cardValue = (int)suit + faceValue * 4;
IntPtr hDc = g.GetHdc();
try
{
cdtDrawExt(hDc, x, y, width, height, cardValue, invertedColor!=Color.Empty ? 2 : 0, ConvertColor(invertedColor));
}
finally
{
g.ReleaseHdc(hDc);
}
}
public static void DrawFace(Graphics g, int x, int y, int width, int height, int faceValue, CardSuit suit)
{
DrawFace(g, x, y, width, height, faceValue, suit, Color.Empty);
}
public static void DrawFace(Graphics g, int x, int y, int faceValue, CardSuit suit, Color invertedColor)
{
if (faceValue<0 || faceValue>12)
throw new ArgumentOutOfRangeException("FaceValue", faceValue, "faceValue must be in the range 0 - 12.");
int cardValue = (int)suit + faceValue * 4;
IntPtr hDc = g.GetHdc();
try
{
cdtDraw(hDc, x, y, cardValue, invertedColor!=Color.Empty ? 2 : 0, ConvertColor(invertedColor));
}
finally
{
g.ReleaseHdc(hDc);
}
}
public static void DrawFace(Graphics g, int x, int y, int faceValue, CardSuit suit)
{
Card.DrawFace(g, x, y, faceValue, suit, Color.Empty);
}
public static void DrawDeck(Graphics g, int x, int y, int width, int height, CardDeck deck)
{
IntPtr hDc = g.GetHdc();
try
{
cdtDrawExt(hDc, x, y, width, height, (int)deck, 1, 0);
}
finally
{
g.ReleaseHdc(hDc);
}
}
public static void DrawDeck(Graphics g, int x, int y, CardDeck deck)
{
IntPtr hDc = g.GetHdc();
try
{
cdtDraw(hDc, x, y, (int)deck, 1, 0);
}
finally
{
g.ReleaseHdc(hDc);
}
}
public static void DrawDeck(Graphics g, int x, int y, int width, int height, Color backgroundColor)
{
IntPtr hDc = g.GetHdc();
try
{
cdtDrawExt(hDc, x, y, width, height, (int)CardDeck.CrossHatch, 1, Card.ConvertColor(backgroundColor));
}
finally
{
g.ReleaseHdc(hDc);
}
}
public static void DrawDeck(Graphics g, int x, int y, Color backgroundColor)
{
IntPtr hDc = g.GetHdc();
try
{
cdtDraw(hDc, x, y, (int)CardDeck.CrossHatch, 1, Card.ConvertColor(backgroundColor));
}
finally
{
g.ReleaseHdc(hDc);
}
}
#endregion
#region Properties
/// <summary>
/// Gets the standard width of the cards.
/// </summary>
public static int StandardWidth
{
get
{
return Card._standardWidth;
}
}
/// <summary>
/// Gets the standard height of the cards.
/// </summary>
public static int StandardHeight
{
get
{
return Card._standardHeight;
}
}
#endregion
#region private members
private static void CurrentDomain_ProcessExit(object sender, EventArgs e)
{
Card.cdtTerm();
}
private static int ConvertColor(Color c)
{
if (c!=Color.Empty)
return (Convert.ToInt32(c.B) << 16) + (Convert.ToInt32(c.G) << 8) + c.R;
return 0;
}
#endregion
}
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).