begin process at 2012 02 09 21:48:32
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

API

 > IMPRIMER UN DOCUMENT [DEV C++]

IMPRIMER UN DOCUMENT [DEV C++]


 Information sur la source

Note :
7 / 10 - par 2 personnes
7,00 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10
Catégorie :API Niveau :Expert Date de création :13/01/2002 Date de mise à jour :13/01/2002 16:12:26 Vu :9 511

Auteur : mmuller57

Ecrire un message privé
Site perso
Commentaire sur cette source (4)
Ajouter un commentaire et/ou une note

 Description

Ce code vient du hors-série de PC TEAM n°9.

Source

  • #include <windows.h>
  • extern HINSTANCE hInst ;
  • extern TCHAR szAppName[] ;
  • extern TCHAR szCaption[] ;
  • void CreerFormesGeometriques (HDC hdcPrn, int cxPage, int cyPage)
  • {
  • static TCHAR szTextStr[] = TEXT ("Ce code vient du hors-série de PC TEAM n°9") ;
  • SaveDC (hdcPrn) ;
  • SetMapMode (hdcPrn, MM_ISOTROPIC) ;
  • SetWindowExtEx (hdcPrn, 1000, 1000, NULL) ;
  • SetViewportExtEx (hdcPrn, cxPage / 2, -cyPage / 2, NULL) ;
  • SetViewportOrgEx (hdcPrn, cxPage / 2, cyPage / 2, NULL) ;
  • Ellipse (hdcPrn, -500, 500, 500, -500) ;
  • SetTextAlign (hdcPrn, TA_BASELINE | TA_CENTER) ;
  • TextOut (hdcPrn, 0, 0, szTextStr, lstrlen (szTextStr)) ;
  • RestoreDC (hdcPrn, -1) ;
  • }
  • HDC GetPrinterDC (void)
  • {
  • DWORD dwNeeded, dwReturned ;
  • HDC hdc ;
  • PRINTER_INFO_4 * pinfo4 ;
  • PRINTER_INFO_5 * pinfo5 ;
  • //sous Windows 98
  • if (GetVersion () & 0x80000000)
  • {
  • EnumPrinters (PRINTER_ENUM_DEFAULT, NULL, 5, NULL,
  • 0, &dwNeeded, &dwReturned) ;
  • pinfo5 = (PRINTER_INFO_5 *)malloc (dwNeeded) ;
  • EnumPrinters (PRINTER_ENUM_DEFAULT, NULL, 5, (PBYTE) pinfo5,
  • dwNeeded, &dwNeeded, &dwReturned) ;
  • hdc = CreateDC (NULL, pinfo5->pPrinterName, NULL, NULL) ;
  • free (pinfo5) ;
  • }
  • //sous un win NT
  • else
  • {
  • EnumPrinters (PRINTER_ENUM_LOCAL, NULL, 4, NULL,
  • 0, &dwNeeded, &dwReturned) ;
  • pinfo4 = (PRINTER_INFO_4 *)malloc (dwNeeded) ;
  • EnumPrinters (PRINTER_ENUM_LOCAL, NULL, 4, (PBYTE) pinfo4,
  • dwNeeded, &dwNeeded, &dwReturned) ;
  • hdc = CreateDC (NULL, pinfo4->pPrinterName, NULL, NULL) ;
  • free (pinfo4) ;
  • }
  • return hdc ;
  • }
  • HINSTANCE hInst ;
  • TCHAR szAppName[] = TEXT ("Print1") ;
  • TCHAR szCaption[] = TEXT ("Programme Print 1") ;
  • BOOL imprimer (HWND hwnd)
  • {
  • static DOCINFO di = { sizeof (DOCINFO), TEXT ("Print1 : impression en cours") } ;
  • BOOL bSuccess = TRUE ;
  • HDC hdcPrn ;
  • int xPage, yPage ;
  • if (NULL == (hdcPrn = GetPrinterDC ()))
  • return FALSE ;
  • xPage = GetDeviceCaps (hdcPrn, HORZRES) ;
  • yPage = GetDeviceCaps (hdcPrn, VERTRES) ;
  • if (StartDoc (hdcPrn, &di) > 0)
  • {
  • if (StartPage (hdcPrn) > 0)
  • {
  • CreerFormesGeometriques (hdcPrn, xPage, yPage) ;
  • if (EndPage (hdcPrn) > 0)
  • EndDoc (hdcPrn) ;
  • else
  • bSuccess = FALSE ;
  • }
  • }
  • else
  • bSuccess = FALSE ;
  • DeleteDC (hdcPrn) ;
  • return bSuccess ;
  • }
  • LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
  • int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
  • PSTR szCmdLine, int iCmdShow)
  • {
  • HWND hwnd ;
  • MSG msg ;
  • WNDCLASS wndclass ;
  • wndclass.style = CS_HREDRAW | CS_VREDRAW ;
  • wndclass.lpfnWndProc = WndProc ;
  • wndclass.cbClsExtra = 0 ;
  • wndclass.cbWndExtra = 0 ;
  • wndclass.hInstance = hInstance ;
  • wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
  • wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
  • wndclass.hbrBackground = (HBRUSH) GetStockObject (GRAY_BRUSH) ;
  • wndclass.lpszMenuName = NULL ;
  • wndclass.lpszClassName = szAppName ;
  • if (!RegisterClass (&wndclass))
  • {
  • MessageBox (NULL, TEXT ("Ce programme fonctionne exclusivement sous Windows NT!"),
  • szAppName, MB_ICONERROR) ;
  • return 0 ;
  • }
  • hInst = hInstance ;
  • hwnd = CreateWindow (szAppName, szCaption,
  • WS_OVERLAPPEDWINDOW,
  • CW_USEDEFAULT, CW_USEDEFAULT,
  • CW_USEDEFAULT, CW_USEDEFAULT,
  • NULL, NULL, hInstance, NULL) ;
  • ShowWindow (hwnd, iCmdShow) ;
  • UpdateWindow (hwnd) ;
  • while (GetMessage (&msg, NULL, 0, 0))
  • {
  • TranslateMessage (&msg) ;
  • DispatchMessage (&msg) ;
  • }
  • return msg.wParam ;
  • }
  • LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  • {
  • static int cxClient, cyClient ;
  • HDC hdc ;
  • HMENU hMenu ;
  • PAINTSTRUCT ps ;
  • switch (message)
  • {
  • case WM_CREATE:
  • hMenu = GetSystemMenu (hwnd, FALSE) ;
  • AppendMenu (hMenu, MF_SEPARATOR, 0, NULL) ;
  • AppendMenu (hMenu, 0, 1, TEXT ("Im&primer")) ;
  • return 0 ;
  • case WM_SIZE:
  • cxClient = LOWORD (lParam) ;
  • cyClient = HIWORD (lParam) ;
  • return 0 ;
  • case WM_SYSCOMMAND:
  • if (wParam == 1)
  • {
  • if (!imprimer (hwnd))
  • MessageBox (hwnd, TEXT ("Impression de la page impossible !"),
  • szAppName, MB_OK | MB_ICONEXCLAMATION) ;
  • return 0 ;
  • }
  • break ;
  • case WM_PAINT :
  • hdc = BeginPaint (hwnd, &ps) ;
  • CreerFormesGeometriques (hdc, cxClient, cyClient) ;
  • EndPaint (hwnd, &ps) ;
  • return 0 ;
  • case WM_DESTROY :
  • PostQuitMessage (0) ;
  • return 0 ;
  • }
  • return DefWindowProc (hwnd, message, wParam, lParam) ;
  • }
#include <windows.h>

extern HINSTANCE hInst ;
extern TCHAR szAppName[] ;
extern TCHAR szCaption[] ;

void CreerFormesGeometriques (HDC hdcPrn, int cxPage, int cyPage)
{
	
	static TCHAR szTextStr[] = TEXT ("Ce code vient du hors-série de PC TEAM n°9") ;
     
     
     SaveDC (hdcPrn) ;
     
     SetMapMode       (hdcPrn, MM_ISOTROPIC) ;
     SetWindowExtEx   (hdcPrn, 1000, 1000, NULL) ;
     SetViewportExtEx (hdcPrn, cxPage / 2, -cyPage / 2, NULL) ;
     SetViewportOrgEx (hdcPrn, cxPage / 2,  cyPage / 2, NULL) ;
     
     Ellipse (hdcPrn, -500, 500, 500, -500) ;
     
     SetTextAlign (hdcPrn, TA_BASELINE | TA_CENTER) ;
     TextOut (hdcPrn, 0, 0, szTextStr, lstrlen (szTextStr)) ;
     RestoreDC (hdcPrn, -1) ;
}

HDC GetPrinterDC (void)
{
     DWORD            dwNeeded, dwReturned ;
     HDC              hdc ;
     PRINTER_INFO_4 * pinfo4 ;
     PRINTER_INFO_5 * pinfo5 ; 

	 //sous Windows 98
     if (GetVersion () & 0x80000000)  
     {
          EnumPrinters (PRINTER_ENUM_DEFAULT, NULL, 5, NULL,
                        0, &dwNeeded, &dwReturned) ;

          pinfo5 = (PRINTER_INFO_5 *)malloc (dwNeeded) ;

          EnumPrinters (PRINTER_ENUM_DEFAULT, NULL, 5, (PBYTE) pinfo5,
                        dwNeeded, &dwNeeded, &dwReturned) ;

          hdc = CreateDC (NULL, pinfo5->pPrinterName, NULL, NULL) ;

          free (pinfo5) ;
     }
	 //sous un win NT
     else 
     {
          EnumPrinters (PRINTER_ENUM_LOCAL, NULL, 4, NULL,
                        0, &dwNeeded, &dwReturned) ;

          pinfo4 = (PRINTER_INFO_4 *)malloc (dwNeeded) ;

          EnumPrinters (PRINTER_ENUM_LOCAL, NULL, 4, (PBYTE) pinfo4,
                        dwNeeded, &dwNeeded, &dwReturned) ;

          hdc = CreateDC (NULL, pinfo4->pPrinterName, NULL, NULL) ;

          free (pinfo4) ;
     }
     return hdc ;   
}





HINSTANCE hInst ;
TCHAR     szAppName[] = TEXT ("Print1") ;
TCHAR     szCaption[] = TEXT ("Programme Print 1") ;



BOOL imprimer (HWND hwnd)
{
     static DOCINFO di = { sizeof (DOCINFO), TEXT ("Print1 : impression en cours") } ;
     BOOL           bSuccess = TRUE ;
     HDC            hdcPrn ;
     int            xPage, yPage ;
     
     if (NULL == (hdcPrn = GetPrinterDC ()))
          return FALSE ;

     xPage = GetDeviceCaps (hdcPrn, HORZRES) ;
     yPage = GetDeviceCaps (hdcPrn, VERTRES) ;
     
     if (StartDoc (hdcPrn, &di) > 0)
     {
          if (StartPage (hdcPrn) > 0)
          {
               CreerFormesGeometriques (hdcPrn, xPage, yPage) ;
               
               if (EndPage (hdcPrn) > 0)
                    EndDoc (hdcPrn) ;
               else
                    bSuccess = FALSE ;
          }
     }
     else
          bSuccess = FALSE ;
     
     DeleteDC (hdcPrn) ;
     return bSuccess ;
}


LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                    PSTR szCmdLine, int iCmdShow)
{
     HWND     hwnd ;
     MSG      msg ;
     WNDCLASS wndclass ;
     
     wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
     wndclass.lpfnWndProc   = WndProc ;
     wndclass.cbClsExtra    = 0 ;
     wndclass.cbWndExtra    = 0 ;
     wndclass.hInstance     = hInstance ;
     wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION) ;
     wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
     wndclass.hbrBackground = (HBRUSH) GetStockObject (GRAY_BRUSH) ;
     wndclass.lpszMenuName  = NULL ;
     wndclass.lpszClassName = szAppName ;
     
     if (!RegisterClass (&wndclass))
     {
          MessageBox (NULL, TEXT ("Ce programme fonctionne exclusivement sous Windows NT!"),
                      szAppName, MB_ICONERROR) ;
          return 0 ;
     }
     
     hInst = hInstance ;
     
     hwnd = CreateWindow (szAppName, szCaption,
                          WS_OVERLAPPEDWINDOW,
                          CW_USEDEFAULT, CW_USEDEFAULT,
                          CW_USEDEFAULT, CW_USEDEFAULT,
                          NULL, NULL, hInstance, NULL) ;
     
     ShowWindow (hwnd, iCmdShow) ;
     UpdateWindow (hwnd) ;
     
     while (GetMessage (&msg, NULL, 0, 0))
     {
          TranslateMessage (&msg) ;
          DispatchMessage (&msg) ;
     }
     return msg.wParam ;
}


LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
     static int   cxClient, cyClient ;
     HDC          hdc ;
     HMENU        hMenu ;
     PAINTSTRUCT  ps ;
     
     switch (message)
     {
     case WM_CREATE:
          hMenu = GetSystemMenu (hwnd, FALSE) ;
          AppendMenu (hMenu, MF_SEPARATOR, 0, NULL) ;
          AppendMenu (hMenu, 0, 1, TEXT ("Im&primer")) ;
          return 0 ;
          
     case WM_SIZE:
          cxClient = LOWORD (lParam) ;
          cyClient = HIWORD (lParam) ;
          return 0 ;
          
     case WM_SYSCOMMAND:
          if (wParam == 1)
          {
               if (!imprimer (hwnd))
                    MessageBox (hwnd, TEXT ("Impression de la page impossible !"),
                                szAppName, MB_OK | MB_ICONEXCLAMATION) ;
               return 0 ;
          }
          break ;
          
     case WM_PAINT :
          hdc = BeginPaint (hwnd, &ps) ;
          
          CreerFormesGeometriques (hdc, cxClient, cyClient) ;
          
          EndPaint (hwnd, &ps) ;
          return 0 ;
          
     case WM_DESTROY :
          PostQuitMessage (0) ;
          return 0 ;
     }
     return DefWindowProc (hwnd, message, wParam, lParam) ;
} 

 Conclusion

Si quelqu'un a besoin de plus d'explications qu'il me contact via le service de messagerie du site !


 Sources du même auteur

Source avec Zip PROBABILITÉS ET PROGRAMMATION [ANSI-C++]
[TC++ 3.1] PROTÉGER L'ACCÈS DE VOTRE ORDINATEUR
[DEV C++] MODIFIER LE STYLE D'UNE FENÊTRE DÉJA AFFICHÉE
Source avec Zip Source avec une capture CRYPTAGE SIMPLE [DEV C++]
MANIPULATION DES FICHIERS EN ANSI-C++ [ANSI-C++]

 Sources de la même categorie

Source avec Zip WIN32 TLS LENT par dguilmain
Source avec Zip VIDER ELEMENTS DE CORBEILLE WINDOWS7 (WIN64) par BruNews
Source avec Zip Source avec une capture FIND TEXT (WIN64) par BruNews
Source avec Zip DELETE DIRECTORY (WIN64) par BruNews
Source avec Zip ENUM DIRECTORY (WIN64) par BruNews

Commentaires et avis

Commentaire de mmuller57 le 13/01/2002 17:58:35

Euh j'ai oublié de dire qu'il faut ajouter la librairie winspool  au options du compilateur ! 1000 excuses !

Commentaire de Fabrysse le 24/11/2003 22:16:37

Comprends pas...
Le compilateur (Dev C++) trouve 2 erreurs :
- ligne 41 : implicit declaration of function `int malloc(...)'
- ligne 48 : implicit declaration of function `int free(...)'
Quelqu'un sait pourquoi ?...
Merci.

Commentaire de jourgun le 08/02/2004 15:06:00

Et tu a aussi oublié de dire qu'il faut ajouter #include &lt;malloc.h&gt; au début de la source.

Commentaire de ndubien le 24/05/2009 10:14:59 10/10

Parfait ! C'est ce qu'il me fallait et ça marche !

 Ajouter un commentaire




Nos sponsors


Sondage...

CalendriCode

Février 2012
LMMJVSD
  12345
6789101112
13141516171819
20212223242526
272829    

Consulter la suite du CalendriCode

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,936 sec (4)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales