[RESOLU] Imprimer une fenêtre

Vous débutez et vous avez besoin d'aide ? N'hésitez pas à poser vos questions
Anonyme 2
Messages : 183
Inscription : ven. 18/mars/2011 11:53

[RESOLU] Imprimer une fenêtre

Message par Anonyme 2 »

Yo, tout est dans le titre.. :roll:
J'a vus que la bibliothèque purebasic contenait un fonction pour imprimer, mais seulement une page que l'on a dessiner, et pas une fenêtre.
Comment faire dans ce cas?
Merci d'avance! :)
Dernière modification par Anonyme 2 le ven. 16/mars/2012 17:14, modifié 2 fois.
Avatar de l’utilisateur
Ar-S
Messages : 9540
Inscription : dim. 09/oct./2005 16:51
Contact :

Re: Imprimer une fenêtre

Message par Ar-S »

tu n'as cas créer une image de ta fenêtre puis l'imprimer..
Mots clés : PrintScreen, capture ecran

Voilà de quoi capturer l'ecran.

Code : Tout sélectionner

UseJPEGImageEncoder()

Procedure CaptEcran (Destination$ , LargSortie, HautSortie)
  
  EcranX.i = GetSystemMetrics_(#SM_CXSCREEN)
  EcranY.i = GetSystemMetrics_(#SM_CYSCREEN)
  
  Debug EcranX
  
  
  Im = CreateImage(1, EcranX, EcranY)
  
  If Im = 0
    ProcedureReturn 0
    
  Else 
    
    hwnd = GetDesktopWindow_()
    hDDC = GetDC_(hwnd)
    hDC = StartDrawing(ImageOutput(1))
    BitBlt_(hDC,0,0,ImageWidth(1),ImageHeight(1),hDDC,0,0,#SRCCOPY)
    StopDrawing()
    ReleaseDC_(hwnd,hDDC)
    
    If LargSortie = 0 Or HautSortie = 0 Or Str(LargSortie) = "" Or Str(HautSortie) = ""
      ResizeImage(Im, EcranX, EcranY)
      If LargSortie <> EcranX Or HautSortie <> EcranY
        ResizeImage(Im, LargSortie, HautSortie)
      EndIf

    EndIf
     
    Result = SaveImage(1, Destination$+FormatDate("LDVM_%yyyy_%mm_%dd_%hhh_%iim_%sss",Date())+".jpg",#PB_ImagePlugin_JPEG,8)
    FreeImage(1)
    If Result <> 0
      ProcedureReturn 1
    Else
      ProcedureReturn 0
    EndIf
    
  EndIf
  
EndProcedure

Test = CaptEcran("C:\",800,600)

; Si résultat = 1 alors ça a marché sinon resultat = 0
Debug Test

Ensuite en récupérant les coordonnées de la fenêtre, tu pourras te faire une découpe adéquat.
~~~~Règles du forum ~~~~
⋅.˳˳.⋅ॱ˙˙ॱ⋅.˳Ar-S ˳.⋅ॱ˙˙ॱ⋅.˳˳.⋅
W11x64 PB 6.x
Section HORS SUJET : ICI
LDV MULTIMEDIA : Dépannage informatique & mes Logiciels PB
UPLOAD D'IMAGES : Uploader des images de vos logiciels
Anonyme 2
Messages : 183
Inscription : ven. 18/mars/2011 11:53

Re: Imprimer une fenêtre

Message par Anonyme 2 »

Merci de ta réponse!
Il m'est venus à l'esprit d'utiliser comme tu l'as fait les API de windows, mais cela signifierais alors que l'on doit par la suite rogner manuellement?
Avatar de l’utilisateur
Ar-S
Messages : 9540
Inscription : dim. 09/oct./2005 16:51
Contact :

Re: Imprimer une fenêtre

Message par Ar-S »

Je réecris
Ensuite en récupérant les coordonnées de la fenêtre, tu pourras te faire une découpe adéquat.
C'est une façon de faire, il y a peut-être plus simple, en simulant ALT+PrintScreen via l'API sendmessage_
Pour info, sous Windows, Alt + printScreen ne copie que la fenêtre active :wink:
~~~~Règles du forum ~~~~
⋅.˳˳.⋅ॱ˙˙ॱ⋅.˳Ar-S ˳.⋅ॱ˙˙ॱ⋅.˳˳.⋅
W11x64 PB 6.x
Section HORS SUJET : ICI
LDV MULTIMEDIA : Dépannage informatique & mes Logiciels PB
UPLOAD D'IMAGES : Uploader des images de vos logiciels
Mesa
Messages : 1126
Inscription : mer. 14/sept./2011 16:59

Re: Imprimer une fenêtre

Message par Mesa »

Essaie ça, je pense que ça marche. Je l'ai trouvé quelque part sur le forum, il y a déjà un certain temps. Il faudra ajouter la fonction d'impression.

Code : Tout sélectionner

; Auteur : Le Soldat Inconnu
; Version de PB : 4.41
;
; Explication du programme :
; Faire une copie d'écran

UsePNGImageEncoder()
UseJPEGImageEncoder()
; UsePNGImageDecoder()
; UseJPEGImageDecoder()

Global Format, Qualite, Type

Procedure CopieEcran()
  Protected Ecran.rect, Nb, Image, Image2, WinMouse, Fenetre.rect, FenetreHG.POINT
   
   Ecran_Largeur = GetSystemMetrics_(#SM_CXSCREEN)
   Ecran_Hauteur = GetSystemMetrics_(#SM_CYSCREEN)
   DC = GetDC_(0)
   Image2 = CreateImage(#PB_Any, Ecran_Largeur, Ecran_Hauteur)
   Dessin = StartDrawing(ImageOutput(Image2))
      BitBlt_(Dessin, 0, 0, Ecran_Largeur, Ecran_Hauteur, DC, 0, 0, #SRCCOPY | $40000000)
   StopDrawing()
   ReleaseDC_(0, DC)
 
  ; On découpe l'image suivant le Type
  Select Type
      Case 0
      ; Tout l'écran
         Fenetre\left = 0
      Fenetre\right = Ecran_Largeur
      Fenetre\top = 0
      Fenetre\bottom = Ecran_Hauteur
      Case 1
      ; L'écran sans la barre des taches
      SystemParametersInfo_(#SPI_GETWORKAREA, 0, @Fenetre.rect, 0)
      Case 2
      ; La fenêtre sous la souris
      WinMouse = WindowFromPoint_(DesktopMouseX() | DesktopMouseY() << 32)
         Repeat
            WinParent = GetParent_(WinMouse)
            If WinParent
               WinMouse = WinParent   
            EndIf
         Until WinParent = 0
      GetWindowRect_(WinMouse, Fenetre.rect)
      Case 3
      ; Uniquement le contenu de la fenêtre sous la souris
      WinMouse = WindowFromPoint_(DesktopMouseX() | DesktopMouseY() << 32)
         Repeat
            WinParent = GetParent_(WinMouse)
            If WinParent
               WinMouse = WinParent   
            EndIf
         Until WinParent = 0
         GetClientRect_(WinMouse, Fenetre.rect) : ClientToScreen_(WinMouse, FenetreHG.POINT)
      Fenetre\left + FenetreHG\x
      Fenetre\right + FenetreHG\x
      Fenetre\top + FenetreHG\y
      Fenetre\bottom + FenetreHG\y
      Case 4
         ; Uniquement l'objet sous la souris
      WinMouse = WindowFromPoint_(DesktopMouseX() | DesktopMouseY() << 32)
         ; WinAncestor = GetAncestor_(WinMouse, #GA_PARENT)
         ; If WinAncestor
         ; WinMouse = WinAncestor
         ; EndIf
      GetClientRect_(WinMouse, Fenetre.rect) : ClientToScreen_(WinMouse, FenetreHG.POINT)
      Fenetre\left + FenetreHG\x
      Fenetre\right + FenetreHG\x
      Fenetre\top + FenetreHG\y
      Fenetre\bottom + FenetreHG\y
   EndSelect
 
   If Fenetre\left < 0 : Fenetre\left = 0 : EndIf
   If Fenetre\top < 0 : Fenetre\top = 0 : EndIf
   If Fenetre\right > ImageWidth(Image2) : Fenetre\right = ImageWidth(Image2) : EndIf
   If Fenetre\bottom > ImageHeight(Image2) : Fenetre\bottom = ImageHeight(Image2) : EndIf
   Image = GrabImage(Image2, #PB_Any, Fenetre\left, Fenetre\top, Fenetre\right - Fenetre\left, Fenetre\bottom - Fenetre\top)
   
   FreeImage(Image2)
   If IsImage(Image)
      Visualiser = OpenWindow(#PB_Any, Fenetre\left, Fenetre\top, Fenetre\right - Fenetre\left, Fenetre\bottom - Fenetre\top, "Visualisation", #PB_Window_BorderLess)
      If Visualiser
         StickyWindow(Visualiser, 1)
         
         Image2 = CopyImage(Image, #PB_Any)
         StartDrawing(ImageOutput(Image2))
            DrawingMode(#PB_2DDrawing_AlphaBlend)
            For x = 0 To Fenetre\right - Fenetre\left - 1 Step 8
               For y = 0 To Fenetre\bottom - Fenetre\top - 1 Step 8
                  If ((x + y) / 8) & %1 = 1
                     Box(x, y, 8, 8, $40FFFFFF)
                  Else
                     Box(x, y, 8, 8, $40000000)
                  EndIf
               Next
            Next
         StopDrawing()
         
         Gadget = ImageGadget(#PB_Any, 1, 1, 0, 0, ImageID(Image2))
         GadgetToolTip(Gadget, "Clic gauche = Sauver  /  Clic droit = Annuler")
         
         Repeat
            Event = WaitWindowEvent()
            
            If Event = #PB_Event_Gadget
               If EventGadget() = Gadget
                  Select EventType()
                     Case #PB_EventType_LeftClick
                        Enregistrer = 1
                     Case #PB_EventType_RightClick
                        Enregistrer = -1
                  EndSelect
               EndIf
            EndIf
            
         Until Enregistrer <> 0
         
         CloseWindow(Visualiser)
         
         FreeImage(Image2)
      EndIf
   
      
      ; On enregistre l'image
      If Enregistrer > 0
         Nb = 0
         Repeat
            Nb + 1
         Until FileSize("Copie d'écran " + RSet(Str(Nb), 4, "0") + ".bmp") = -1 And FileSize("Copie d'écran " + RSet(Str(Nb), 4, "0") + ".png") = -1 And FileSize("Copie d'écran " + RSet(Str(Nb), 4, "0") + ".jpg") = -1
         
         Select Format
            Case 0
               Nom.s = "Copie d'écran " + RSet(Str(Nb), 4, "0") + ".bmp"
               SaveImage(Image, Nom, #PB_ImagePlugin_BMP)
            Case 1
               Nom.s = "Copie d'écran " + RSet(Str(Nb), 4, "0") + ".png"
               SaveImage(Image, Nom, #PB_ImagePlugin_PNG)
            Case 2
               Nom.s = "Copie d'écran " + RSet(Str(Nb), 4, "0") + ".jpg"
               SaveImage(Image, Nom, #PB_ImagePlugin_JPEG, Qualite)
         EndSelect
         SetGadgetText(5, Nom)
         
         MessageBeep_(#MB_OK)
      EndIf
      
      FreeImage(Image)
   EndIf

EndProcedure


Global KeyboardHook
Procedure LowLevelKeyboardProc(nCode.l, wParam.l, lParam.l)
   If nCode=#HC_ACTION
      Select wParam
         Case #WM_KEYDOWN
         Case #WM_KEYUP
            vkCode = PeekL(lParam)
            If vkCode = 44
               CopieEcran()
            EndIf
      EndSelect
   EndIf
   ProcedureReturn CallNextHookEx_(KeyboardHook, nCode, wParam, lParam)
EndProcedure
Procedure AddKeyboardHook()
   If KeyboardHook = 0
      KeyboardHook = SetWindowsHookEx_(#WH_KEYBOARD_LL, @LowLevelKeyboardProc(), GetModuleHandle_(0), 0)
   EndIf
   ProcedureReturn KeyboardHook
EndProcedure
Procedure RemoveKeyboardHook()
   If KeyboardHook
      UnhookWindowsHookEx_(KeyboardHook)
      KeyboardHook = 0
   EndIf
EndProcedure

; Format
; 0 = BMP
; 1 = PNG
; 2 = JPG



Procedure AffichageQualite()
  If Format = 2
    HideGadget(2, 0)
    HideGadget(3, 0)
  Else
    HideGadget(2, 1)
    HideGadget(3, 1)
  EndIf
EndProcedure





; Création de la fenêtre et de la GadgetList
If OpenWindow(0, 0, 0, 350, 296, "Copie d'écran", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_MinimizeGadget) = 0
  End
EndIf

StickyWindow(0, 1)

LoadFont(0, "Tahoma", 8)
SetGadgetFont(#PB_Default, FontID(0))
LoadFont(1, "Tahoma", 8, #PB_Font_Bold)

TextGadget(0, 0, 0, 150, 16, " Format de l'image :") : SetGadgetFont(0, FontID(1))
ComboBoxGadget(1, 0, 16, 150, 24)
AddGadgetItem(1, 0, "Bmp")
AddGadgetItem(1, 1, "Png")
AddGadgetItem(1, 2, "Jpg")
TextGadget(2, 150, 0, 150, 16, " Qualité de l'image :") : SetGadgetFont(2, FontID(1))
ComboBoxGadget(3, 150, 16, 150, 24)
For n = 1 To 10
  AddGadgetItem(3, n - 1, Str(n))
Next

OpenPreferences("Copie d'écran.ini")
Format = ReadPreferenceLong("Format", 1)
Qualite = ReadPreferenceLong("Qualité", 10)
Type = ReadPreferenceLong("Type", 0)
ClosePreferences()

SetGadgetState(1, Format)
SetGadgetState(3, Qualite - 1)

AffichageQualite()

TextGadget(7, 0, 50, 300, 16, " Type de copie d'écran :") : SetGadgetFont(7, FontID(1))
OptionGadget(10, 0, 66, 300, 16, "Tout l'écran")
OptionGadget(11, 0, 82, 300, 16, "L'écran sans la barre des taches")
OptionGadget(12, 0, 98, 300, 16, "La fenêtre sous la souris")
OptionGadget(13, 0, 114, 320, 16, "Uniquement le contenu de la fenêtre sous la souris")
OptionGadget(14, 0, 130, 300, 16, "Uniquement l'objet sous la souris")
SetGadgetState(10 + Type, 1)

TextGadget(4, 0, 156, 50, 16, " Image :") : SetGadgetFont(4, FontID(1))
TextGadget(5, 50, 156, 250, 16, "")

ButtonGadget(6, 0, 172, 276, 24, "Ouvrir le dossier contenant les copies d'écran")
ButtonGadget(8, 275, 172, 24, 24, "?")

TextGadget(9, 0, 200, 326, 16, "Pour capturer : APPUYER SUR PRINTSCR au clavier")

Icone = CreateImage(#PB_Any, 16, 16, 32)
StartDrawing(ImageOutput(Icone))
   DrawingMode(#PB_2DDrawing_AlphaChannel)
   Box(0, 0, 16, 16, 0)
   DrawingMode(#PB_2DDrawing_AlphaBlend)
   Box(1, 1, 14, 14, RGBA(150, 200, 255, 100))
   Box(0, 0, 2, 2, $FF000000)
   Box(14, 0, 2, 2, $FF000000)
   Box(0, 14, 2, 2, $FF000000)
   Box(14, 14, 2, 2, $FF000000)
   DrawingMode(#PB_2DDrawing_AlphaBlend | #PB_2DDrawing_Outlined)
   Box(1, 1, 14, 14, $60000000)
StopDrawing()

If AddSysTrayIcon(0, WindowID(0), ImageID(Icone))
  SysTrayIconToolTip(0, "Copie d'écran")
Else
  End
EndIf

AddKeyboardHook()

Repeat
  Event = WaitWindowEvent(200)
  Select Event
    Case #PB_Event_Gadget
      Select EventGadget() ; Gadgets
        Case 1
          Format = GetGadgetState(1)
          AffichageQualite()
        Case 3
          Qualite = GetGadgetState(3) + 1
        Case 6
          RunProgram("Explorer.exe", GetPathPart(ProgramFilename()), "")
        Case 10
          If GetGadgetState(10) = 1
            Type = 0
          EndIf
        Case 11
          If GetGadgetState(11) = 1
            Type = 1
          EndIf
        Case 12
          If GetGadgetState(12) = 1
            Type = 2
          EndIf
        Case 13
          If GetGadgetState(13) = 1
            Type = 3
               EndIf
            Case 14
          If GetGadgetState(14) = 1
            Type = 4
               EndIf
        Case 8
          MessageRequester("Copie d'écran", "Auteur : BOUGUIN Régis (LSI Développements)" + Chr(10) + "Logiciel de programmation : PureBasic v4")
      EndSelect
    Case #PB_Event_SysTray
      Select EventType()
        Case #PB_EventType_LeftClick, #PB_EventType_RightClick
               Masquer = 1 - Masquer
          If Masquer
            HideWindow(0, 1)
          Else
                  ; ShowWindow_(WindowID(0), #SW_NORMAL)
                  SetWindowState(0, #PB_Window_Normal)
            HideWindow(0, 0)
          EndIf
      EndSelect
  EndSelect
   
  If IsIconic_(WindowID(0)) And Masquer = 0
    HideWindow(0, 1)
      Masquer = 1
  EndIf
 
Until Event = #PB_Event_CloseWindow

If CreatePreferences("Copie d'écran.ini")
  WritePreferenceLong("Format", Format)
  WritePreferenceLong("Qualité", Qualite)
  WritePreferenceLong("Type", Type)
  ClosePreferences()
EndIf

End
Mesa.
Avatar de l’utilisateur
venom
Messages : 3138
Inscription : jeu. 29/juil./2004 16:33
Localisation : Klyntar
Contact :

Re: Imprimer une fenêtre

Message par venom »

Ar-S a écrit :Pour info, sous Windows, Alt + printScreen ne copie que la fenêtre active :wink:
Excellent ça, je ne connaissais pas :P

Donc pour Dzoumaka c'est encore plus simple, il a qu'a simuler les touches Alt+PrintScreen et envoyé le tout en jpeg ou bmp :)







@++
Windows 10 x64, PureBasic 5.73 x86 & x64
GPU : radeon HD6370M, CPU : p6200 2.13Ghz
Avatar de l’utilisateur
Ar-S
Messages : 9540
Inscription : dim. 09/oct./2005 16:51
Contact :

Re: Imprimer une fenêtre

Message par Ar-S »

venom a écrit :
Ar-S a écrit : Excellent ça, je ne connaissais pas :P
Y'a tant de choses pratiques que les gens ne connaissent pas sous Windows, c'est bien dommage (pour eux).
Les raccourcis clavier: (Windows+L, Windows+R, Ctrl+Molette sur le bureau, Windows+Pause, Alt+tab et tant d'autres !)
Depuis vista/7 y'a même des petites nouveautés bien pratiques.
Secouer une fenêtre pour faire disparaitre ou réapparaitre les autres, coller une fenêtre à gauche de sont ecran et la fenêtre se redimensionne pour prendre la moitié gauche, pareil à droite, Ctrl+molette pour grossir/diminuer
venom a écrit : Donc pour Dzoumaka c'est encore plus simple, il a qu'a simuler les touches Alt+PrintScreen et envoyé le tout en jpeg ou bmp :)
@++
Oui mais en PB j'ai l'impression que la combinaison Alt+PrintScreen n'a aucun effet. Il faut surement passer par de l'API mais sur le principe oui ce serait le plus simple
~~~~Règles du forum ~~~~
⋅.˳˳.⋅ॱ˙˙ॱ⋅.˳Ar-S ˳.⋅ॱ˙˙ॱ⋅.˳˳.⋅
W11x64 PB 6.x
Section HORS SUJET : ICI
LDV MULTIMEDIA : Dépannage informatique & mes Logiciels PB
UPLOAD D'IMAGES : Uploader des images de vos logiciels
Anonyme 2
Messages : 183
Inscription : ven. 18/mars/2011 11:53

Re: Imprimer une fenêtre

Message par Anonyme 2 »

Merci de vos réponse!
J'approche du but.. :mrgreen:
Voici ce que j'ai extrait du code fournit par Mesa:

Code : Tout sélectionner

UsePNGImageEncoder()
Ecran_Largeur = GetSystemMetrics_(#SM_CXSCREEN)
Ecran_Hauteur = GetSystemMetrics_(#SM_CYSCREEN)
DC = GetDC_(0)
Image2 = CreateImage(#PB_Any, Ecran_Largeur, Ecran_Hauteur)
Dessin = StartDrawing(ImageOutput(Image2))
BitBlt_(Dessin, 0, 0, Ecran_Largeur, Ecran_Hauteur, DC, 0, 0, #SRCCOPY | $40000000)
StopDrawing()
ReleaseDC_(0, DC)
WinMouse = WindowFromPoint_(DesktopMouseX() | DesktopMouseY() << 32)
Repeat
  WinParent = GetParent_(WinMouse)
  If WinParent
    WinMouse = WinParent   
  EndIf
Until WinParent = 0
GetClientRect_(WinMouse, Fenetre.rect) : ClientToScreen_(WinMouse, FenetreHG.POINT)
Fenetre\left + FenetreHG\x
Fenetre\right + FenetreHG\x
Fenetre\top + FenetreHG\y
Fenetre\bottom + FenetreHG\y
GetWindowRect_(WinMouse, Fenetre.rect)
If Fenetre\left < 0 : Fenetre\left = 0 : EndIf
If Fenetre\top < 0 : Fenetre\top = 0 : EndIf
If Fenetre\right > ImageWidth(Image2) : Fenetre\right = ImageWidth(Image2) : EndIf
If Fenetre\bottom > ImageHeight(Image2) : Fenetre\bottom = ImageHeight(Image2) : EndIf
Image = GrabImage(Image2, #PB_Any, Fenetre\left, Fenetre\top, Fenetre\right - Fenetre\left, Fenetre\bottom - Fenetre\top)
SaveImage(Image, "C:\Users\Rome\Desktop\image.png", #PB_ImagePlugin_PNG)
Cela cree une premier screenhot de l'écran, puis celui-là est découpé en fonction de la fenêtre sous la souris..
Quelqun saurait cmt tout simplement faire un screenhot de la fenêtre active (en avant-plan) sans avoir a pointer la fenêtre désiré comme dans le code ci-dessus? (désolé de vous demander tant de choses mais coté API je suis un peu ignorant)
Merci! :|
brossden
Messages : 833
Inscription : lun. 26/janv./2004 14:37

Re: Imprimer une fenêtre

Message par brossden »

Il y a ce prog qui peux t'être utile pour imprimer un écran voir l'un des deux écrans si on en possède deux :

Code : Tout sélectionner

Enumeration
  #Window_0 : #ButtonImage_0 : #ButtonImage_1 : #Image0 : #image1 : #ImageB0
  #imageB1 : #Texte : #Libel
EndEnumeration

Global  Image0, Image1, Image2, DH0, DW0, DH1, DW1
 

ProcedureDLL.l RotateImageEx2(ImageID, Angle.f)
  Protected bmi.BITMAPINFO, bmi2.BITMAPINFO, Hdc.l, NewImageID, Mem, n, nn, bm.BITMAP
  Debug "Angle : "+Str(Angle)
  Angle*#PI/180
  Protected Cos.f = Cos(Angle)
  Protected Sin.f = Sin(Angle)
  Protected CouleurFond = 0
  GetObject_(ImageID, SizeOf(BITMAP), @bm.BITMAP)
  bmi\bmiHeader\biSize = SizeOf(BITMAPINFOHEADER)
  bmi\bmiHeader\biWidth = bm\bmWidth
  bmi\bmiHeader\biHeight = bm\bmHeight
  bmi\bmiHeader\biPlanes = 1
  bmi\bmiHeader\biBitCount = 32
  bmi\bmiHeader\biCompression = #BI_RGB
  bmi2\bmiHeader\biSize = SizeOf(BITMAPINFOHEADER)
  bmi2\bmiHeader\biWidth = bm\bmWidth * Abs(Cos) + bm\bmHeight * Abs(Sin)
  bmi2\bmiHeader\biHeight = bm\bmHeight * Abs(Cos) + bm\bmWidth * Abs(Sin)
  bmi2\bmiHeader\biPlanes = 1
  bmi2\bmiHeader\biBitCount = 32
  bmi2\bmiHeader\biCompression = #BI_RGB
  Mem = AllocateMemory(bm\bmWidth * bm\bmHeight * 4)
  If Mem
    Protected Mem2 = AllocateMemory(bmi2\bmiHeader\biWidth * bmi2\bmiHeader\biHeight * 4)
    If Mem2
      Hdc = CreateCompatibleDC_(GetDC_(ImageID))
      If Hdc
        GetDIBits_(Hdc, ImageID, 0, bm\bmHeight, Mem, @bmi, #DIB_RGB_COLORS)
        ReleaseDC_(0, Hdc)
      EndIf
      Protected CX1 = bm\bmWidth - 1
      Protected CY1 = bm\bmHeight - 1
      Protected CX2 = bmi2\bmiHeader\biWidth - 1
      Protected CY2 = bmi2\bmiHeader\biHeight - 1
      Protected Mem01 = Mem + bm\bmWidth * 4
      Protected Mem10 = Mem + 4
      Protected Mem11 = Mem01 + 4
      Protected Mem2Temp = Mem2
      Protected deb=-CX2/2
    Protected fin=deb+CX2;= Round(CX2/2,1) but <> (CX2*2-CX2)/2
      For nn = 0 To CY2
        Protected x1b.l
        Protected y1b.l = (nn * 2) - CY2
        Protected Temp1.f = (CX1 - (y1b * Sin))/2
        Protected Temp2.f = (CY1 + (y1b * Cos))/2
        Protected x1.f = Temp1 + (deb * Cos)
        Protected y1.f = Temp2 + (deb * Sin)
        For x1b = deb To fin
          Protected x2.l = x1
          Protected y2.l = y1
          If x1 < x2
            !DEC dword[p.v_x2]
          EndIf
          If y1 < y2
            !DEC dword[p.v_y2]
          EndIf
          Protected x2b.l = x2 + 1
          Protected y2b.l = y2 + 1
          ;test boundaries
          If x2b >= 0 And x2 <= CX1 And y2b >= 0 And y2 <= CY1
            Protected fx.f = x1 - x2
            Protected fy.f = y1 - y2
            Protected f00.f = 1 - fx
            Protected f10.f = 1 - fy
            Protected f01.f = f00 * fy
            f00 * f10
            f10 * fx
            Protected f11.f = fx * fy
            
            Protected MemTemp = (x2 + y2 * bm\bmWidth) * 4
            Protected c00.l, c01.l, c11.l, c10.l
            
            If x2 >= 0 And x2 <= CX1
              If y2 >= 0 And y2 <= CY1
                !MOV eax,dword[p.v_Mem]
                !ADD eax,dword[p.v_MemTemp]
                !MOV eax,dword[eax]
                !MOV dword[p.v_c00],eax
              Else
                c00 = 0
              EndIf
              If y2b >= 0 And y2b <= CY1
                !MOV eax,dword[p.v_Mem01]
                !ADD eax,dword[p.v_MemTemp]
                !MOV eax,dword[eax]
                !MOV dword[p.v_c01],eax
              Else
                c01 = 0
              EndIf
            Else
              c00 = 0
              c01 = 0
            EndIf
            If x2b >= 0 And x2b <= CX1
              If y2 >= 0 And y2 <= CY1
                !MOV eax,dword[p.v_Mem10]
                !ADD eax,dword[p.v_MemTemp]
                !MOV eax,dword[eax]
                !MOV dword[p.v_c10],eax
              Else
                c10 = 0
              EndIf
              If  y2b >= 0 And y2b <= CY1
                !MOV eax,dword[p.v_Mem11]
                !ADD eax,dword[p.v_MemTemp]
                !MOV eax,dword[eax]
                !MOV dword[p.v_c11],eax
              Else
                c11 = 0
              EndIf
            Else
              c10 = 0
              c11 = 0
            EndIf
            Protected r1.l,r2.l,r3.l,r4.l,g1.l,g2.l,g3.l,g4.l,b1.l,b2.l,b3.l,b4.l
            !MOV eax,dword[p.v_c00]
            !MOV ebx,eax
            !MOV ecx,eax
            !AND eax,$FF
            !MOV dword[p.v_r1],eax
            !AND ebx,$FF00
            !MOV dword[p.v_g1],ebx
            !AND ecx,$FF0000
            !MOV dword[p.v_b1],ecx
            !MOV eax,dword[p.v_c10]
            !MOV ebx,eax
            !MOV ecx,eax
            !AND eax,$FF
            !MOV dword[p.v_r2],eax
            !AND ebx,$FF00
            !MOV dword[p.v_g2],ebx
            !AND ecx,$FF0000
            !MOV dword[p.v_b2],ecx
            !MOV eax,dword[p.v_c01]
            !MOV ebx,eax
            !MOV ecx,eax
            !AND eax,$FF
            !MOV dword[p.v_r3],eax
            !AND ebx,$FF00
            !MOV dword[p.v_g3],ebx
            !AND ecx,$FF0000
            !MOV dword[p.v_b3],ecx
            !MOV eax,dword[p.v_c11]
            !MOV ebx,eax
            !MOV ecx,eax
            !AND eax,$FF
            !MOV dword[p.v_r4],eax
            !AND ebx,$FF00
            !MOV dword[p.v_g4],ebx
            !AND ecx,$FF0000
            !MOV dword[p.v_b4],ecx
            
            Protected r.l = r1 * f00 + r2 * f10 + r3 * f01 + r4 * f11
            Protected g.l = g1 * f00 + g2 * f10 + g3 * f01 + g4 * f11
            Protected b.l = b1 * f00 + b2 * f10 + b3 * f01 + b4 * f11
            
            !MOV eax,dword[p.v_r]
            !MOV ebx,dword[p.v_g]
            !MOV ecx,dword[p.v_b]
            !AND eax,$FF
            !AND ebx,$FF00
            !AND ecx,$FF0000
            !OR eax,ebx
            !OR eax,ecx
            
            !MOV ebx,dword[p.v_Mem2Temp]
            !MOV dword[ebx],eax
            
          Else
            
            !MOV ebx,dword[p.v_Mem2Temp]
            !XOR eax,eax
            !MOV dword[ebx],eax
            
          EndIf
          
          Mem2Temp + 4
          x1 + Cos
          y1 + Sin
          
        Next
      Next
      
      ; On crée la nouvelle image
      NewImageID = CreateImage(#PB_Any, bmi2\bmiHeader\biWidth, bmi2\bmiHeader\biHeight)
      Hdc = CreateCompatibleDC_(GetDC_(ImageID(NewImageID)))
      If Hdc
        SetDIBits_(Hdc, ImageID(NewImageID), 0, bmi2\bmiHeader\biHeight, Mem2, @bmi2, #DIB_RGB_COLORS) ; on envoie la liste dans l'image
        ReleaseDC_(0, Hdc)
      EndIf
      
      FreeMemory(Mem2)
    EndIf
    FreeMemory(Mem)
  EndIf
  
  ProcedureReturn NewImageID
EndProcedure

Procedure Max(X,Y)
  If X>Y
    ProcedureReturn X
  Else
    ProcedureReturn Y
  EndIf
  
EndProcedure

Procedure CopyImageToMemory(ImageNumber, Memory)
  Protected TemporaryDC, TemporaryBitmap.BITMAP, TemporaryBitmapInfo.BITMAPINFO
  TemporaryDC = CreateDC_("DISPLAY", #Null, #Null, #Null)
  GetObject_(ImageID(ImageNumber), SizeOf(BITMAP), TemporaryBitmap.BITMAP)
  TemporaryBitmapInfo\bmiHeader\biSize        = SizeOf(BITMAPINFOHEADER)
  TemporaryBitmapInfo\bmiHeader\biWidth       = TemporaryBitmap\bmWidth
  TemporaryBitmapInfo\bmiHeader\biHeight      = -TemporaryBitmap\bmHeight
  TemporaryBitmapInfo\bmiHeader\biPlanes      = 1
  TemporaryBitmapInfo\bmiHeader\biBitCount    = 32
  TemporaryBitmapInfo\bmiHeader\biCompression = #BI_RGB
  GetDIBits_(TemporaryDC, ImageID(ImageNumber), 0, TemporaryBitmap\bmHeight, Memory, TemporaryBitmapInfo, #DIB_RGB_COLORS)
  
  DeleteDC_(TemporaryDC)
  
EndProcedure

Procedure Open_Window_0()
  
  If OpenWindow(#Window_0, 289, 53, (DW0+DW1)/8+20, Max(DH1,DH0)/8+60, "Impression d'écran",  #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar | #PB_Window_ScreenCentered | #PB_Window_WindowCentered )
    If CreateGadgetList(WindowID(#Window_0))
      ButtonImageGadget(#ButtonImage_0, 10, 10, DW0/8, DH0/8, ImageID(#ImageB0))
      TextGadget(#Libel,20,Max(DH1,DH0)/8+32,70,20,"Titre Page :")
      StringGadget(#Texte,80,Max(DH1,DH0)/8+30,150,20,"Copie d'écran")
      If DW1<>0
        ButtonImageGadget(#ButtonImage_1, 10+DW0/8, 10, DW1/8, DH1/8, ImageID(#imageB1))
      EndIf
    EndIf
  EndIf
EndProcedure
  
Procedure ImprimeImage(ImageX)
  X = RotateImageEx2(ImageID(ImageX),90)
  If PrintRequester()
    If StartPrinting(GetGadgetText(#Texte))
      LoadFont(1, "Arial", 100)
      If StartDrawing(PrinterOutput())
          DrawingFont(FontID(1))
          
          Lg = PrinterPageHeight()-200
          LgP = Lg/ImageHeight(X)*ImageWidth(X)
          XL = (PrinterPageWidth()-LgP) /2
          DrawText(Lg/2 - 500 , 100, GetGadgetText(#Texte))
          DrawImage(ImageID(X), XL, 100, LgP, Lg)
        StopDrawing()
      EndIf
      StopPrinting()
    EndIf
  EndIf
  End
EndProcedure


ExamineDesktops()
DH0 = DesktopHeight(0)
DW0 = DesktopWidth(0)
DH1 = DesktopHeight(1)
DW1 = DesktopWidth(1)

CreateImage(#Image0,DW0,DH0)
DC0 = StartDrawing(ImageOutput(#Image0))
  BitBlt_(DC0,0,0,DW0,DH0,GetDC_(GetDesktopWindow_()),0,0,#SRCCOPY )
StopDrawing()
CreateImage(#image1,DW1,DH1)
DC1 = StartDrawing(ImageOutput(#image1))
  BitBlt_(DC1,0,0,DW1,DH1,GetDC_(GetDesktopWindow_()),DW0,0,#SRCCOPY )
StopDrawing()
CopyImage(#Image0,#ImageB0)
CopyImage(#image1,#imageB1)
ResizeImage(#ImageB0,DW0/8,DH0/8)
ResizeImage(#imageB1,DW1/8,DH1/8)
*Mem = AllocateMemory(500000)
CopyImageToMemory(#imageB1,*Mem)
z=0
For n = 100 To 100000 Step 10
  z + PeekC(*Mem+n)
Next
Debug z
If z=0
  CreateImage(#image1,DW1,DH1)
  DC1 = StartDrawing(ImageOutput(#image1))
    BitBlt_(DC1,0,0,DW1,DH1,GetDC_(GetDesktopWindow_()),-DW1,0,#SRCCOPY )
  StopDrawing()
  CopyImage(#image1,#imageB1)
  ResizeImage(#imageB1,DW1/8,DH1/8)
  
EndIf
CloseFile(1)
Open_Window_0()
Repeat ; Start of the event loop
  
  Event = WaitWindowEvent()
  GadgetID = EventGadget()
  If Event = #PB_Event_Gadget
    
    If GadgetID = #ButtonImage_0
      ImprimeImage(#Image0)
    ElseIf GadgetID = #ButtonImage_1
      ImprimeImage(#image1)
    EndIf
  EndIf
Until Event = #PB_Event_CloseWindow ; End of the event loop
End
Denis

Bonne Jounée à tous
Anonyme 2
Messages : 183
Inscription : ven. 18/mars/2011 11:53

Re: Imprimer une fenêtre

Message par Anonyme 2 »

Merci pour ta réponse qui m'est très utile!
Mais ne saurais-tu pas comment ne prendre que l'interieur de la fenêtre donc sans ses bords (en le coupant peut-être, mais comment le couper? :/)
nico
Messages : 3702
Inscription : ven. 13/févr./2004 0:57

Re: Imprimer une fenêtre

Message par nico »

Mais tu veux faire quoi exactement?
une capture d'une fenêtre de ton programme où celui d'une fenêtre externe à ton programme?
Anonyme 2
Messages : 183
Inscription : ven. 18/mars/2011 11:53

Re: Imprimer une fenêtre

Message par Anonyme 2 »

Capturer tout ce qui se trouve à l'interieur du programme: donc la fenêtre sans ses bords :roll:
Avatar de l’utilisateur
Ar-S
Messages : 9540
Inscription : dim. 09/oct./2005 16:51
Contact :

Re: Imprimer une fenêtre

Message par Ar-S »

Pourquoi ne crées tu pas une fenêtre sans bord :?:
Z'aimez bien vous compliquer la vie hein. ;)
~~~~Règles du forum ~~~~
⋅.˳˳.⋅ॱ˙˙ॱ⋅.˳Ar-S ˳.⋅ॱ˙˙ॱ⋅.˳˳.⋅
W11x64 PB 6.x
Section HORS SUJET : ICI
LDV MULTIMEDIA : Dépannage informatique & mes Logiciels PB
UPLOAD D'IMAGES : Uploader des images de vos logiciels
Anonyme 2
Messages : 183
Inscription : ven. 18/mars/2011 11:53

Re: Imprimer une fenêtre

Message par Anonyme 2 »

Effectivement, c'est une solution! Bien que... :roll:
Merci de vos réponse :mrgreen:
nico
Messages : 3702
Inscription : ven. 13/févr./2004 0:57

Re: Imprimer une fenêtre

Message par nico »

C'est très simple, il y a une API pour ça!

Je te poste un code ce soir.
Répondre