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.Windows.Forms;
using System.Runtime.InteropServices;
namespace Cards
{
/// <summary>
/// A class wrapper to the cards.dll. This misses only the crlAnimate functionaliy.
/// </summary>
public class Card32
{
#region API Declares
[DllImport("cards.dll")]
private static extern bool cdtInit([In] ref int width, [In] ref int height);
[DllImport("cards.dll")]
private static extern int cdtDrawExt(IntPtr hDC, int x, int y, int dx, int dy,
int ecsCard, int ectDraw, int clr);
[DllImport("cards.dll")]
private static extern int cdtDraw(IntPtr hDC, int x, int y, int ecsCard,
int ectDraw, int clr);
[DllImport("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 Card32()
{
bool ret = Card32.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, bool inverted)
{
int cardValue = (int)suit + faceValue * 4;
IntPtr hDc = g.GetHdc();
try
{
cdtDrawExt(hDc, x, y, width, height, cardValue, inverted ? 2 : 0, 0);
}
finally
{
g.ReleaseHdc(hDc);
}
}
public static void DrawFace(Graphics g, int x, int y, int faceValue, CardSuit suit, bool inverted)
{
int cardValue = (int)suit + faceValue * 4;
IntPtr hDc = g.GetHdc();
try
{
cdtDraw(hDc, x, y, cardValue, inverted ? 2 : 0, 0);
}
finally
{
g.ReleaseHdc(hDc);
}
}
public static void DrawFace(Graphics g, int x, int y, int faceValue, CardSuit suit)
{
Card32.DrawFace(g, x, y, faceValue, suit, false);
}
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
{
Color color = Color.FromArgb(0, backgroundColor);
cdtDrawExt(hDc, x, y, width, height, (int)CardDeck.CrossHatch, 1, color.ToArgb());
}
finally
{
g.ReleaseHdc(hDc);
}
}
public static void DrawDeck(Graphics g, int x, int y, Color backgroundColor)
{
IntPtr hDc = g.GetHdc();
try
{
Color color = Color.FromArgb(0, backgroundColor);
cdtDraw(hDc, x, y, (int)CardDeck.CrossHatch, 1, color.ToArgb());
}
finally
{
g.ReleaseHdc(hDc);
}
}
#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).