Classe pour utiliser cards.dll facilement

Description

Il s'agit d'une classe très simple qui permet une utilisation simplifiée et facile de la librairie Cards.dll.

Source / Exemple :


// MyCards.h

/*****************************************

MyCards : Classe permettant d'utiliser facilement la librairie Cards.dll

Guillaume Bourgeois ( 14/06/06 )

                                                                                  • /
#include "windows.h" #define CLUBS 0 #define DIAMONDS 1 #define HEARTS 2 #define SPADES 3 #define ACE 0 #define TWO 1 #define THREE 2 #define FOUR 3 #define FIVE 4 #define SIX 5 #define SEVEN 6 #define EIGHT 7 #define NINE 8 #define TEN 9 #define JACK 10 #define QUEEN 11 #define KING 12 #define CS_CROSSHATCH 53 #define CS_WEAVE1 54 #define CS_WEAVE2 55 #define CS_ROBOT 56 #define CS_FLOWERS 57 #define CS_VINE1 58 #define CS_VINE2 59 #define CS_FISH1 60 #define CS_FISH2 61 #define CS_SHELLS 62 #define CS_CASTLE 63 #define CS_ISLAND 64 #define CS_CARDHAND 65 #define CS_UNUSED 66 #define CS_THE_X 67 #define CS_THE_O 68 #define MAKE_CARD_VALUE(Face, Suit) (Face * 4 + Suit) // Faces : 0 = Ace, 1 = Two , ... 10 = Jack, 11 = Queen, 12 = King. // Suit : 0 = Clubs, 1 = Diamond, 2 = Heart, 3 = Spades typedef BOOL (WINAPI *pfcdtInit)(int *, int *); typedef BOOL (WINAPI *pfcdtDraw)(HDC, int x, int y, int card, int type, DWORD color); typedef BOOL (WINAPI *pfcdtDrawEx)(HDC, int x, int y, int dx, int dy, int card, int type, DWORD color); typedef BOOL (WINAPI *pfcdtAnimate)(HDC hdc, int cardback, int x, int y, int state); typedef void (WINAPI *pfcdtTerm) (void); class MyCards { public: MyCards(); //Constructeur ~MyCards(); //Destructeur private: bool InitCardsDll(void); HMODULE hCardDll; pfcdtInit cdtInit; pfcdtDraw cdtDraw; pfcdtDrawEx cdtDrawEx; pfcdtAnimate cdtAnimate; pfcdtTerm cdtTerm; public: bool SetDefaultCardSize(int Height, int Width); bool DrawCard(HDC hDC, int x, int y, int CardValue, int Type, DWORD Color=0x00FFFFFF); bool DrawCard(HDC hDC, POINT Position, int CardValue, int Type, DWORD Color=0x00FFFFFF); bool DrawCard(HDC hDC, int x, int y, int Height, int Width, int CardValue, int Type, DWORD Color=0x00FFFFFF); bool DrawCard(HDC hDC, POINT Position, int Height, int Width, int CardValue, int Type, DWORD Color=0x00FFFFFF); bool DrawCard(HDC hDC, RECT Position, int CardValue, int Type, DWORD Color=0x00FFFFFF); // To make a card value use MAKE_CARD_VALUE(Face,Suit) // Type = 0 -> Front Face // Type = 1 -> Back face // Type = 3 -> Front Face ( Inverted colors ) }; /*************************************************************
                                                                                                                            • /
#include "MyCards.h" MyCards::MyCards() { if ( !InitCardsDll() ) ::MessageBox(0,"Unable to load Cards.dll","Error",MB_ICONERROR); SetDefaultCardSize(30,20); } MyCards::~MyCards() { cdtTerm(); ::FreeLibrary(hCardDll); } bool MyCards::InitCardsDll(void) { hCardDll = ::LoadLibrary("cards.dll"); if(hCardDll == 0) return 0; cdtInit = (pfcdtInit) GetProcAddress(hCardDll, "cdtInit"); cdtDraw = (pfcdtDraw) GetProcAddress(hCardDll, "cdtDraw"); cdtDrawEx = (pfcdtDrawEx) GetProcAddress(hCardDll, "cdtDrawExt"); cdtAnimate = (pfcdtAnimate) GetProcAddress(hCardDll, "cdtAnimate"); cdtTerm = (pfcdtTerm) GetProcAddress(hCardDll, "cdtTerm"); return 1; } bool MyCards::SetDefaultCardSize(int Height, int Width) { return cdtInit(&Height,&Width); } bool MyCards::DrawCard(HDC hDC, int x, int y, int CardValue, int Type, DWORD Color) { return cdtDraw(hDC,x,y,CardValue,Type,Color); } bool MyCards::DrawCard(HDC hDC, POINT Position, int CardValue, int Type, DWORD Color) { return cdtDraw(hDC,Position.x,Position.y,CardValue,Type,Color); } bool MyCards::DrawCard(HDC hDC, int x, int y, int Height, int Width, int CardValue, int Type, DWORD Color) { return cdtDrawEx(hDC,x,y,Height,Width,CardValue,Type,Color); } bool MyCards::DrawCard(HDC hDC, POINT Position, int Height, int Width, int CardValue, int Type, DWORD Color) { return cdtDrawEx(hDC,Position.x,Position.y,Height,Width,CardValue,Type,Color); } bool MyCards::DrawCard(HDC hDC, RECT Position, int CardValue, int Type, DWORD Color) { return cdtDrawEx(hDC,Position.left,Position.top, (Position.right-Position.left),(Position.bottom-Position.top),CardValue,Type,Color); }

Codes Sources

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.