Newsgroup: it.comp.programmare.win32
Titolo: automazione stampa

Ciao a tutti, ho la necessità di effettuare un certo numero di stampe
di una pagina contenuta in un webbrowser.
Prendendo degli spunti in rete, lancio il processo di stampa
(rundll32,mshtml.dll,PrintHTML), con la comparsa della finestrella di
stampa(identica a quella di IE) setto il numero di pagine e clicco sul
pulsante di stampa tutto tramite api.
Capita a volte che il numero di pagine stampate sia il doppio di
quanto voluto, da cosa può dipendere?Non mi è chiara la funzione del
GlobalLock e se posso toglierlo...
posto parte del codice usato
GlobalLock(hwnd)
Thread.Sleep(1000)
i1 = FindWindowsFormsControlRecursive(hwnd)
i2 = GetDlgItem(Form4.window, CLng(1153)) 'trovo hwnd della
finestra(numero di copie)
SendSetText(i2, CLng(WM_SETTEXT), CLng(0), Text) 'setto il numero di
copie volute
iii = FindWindowEx(hwnd, CType(0, IntPtr), "Button", "&Stampa") 'trovo
hwnd del pulsante stampa
SendMessage(iii, BM_CLICK, 0, 0) 'clicco il pulsante stampa
GlobalUnlock(hwnd)
Grazie per le eventuali risposte.

 GlobalLock e se posso toglierlo...
mi fai ricordare i tempi dei 16 bit :)
GlobalLock è per la memoria e non per gli handle... non vedo buoni motivi 
per usarlo
Visto che per avere quel codice, hai già del codice che gira sul lato 
browser, considera seriamente FlowDocument per creare il documento 
(eventualmente convertendolo da HTML) e XPS per stamparlo. Oltre ad essere 
enormemente più maneggevole del webbrowser, avrai anche risultati 
qualitativamente molto migliori.
-- 
Raffaele Rialdi
Microsoft .NET MVP 
http://mvp.support.microsoft.com
 -
http://italy.mvps.org
 UGIdotNET - User Group Italiano .NET
http://www.ugidotnet.org
 Weblog: 
http://blogs.ugidotnet.org/raffaele
 

 qualitativamente molto migliori.
In effetti uso un webbrowser caricando un modello e in base ai valori
che mi occorrono faccio una sostituzione al volo di alcune parti del
testo. Avresti qualche riferimento per prendere confidenza al volo con
FlowDocument/xps? ho provato a fare una ricerca al volo ma ho li idee
un pò confuse.
Grazie

 un pò confuse.
Entrambi fanno parte di WPF, cioè presenti nel framework 3.0 in poi
- FlowDocument è l'analogo di un file html, cioè una pagina di lunghezza 
virtuale infinita e privo di paginazione. Lo costruisci con un object model 
molto ricco e ben strutturato oppure con una RichTextBox di WPF che può 
leggere RTF o FlowDocument e scrivere FlowDocument. Il FlowDocument è 
serializzato secondo lo schema XAML, quindi un formato XML che è scrivibile 
anche solo concatenando testo.... ovviamente l'object model è molto più 
comodo.
Altre classi del Fx 3.x ti permettono di impaginare il FlowDocument, 
seguendo persino le regole d'oro di Knuth per una buona resa visiva e 
ottenere un XPS.
Per miei scopi ho creato una conversione FlowDocument to XHtml che è molto 
più sofisticata (css e altre cose) rispetto all'esempio dell'sdk (che pure 
il suo _piccolo_ lavoro lo fa).
- xps è l'analogo del pdf, quindi assolutamente fedele a quello che verrà 
stampato, firmabile con un certificato digitale.
Il suo formato file è uno zip organizzato secondo le specifiche OPC (che non 
devi conoscere perché il framework ha le classi per usarle). I file interni 
allo zip sono tutti xml (ma a scriverli ci pensa il framework, quindi di 
solito non devi metterci mano).
Io ci ho lavorato parecchio sopra e ho anche creato una conversione XPS to 
PDFcon l'ausilio di una libreria per scrivere PDF.
Se ti installi il Windows SDK (che contiene il Framework 3.x sdk) troverai 
dentro tools ed esempi di WPF che contengono nella sottocartella Documents 
tantissimi esempi sia su FlowDocument che XPS.
Documentazione la trovi ovviamente sul sito msdn2.
Se serve altro, fai un fischio sui ng (magari su quello del framework della 
gerarchia MS, visto che questo è specifico win32).


The regular earnings of the girls go to the same
    quarters, and the unfortunate creatures obviously form subjects
    of speculation to regular traders in this kind of business, who
    reside beyond our jurisdiction. In most of the regular houses, the
    inmates are more or less in debt to the keepers, and though such
    debts are not legally enforceable, a custom stronger than law
    forbids the woman to leave the brothel until her debts are
    liquidated, and it is only in rare cases that she does so." "As to
    the brothel-keepers, there is nothing known against them, and they
    are supported by capitalists. Mr. Lister speaks of them as 'a
    horrible race of cruel women, cruel to the last degree, who use an
    ingenious form of torture, which they call prevention of sleep,'
    which he describes in detail.... It seems that although the
    Brothel Ordinances did not call into being this 'horrible,'
    'cruel,' and 'haughty' race of women, they have armed them with
    obvious powers, which they would not otherwise have possessed,
    and there is consequently reason to apprehend that Government
    supervision accentuates in some respects rather than relieves the
    hardships of the servitude of the i

at Hong Kong the story of the
following seems typical of her class, so we extract it from our
journal:
    "At the first place we called there were six inmates--four of whom
    were present at the interview. The keeper went out of the room as
    we entered, and did not return. The girls were very friendly, and
    one of them talked a little English. This one told us that she
    came from Canton, and, in broken English, said that she had 'no
    father, no mother, no brother; a poor man took her when a _very_
    little child and raised her to sell. By and by a woman came and
    offered to buy poor man's little girl, and as he had but little
    food, he asks, 'How much?' then she buys the little girl and
    brings her to Hong Kong. Then woman take her to Englishman and
    say, 'She first-class girl,' and he say, 'I make her my wife,' but
    he not good; he no husband; he go away to his house--England.'
    Thus she described in a few simple words the tragedy of her life
    with tears in her eyes; her training for vice; her sale; her hopes
    of marriage; her desertion; the outcome, her consignment to a
    Government-licensed brothel. She was but one of the tens of
    thousands at Hong Kong. We asked, 'How would a girl have to do in
    order to live in this house?' They said, 'She must be registered
    at the Lock. Hospital, and would have to go to the Court and Mr.
    Lockhart (the Registrar-General) would ask her questions; whether
    she had a father and mother; how old she was; _where the money
    went to that was paid for her_; and whether she wanted to be a
    prostitute or not.' We asked, 'If a girl should say that she _did
    not_ want to be a prostitute what would be done?' They answered,
    'No girl would _dare_ to say this _when she had been bought_.' We

where
these Acts originated, nominated an extra-Parliamentary Commission to
go thoroughly into these questions. This Commission held its numerous
sittings in 1905, and in the end by almost a two-thirds' majority
condemned the existing system of regulation in France, and furthermore
rejected the alternative proposal of notification with compulsory
treatment, by sixteen votes to one. In reporting on the Conferences
held in Brussels, the _Independence Belge_ said, in a leading article:
"Regulation is visibly decaying, and the fact is the more striking
because the country that instituted it (France) is at present the one
that meets it with the most ardent hostility."
CHAPTER 4.
MORE POWER DEMANDED AND OBTAINED.
In 1866 the Governor of Hong Kong, Sir Richard Graves MacDonnell,
determined upon the repeal of Ordinance 12, 1857, in order to
inaugurate "a more vigorous policy of coercion," (says the
Commission's report): "The key note of the new regime was struck by
the Governor's first minute on the subject, dated 20th October, 1866,
in which he wrote he was 'anxious early to introduce to the Council an
amended Brothel Ordinance, conferring _necessarily_ almost despotic
powers on the Registrar General." ... Be it said to the honor of
Attorney General (now Sir Julian) Pauncefote, that in the face of this
he urges the most weighty objections to the policy of "subjecting
persons to fine and imprisonment without the safeguards which surround
the administration of justice in a public and open court." But these
objections were not allowed to prevail.
It appears that some hesitation was felt on the part of the home
authorities in giving approval to the new ordinance. It may have been
the warning given by Attorney General Pauncefote, it may have been
something else. Whatever it was, the Commission informs us: "The
Ordinance 10 of 1867 received its final sanction when the conclusion
arrived at by the Colonial Government was before the home authorities,
sh