Page 1 sur 1

Comment utiliser un prototype dans une procédure ?

Publié : mer. 27/août/2014 19:33
par falsam
Je ne sais pas utiliser un prototype dans une procédure.

Pour cette exemple, Je souhaite capturer le bureau de window.

■ Ce code sans procédure fonctionne

Code : Tout sélectionner

;Préparation du prototype générant la fonction "PrintWindow"
Prototype.i ptPrintWindow(hWnd, hdc, flags)

OpenLibrary(1, "User32.dll")
PrintWindow.ptPrintWindow = GetFunction(1, "PrintWindow")

;Dimension du desktop
ExamineDesktops()
Width + DesktopWidth(0)
Height + DesktopHeight(0)

;Quel est le handle du Desktop
hWnd = FindWindow_(0,"Program Manager")

;Capture du Desktop
Image = CreateImage(#PB_Any, Width, height, 24)
Result = StartDrawing(ImageOutput(Image))
Delay(10)
PrintWindow(hWnd, Result, 0)
StopDrawing()

ShowLibraryViewer("Image", Image)
CallDebugger
Vous devez voir l'image dans le visualisateur de bibliothéque.

■ Par contre si je veux utiliser une procédure la fonction déclarée dans mon prototype devient inexistante.

Code : Tout sélectionner

;Préparation du prototype générant la fonction "PrintWindow"
Prototype.i ptPrintWindow(hWnd, hdc, flags)

OpenLibrary(1, "User32.dll")
PrintWindow.ptPrintWindow = GetFunction(1, "PrintWindow")

Procedure Capture()
  ;Dimension du desktop
  ExamineDesktops()
  Width + DesktopWidth(0)
  Height + DesktopHeight(0)

  ;Quel est le handle du Desktop
  hWnd = FindWindow_(0,"Program Manager")

  ;Capture du Desktop
  Image = CreateImage(#PB_Any, Width, height, 24)
  Result = StartDrawing(ImageOutput(Image))
  Delay(10)
  PrintWindow(hWnd, Result, 0)
  StopDrawing()
EndProcedure  

Capture()

ShowLibraryViewer("Image", Image)
CallDebugger
Merci d'avance pour votre aide :)

Re: Comment utiliser un prototype dans une procédure ?

Publié : mer. 27/août/2014 19:43
par nico
Global PrintWindow.ptPrintWindow

Il faut que tu prennes l'habitude de mettre des if pour tester les fonctions.

Re: Comment utiliser un prototype dans une procédure ?

Publié : mer. 27/août/2014 22:34
par falsam
nico a écrit :Global PrintWindow.ptPrintWindow
Evidement :oops:
nico a écrit :l faut que tu prennes l'habitude de mettre des if pour tester les fonctions.
C'est le cas normalement. je voulais aller à l'essentiel. Merci encore pour ton aide.