PureBasic

Forums PureBasic
Nous sommes le Jeu 20/Juin/2013 3:33

Heures au format UTC + 1 heure




Poster un nouveau sujet Répondre au sujet  [ 18 messages ]  Aller à la page Précédente  1, 2
Auteur Message
 Sujet du message: Re: Imprimer une fenêtre
MessagePosté: Mer 14/Mar/2012 18:18 
Hors ligne
Avatar de l’utilisateur

Inscription: Ven 13/Fév/2004 0:57
Messages: 3073
Voici un code simple qui fonctionne, que tu adapteras bien sûr, suivant tes besoins (Notamment pour adapter l'image par rapport au papier de sortie)



Code:
Procedure ImprimeFenetreClient(id_fenetre.l)
  Protected Hdc.i, id_image.l, id_library.l, Creation_image.l
 
  If GetClientRect_(WindowID(id_fenetre),@rect.rect)
    id_image= CreateImage(#PB_Any,rect\right,rect\bottom)
    If id_image<> 0
      hdc.i=StartDrawing(ImageOutput(id_image))
      If hdc
        id_library= OpenLibrary(#PB_Any,"User32.dll")
        If id_library<>0
          If CallFunction(id_library, "PrintWindow", WindowID(id_fenetre), Hdc, #PW_CLIENTONLY)
            Creation_image=1
          EndIf
          CloseLibrary(id_library)
        EndIf
      EndIf
      StopDrawing()
    EndIf
  EndIf
 
  If Creation_image
    If PrintRequester()   
      If StartPrinting("PureBasic Test")
        If StartDrawing(PrinterOutput())
          DrawImage(ImageID(id_image), 0, 0)
          StopDrawing()
        EndIf
        StopPrinting()
      EndIf
    EndIf
  EndIf
EndProcedure


#Fenetre=0
#Bouton=0

If OpenWindow(#Fenetre, 0, 0, 240, 240, "ButtonGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ButtonGadget(#Bouton, 10,  20, 220, 20, "Imprimer la Fenêtre sans les bords")
 
  Repeat
    event.l=WaitWindowEvent()
    Select event
      Case #PB_Event_Gadget
        Select EventGadget()
          Case #Bouton
            ImprimeFenetreClient(#Fenetre)
        EndSelect
    EndSelect
   
  Until event = #PB_Event_CloseWindow
EndIf


Haut
 Profil  
 
 Sujet du message: Re: Imprimer une fenêtre
MessagePosté: Jeu 15/Mar/2012 12:51 
Hors ligne
Avatar de l’utilisateur

Inscription: Lun 26/Jan/2004 14:37
Messages: 738
Peut être une solution à améliorer

Code:
Global x1, y1, x2,y2, Fenetre.s, Handle

Enumeration
  #Window_0 : #Listview_0 : #Image0
EndEnumeration

Procedure Open_Window_0()
  If OpenWindow(#Window_0, 216, 0, 452, 380, "New window ( 0 )",  #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar )
    If CreateGadgetList(WindowID(#Window_0))
      ListViewGadget(#Listview_0, 70, 40, 300, 180)
    EndIf
  EndIf
EndProcedure

Procedure Window()
  hWnd.l = FindWindow_( 0, 0 )
  While hWnd <> 0
    If GetWindowLong_(hWnd, #GWL_STYLE) & #WS_VISIBLE = #WS_VISIBLE
      txt.s = Space(256)
      GetWindowText_(hWnd, txt, 256)
      If txt <> ""
         AddGadgetItem(#Listview_0,-1,txt)
      EndIf
    EndIf
    hWnd = GetWindow_(hWnd, #GW_HWNDNEXT)
  Wend
EndProcedure

Procedure Taille(Fenetre.s)
  Handle = FindWindow_(0, Fenetre)
  GetWindowRect_(Handle, rc.Rect)
  GetClientRect_(Handle, sc.Rect)
      x1= rc\Left
      y1= rc\Top
      x2 = sc\Right+8
      y2 = (rc\Bottom + sc\Bottom )/2
EndProcedure

Procedure CopieImage()
  res =  SetForegroundWindow_(Handle)
  Delay(100)
  CreateImage(#Image0,x2,y2)
  DC0 = StartDrawing(ImageOutput(#Image0))
    BitBlt_(DC0,0,0,x2,y2,GetDC_(GetDesktopWindow_()),x1,y1,#SRCCOPY )
  StopDrawing()
  SaveImage(#Image0,"c:\aa.bmp")
EndProcedure

Procedure ImprimeImage(ImageX)
  If PrintRequester()
    If StartPrinting(Fenetre)
      If StartDrawing(PrinterOutput())
          DrawImage(ImageID(ImageX), 100, 100, x2*10, y2*10)
          StopDrawing()
      EndIf
      StopPrinting()
    EndIf
  EndIf
  End
EndProcedure

Open_Window_0()

Window()

Repeat
 
  Event = WaitWindowEvent()
  GadgetID = EventGadget()
  If Event = #PB_Event_Gadget
    If GadgetID = #Listview_0
      Fenetre.s = GetGadgetItemText(#Listview_0, GetGadgetState(#Listview_0))
      Taille(Fenetre)
      CopieImage()
      ImprimeImage(#Image0)
    EndIf
  EndIf
Until Event = #PB_Event_CloseWindow

End


_________________
Denis

Bonne Jounée à tous


Haut
 Profil  
 
 Sujet du message: Re: Imprimer une fenêtre
MessagePosté: Ven 16/Mar/2012 17:13 
Hors ligne

Inscription: Ven 18/Mar/2011 11:53
Messages: 175
Merci pour vos codes, problème résolus :)


Haut
 Profil  
 
Afficher les messages postés depuis:  Trier par  
Poster un nouveau sujet Répondre au sujet  [ 18 messages ]  Aller à la page Précédente  1, 2

Heures au format UTC + 1 heure


Qui est en ligne

Utilisateurs parcourant ce forum: Aucun utilisateur enregistré et 2 invités


Vous ne pouvez pas poster de nouveaux sujets
Vous ne pouvez pas répondre aux sujets
Vous ne pouvez pas éditer vos messages
Vous ne pouvez pas supprimer vos messages

Rechercher:
Aller à:  

 


Powered by phpBB © 2008 phpBB Group | Traduction par: phpBB-fr.com
subSilver+ theme by Canver Software, sponsor Sanal Modifiye