drawing Cards

Share your advanced PureBasic knowledge/code with the community.
User avatar
Rings
Moderator
Moderator
Posts: 1435
Joined: Sat Apr 26, 2003 1:11 am

drawing Cards

Post by Rings »

windows only
This code uses the cards.dll from the windows-systemdrawer.
feel free to create you own blackjack now :)

Code: Select all

Procedure CardDraw(hdc,NR,X,Y,X2,Y2)
 Result=OpenLibrary(1,"cards.dll")
 If Result
  cdtInit=IsFunction(1,"cdtInit")
  cdtDrawExt=IsFunction(1,"cdtDrawExt")
  cdtTerm=IsFunction(1,"cdtTerm")
 EndIf
 Result=CallFunctionFast(cdtInit,@w,@h)
 Result=CallFunctionFast(cdtDrawExt,hdc,X,Y,X2,Y2,NR,0,0)
 Result= CallFunctionFast(cdtTerm)
 CloseLibrary(1)
EndProcedure

If OpenWindow(0, 0, 0, 400, 300, #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget|#PB_Window_TitleBar, "click this window to draw a card ")
    Repeat
        ev.l = WaitWindowEvent()
        If ev=513
             beep_(100,100)      
             hdc.l = StartDrawing(WindowOutput())
             CardDraw(hdc,Random(60),WindowMouseX(),WindowMouseY(),80,100)
             StopDrawing()
        EndIf
    Until ev=#PB_Event_CloseWindow
EndIf
End
SPAMINATOR NR.1
Fred
Administrator
Administrator
Posts: 18249
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

Excellent ;)
LarsG
Enthusiast
Enthusiast
Posts: 713
Joined: Mon Jun 02, 2003 1:06 pm
Location: Norway
Contact:

Post by LarsG »

I get a "Syntax Error!" on line 4... 8O :(

AMD Athlon XP2400, 512 MB RAM, Hercules 3D Prophet 9600 256MB RAM, WinXP
PIII 800MHz, 320 MB RAM, Nvidia Riva Tnt 2 Mach 64 (32MB), WinXP + Linux
17" iMac, 1.8 GHz G5, 512 MB DDR-RAM, 80 GB HD, 64 MB Geforce FX 5200, SuperDrive, OSX
RJP Computing
Enthusiast
Enthusiast
Posts: 202
Joined: Sun Apr 27, 2003 4:44 am
Location: Michigan, USA
Contact:

Post by RJP Computing »

Where can I find the documentation on the DLL. That would be fun to use.

Thanks
-Ryan
RJP Computing

Ubuntu 8.10/WinXP, AMD Athlon 64 3000+, 1000MB RAM, AC 97 Audio, nVidia GeForce 7600GT 512MB
User avatar
Rings
Moderator
Moderator
Posts: 1435
Joined: Sat Apr 26, 2003 1:11 am

Post by Rings »

RJP Computing wrote:Where can I find the documentation on the DLL. That would be fun to use.

Thanks
http://www.google.de/search?q=cards.dll ... uche&meta=
SPAMINATOR NR.1
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post by Karbon »

Now that's a tip n' trick! Awesome!
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: drawing Cards

Post by PB »

> This code uses the cards.dll from the windows-systemdrawer.

Note that this file is only installed if the user chose to install Games
when installing Windows. (I didn't and your example crashes). :wink:
midebor
User
User
Posts: 26
Joined: Fri Apr 25, 2003 10:22 pm
Location: Liege, Belgium

Post by midebor »

On my system (win 98) I found cards.dll and cards32.dll in the windows/system drawer. Using cards.dll produces system error but with cards32.dll everything works fine.

Michel
midebor
User
User
Posts: 26
Joined: Fri Apr 25, 2003 10:22 pm
Location: Liege, Belgium

Post by midebor »

Just to show the value of the cards I modified your code as follows: :)

Code: Select all

Procedure CardDraw(hdc,NR,X,Y,X2,Y2) 
Result=OpenLibrary(1,"cards32.dll") 
If Result 
  cdtInit=IsFunction(1,"cdtInit") 
  cdtDrawExt=IsFunction(1,"cdtDrawExt") 
  cdtTerm=IsFunction(1,"cdtTerm") 
EndIf 
Result=CallFunctionFast(cdtInit,@w,@h) 
Result=CallFunctionFast(cdtDrawExt,hdc,X,Y,X2,Y2,NR,0,0) 
Result= CallFunctionFast(cdtTerm) 
CloseLibrary(1) 
EndProcedure 

If OpenWindow(0, 0, 0, 400, 300, #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget|#PB_Window_TitleBar, "click this window to draw a card ") 
    Repeat 
        ev.l = WaitWindowEvent() 
        If ev=513 
             beep_(100,100)      
             hdc.l = StartDrawing(WindowOutput())
             For a=0 To 3
             For i=a To 51 Step 4
             CardDraw(hdc,i,WindowMouseX(),WindowMouseY(),80,100)
             Delay(500)
             Next i
             Next a
             StopDrawing() 
        EndIf 
    Until ev=#PB_Event_CloseWindow 
EndIf 
End
Michel
TronDoc
Enthusiast
Enthusiast
Posts: 310
Joined: Wed Apr 30, 2003 3:50 am
Location: 3DoorsDown

no32

Post by TronDoc »

I have w98fe and get the system error message.
I do not have cards32.dll only cards.dll.
Any way to make this work?
The games that came with windoze work fine.
Thanks.
Joe
peace
[pI 166Mhz 32Mb w95]
[pII 350Mhz 256Mb atir3RagePro WinDoze '98 FE & 2k]
[Athlon 1.3Ghz 160Mb XPHome & RedHat9]
midebor
User
User
Posts: 26
Joined: Fri Apr 25, 2003 10:22 pm
Location: Liege, Belgium

Post by midebor »

@TronDoc
Send me an email
User avatar
Rook Zimbabwe
Addict
Addict
Posts: 4322
Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:

Post by Rook Zimbabwe »

Just thought I would play with this for an idea I had...

Code: Select all

; modified from original 3.94
; not without some difficulty
;
Enumeration
    #Library
    #Window
EndEnumeration

Procedure CardDraw(hdc,NR,X,Y,X2,Y2)
Result=OpenLibrary(#Library,"cards32.dll") ; or cards.dll
If Result
  ;cdtInit=IsFunction(1,"cdtInit")
  ;cdtDrawExt=IsFunction(1,"cdtDrawExt")
   ;cdtTerm=IsFunction(1,"cdtTerm")
   
  *cdtInit = GetFunction(#Library, "cdtInit")
  *cdtDrawExt = GetFunction(#Library, "cdtDrawExt")
  *cdtTerm = GetFunction(#Library,"cdtTerm")
EndIf

Result=CallFunctionFast(*cdtInit,@w,@h)
Result=CallFunctionFast(*cdtDrawExt,hdc,X,Y,X2,Y2,NR,0,0)
Result= CallFunctionFast(*cdtTerm)

CloseLibrary(#Library)

EndProcedure

If OpenWindow(#Window, 0, 0, 800, 600,"Click this window to draw a card ", #PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_TitleBar)
    Repeat
        ev.l = WaitWindowEvent()
        If ev=513
             Beep_(100,100)     
             hdc.l = StartDrawing(WindowOutput(#Window))
             For a=0 To 3
             For i=a To 51 Step 4
             CardDraw(hdc,i,WindowMouseX(#Window),WindowMouseY(#Window),80,100)
             Delay(500)
             Next i
             Next a
             StopDrawing()
        EndIf
    Until ev=#PB_Event_CloseWindow
EndIf
End
I get an error on line 21 evary time... I thought I had midified it to the new standard... what did I do wrong? :oops:
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
maw

Post by maw »

Because you CallFunctionFast() even if OpenLibrary fails in the procedure CardDraw...
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

I have changed the code with check, enableexplicit and prototypes

Code: Select all

EnableExplicit

Enumeration
  #Library
  #Window
EndEnumeration

Prototype cdtInit(a, b)
Prototype cdtDrawExt(a, b, c, d, e, f, g = 0, h = 0)
Prototype cdtTerm()

Procedure CardDraw(hdc, NR, X, Y, X2, Y2)
  Protected w.l, h.l
  If OpenLibrary(#Library, "cards.dll") ; or cards32.dll
    Protected cdtInit.cdtInit = GetFunction(#Library, "cdtInit")
    Protected cdtDrawExt.cdtDrawExt = GetFunction(#Library, "cdtDrawExt")
    Protected cdtTerm.cdtTerm = GetFunction(#Library, "cdtTerm")
    cdtInit(@w, @h)
    cdtDrawExt(hdc, X, Y, X2, Y2, Nr)
    cdtTerm()
  Else
    Debug "DLL not found"
  EndIf
  
  CloseLibrary(#Library)
  
EndProcedure

Define.l ev, hdc, a, i
If OpenWindow(#Window, 0, 0, 800, 600, "Click this window to draw a card ", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_TitleBar)
  Repeat
    ev.l = WaitWindowEvent(500)
    If ev = 513
      Beep_(100, 100)
      hdc.l = StartDrawing(WindowOutput(#Window))
        For a = 0 To 3
          For i = a To 51 Step 4
            CardDraw(hdc, i, WindowMouseX(#Window), WindowMouseY(#Window), 80, 100)
          Next i
        Next a
      StopDrawing()
    EndIf
  Until ev = #PB_Event_CloseWindow
EndIf
End
I have only cards.dll on winxp. On vista is another dll and doesn't work

greetings
Thomas
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
Rook Zimbabwe
Addict
Addict
Posts: 4322
Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:

Post by Rook Zimbabwe »

Thomas! You got ir in one!!! Great Job!!!

Now I have to figure out how to get card clicked... I may chuck the cards.dll and just load about 55 sprites as a deck... Off a single PNG or something so I can get CLICKED on card and throw them around the screen much easier... Hmmm?

Onward, thank you for showing me a way! :D
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
Post Reply