begin process at 2008 07 06 13:04:39
1 205 544 membres
121 nouveaux aujourd'hui
14 119 membres club

Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum.
Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !

CLASSE POUR UTILISER CARDS.DLL FACILEMENT


Information sur la source

Catégorie :Jeux Classé sous : cardsdll, cartes, cards Niveau : Débutant Date de création : 15/06/2006 Date de mise à jour : 16/06/2006 21:58:28 Vu / téléchargé: 3 677 / 156

Note :
Aucune note

Commentaire sur cette source (13)
Ajouter un commentaire et/ou une note

Description

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

Source

  • // 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);
  • }
// 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);
}
Pour les "Membres Club", vous pouvez télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !

Télécharger le zip

16 juin 2006 16:43:42 :
- Ajouté le HDC en argument aux fonctions. - Enlevé un pointeur inutile :P
16 juin 2006 21:58:29 :
Enlevé la fonction GetDC() qui n'était même plus définie :P, puis ajouter une surcharge a DrawCard().
  • signaler à un administrateur
    Commentaire de Galmiza le 16/06/2006 15:11:50

    # bool MyCards::SetDefaultCardSize(int Height, int Width)
    # {
    #     int *i;
    #     int *j;
    #     BOOL ret;
    #  
    #     i = new int;
    #     j = new int;
    #  
    #     (*i)=Height;
    #     (*j)=Width;
    #  
    #     ret = cdtInit(i,j);
    #     if ( !ret )
    #         return 0;
    #  
    #     return 1;
    # }

    Ca ne revient pas au même de faire ça ?

    # bool MyCards::SetDefaultCardSize(int Height, int Width)
    # {
    #     return cdtInit(&Height,&Width);
    # }

    Je n'ai pas encore essayé mais ça a l'air sympathique.
    Ca facilite grandement le bouleau de ceux qui veulent faire des jeux de cartes quelconques.

  • signaler à un administrateur
    Commentaire de vecchio56 le 16/06/2006 15:15:41 administrateur CS

    Pourquoi retourner 0 ou 1 dans une fonction bool, et pas true/false.
    Ca change pas grand chose, mais dans ce cas autant mettre le fonction en int

    Je suis pas sûr que garder un m_hDC soit une bonne solution. Je l'aurais plutot demandé en argument. Du coupr, m_hWnd n'est plus utile non plus

    # if ( !ret )
    #         return 0;
    #  
    #     return 1;
    Tu peux remplacer ca par return ret; c'est plus joli

    Et dans SetDefaultCardSize, j'ai pas compris pourquoi tu utiliser des pointeurs et des new
    N'est-ce pas équivalent a ca?
    bool MyCards::SetDefaultCardSize(int Height, int Width)
    {
      return cdtInit(Height, Width);
    }

  • signaler à un administrateur
    Commentaire de vecchio56 le 16/06/2006 15:16:30 administrateur CS

    Ah je me suis fait grillé, ca m'apprendra a écrire de longs messages!

  • signaler à un administrateur
    Commentaire de gbourgeois0019 le 16/06/2006 16:40:38

    Merci pour vos commentaires et j'ai apporté les midifications nécessaires :)

    J'ai suivi ton conseil vecchio56 et j'ai mis le HDC en argument comme je l'avais fait au tout debut.

  • signaler à un administrateur
    Commentaire de vecchio56 le 16/06/2006 19:55:55 administrateur CS

    Il te reste encore une méthode getDC() qui traine...
    Je vois que tu essaie de fournir pas mal de méthodes DrawCard
    Je pense que tu pourrais en donner une qui prend en paramètre un RECT (qui contiendra donc la position et la taille)

  • signaler à un administrateur
    Commentaire de gbourgeois0019 le 16/06/2006 21:41:44

    Ah ok merci ! J'arrange ca et j'update dans pas long ! ;)

  • signaler à un administrateur
    Commentaire de Renfield le 23/06/2006 11:33:07 administrateur CS

    y'a une mauvaise compréhension de
    return cdtInit(&Height,&Width);

    cdtInit renvoie la taille des cartes que la dll sais dessiner....
    elle ne permet aucunement de la personnaliser...

  • signaler à un administrateur
    Commentaire de vecchio56 le 23/06/2006 11:40:41 administrateur CS

    Le retour de cdtInit est pour test d'erreur a mon avis. Mais cette fonction sert bien a initialiser la librairie (grace au deux paramètres Height et Width)
    Je vois pas trop non plus pourquoi on passe leur adresse plutot que leur valeur (a moins que les valeurs puissent être modifiées par cdtInit, si par exemple toutes les tailles ne sont pas possibles)

  • signaler à un administrateur
    Commentaire de Renfield le 23/06/2006 12:13:42 administrateur CS

    à Initialiser la librairie, oui, je ne discute pas ce point.

    la fonction en profite juste pour fournir les dimensions des cartes...
    le code :
    SetDefaultCardSize(30,20);

    est donc faux...

  • signaler à un administrateur
    Commentaire de vecchio56 le 23/06/2006 12:46:07 administrateur CS

    En fait cdtInit récupère la taille des cartes, qu'on ne peut donc pas choisir (apparemment 71x96)

  • signaler à un administrateur
    Commentaire de vecchio56 le 23/06/2006 12:48:05 administrateur CS

    (c'est la fonction cdtDrawExt qui permet de choisir la taille des cartes à dessiner)

  • signaler à un administrateur
    Commentaire de Renfield le 23/06/2006 14:11:08 administrateur CS

    on est donc finallement tombés d'accord ^^

  • signaler à un administrateur
    Commentaire de gbourgeois0019 le 23/06/2006 15:31:42

    effectivement c'est moi qui a fait une erreur en lisant l'aide des fonction sur le net. L'aide dit ceci :

    Initializes the cards.dll library for your application. You must supply the addresses of two variables, in which cards.dll stores the width and height (in pixels) of a card.

    On ne peut donc decider de la taille de la carte qu'avec la fonction cdtDrawEx.

    Je vais corriger ca dans pas long ...

    Merci ;)

Ajouter un commentaire

Pub



Appels d'offres

Plugin Dialer outlook
Budget : 2 000€
Travail graphique- ill...
Budget : 1 000€
creation de marque et ...
Budget : 1 000€

CalendriCode

Juillet 2008
LMMJVSD
 123456
78910111213
14151617181920
21222324252627
28293031   

VS Express FR Gratuit !

VS Express en français et 100% gratuit !

Téléchargements

Logiciels à télécharger sur le même thème :

Boutique

Boutique de goodies CodeS-SourceS