Accueil > > > IMPRIMER UN DOCUMENT [DEV C++]
IMPRIMER UN DOCUMENT [DEV C++]
Information sur la source
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
Sources de la même categorie
Commentaires et avis
|
Derniers Blogs
TECHDAYS PARIS 2012 : SESSION PLEINIèRE JOUR 3TECHDAYS PARIS 2012 : SESSION PLEINIèRE JOUR 3 par ROMELARD Fabrice
Speaker: Bernard Ourghanlian Cette session est comme chaque jour transmise en live par BrainSonic, et j'ai donc suivi cette troisième pleinière par ce moyen sur mon iPad . Elle est dédiée comme chaque année à la mise en perspective de l'é...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice MISHRA READER : UN LECTEUR RSS TRèS ZUNE STYLE EN OPEN SOURCE !MISHRA READER : UN LECTEUR RSS TRèS ZUNE STYLE EN OPEN SOURCE ! par Vko
Hier durant une session dédiée aux Techdays 2012, j'ai eu le plaisir d'annoncer la sortie de la Béta 2 de Mishra Reader. C'est quoi ? Pour les utilisateurs, c'est une vraie expérience de lecture de flux RSS sur Windows. Rien à voir avec les produit...
Cliquez pour lire la suite de l'article par Vko [FRAMEWORK 4] LES TASKS ET LE THREAD UI[FRAMEWORK 4] LES TASKS ET LE THREAD UI par fathi
Je viens de passer quelques temps au TechDay's et j'ai pu voir pas mal de session intéressante. Par contre une chose m'a un peu étonné lors de certaines de ces sessions qui abordaient les améliorations du framework .NET (donc le 4.5) : en gros, bea...
Cliquez pour lire la suite de l'article par fathi WORKFLOW FOUNDATION 3 A UN PIED DANS LA TOMBEWORKFLOW FOUNDATION 3 A UN PIED DANS LA TOMBE par JeremyJeanson
Depuis déjà un an, je conseille vivement les utilisateurs de Workflow Foundation 3 à migrer vers la version 4. L'information qui va suivre ne devrait donc pas trop prendre au dépourvu les personnes qui m'ont suivi. Je profite de ce poste, pour faire le re...
Cliquez pour lire la suite de l'article par JeremyJeanson TECHDAYS PARIS 2012 : NOUVELLES TENDANCES DU POSTE DE TRAVAIL - BRING YOUR OWN PCTECHDAYS PARIS 2012 : NOUVELLES TENDANCES DU POSTE DE TRAVAIL - BRING YOUR OWN PC par ROMELARD Fabrice
Speakers: Thierry Rapatout, Antoine Petit et Xavier Trebbia Cette session entre dans le cadre des RDV Décideurs des TechDays 2012, elle est liée à la consumérisation de l'IT et la mise en place du "DeskTop as a Service" dans de plus en ...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice
Logiciels
Academy System (17.2.1.0)ACADEMY SYSTEM (17.2.1.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System Easy-Planning (1.0.0.1)EASY-PLANNING (1.0.0.1)Basé sur les mêmes principes que MyPlanning, Easy-Planning permet de créer des plannings sous la ... Cliquez pour télécharger Easy-Planning COLLECTOR PLUS (3.00B)COLLECTOR PLUS (3.00B)COLLECTOR PLUS version 3.00B est un logiciel utilisant une base de données alimentée par :
- L... Cliquez pour télécharger COLLECTOR PLUS PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V7.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V7.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO LettresFaciles 2011 (8.0.0.1)LETTRESFACILES 2011 (8.0.0.1)LettresFaciles est un logiciel facilitant la création et la rédaction de lettres types.
Son inte... Cliquez pour télécharger LettresFaciles 2011
|