OVH Cloud OVH Cloud

Impression

4 réponses
Avatar
Rombeau Jonathan
Je cherche comment imprimer un fichier txt sans devoir l'ouvrir ou du moins
sans devoir lire et retenir cela dans mon application.

Quelqu'un sait-il comment faire pour simplement dire : imprime le fichier
test.txt ?

4 réponses

Avatar
christophe-pasde
Bonjour,
Tu copies ton fichier texte sous c:Monfichier.txt
Tu copies ceci dans une feuille avec un commandbutton.
Et tu clicks sur le bouton.
Normalement l'utilisateur lorsqu'il aura clicker sur le button verra
aparaitre quelque chose dont il sait se servir et imprimer son fichier.

Christophe

Private Type STARTUPINFO
cb As Long
lpReserved As String
lpDesktop As String
lpTitle As String
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Long
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type

Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessID As Long
dwThreadID As Long
End Type

Private Const NORMAL_PRIORITY_CLASS = &H20&
Private Const INFINITE = -1&

Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal _
hHandle As Long, ByVal dwmilliseconds As Long) As Long
Private Declare Function CreateProcessA Lib "kernel32" (ByVal _
lpApplicationName As String, ByVal lpCommandLine As String, ByVal _
lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, _
ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, _
ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As String, _
lpStartupInfo As STARTUPINFO, lpProcessInformation As _
PROCESS_INFORMATION) As Long

Private Declare Function CloseHandle Lib "kernel32" _
(ByVal hObject As Long) As Long

Private Declare Function GetExitCodeProcess Lib "kernel32" _
(ByVal hProcess As Long, lpExitCode As Long) As Long


Private Function ExecCmd(cmdline$)
Dim Ret&
Dim proc As PROCESS_INFORMATION
Dim start As STARTUPINFO

' Initialize the STARTUPINFO structure:
start.cb = Len(start)

' Start the shelled application:
Ret& = CreateProcessA(vbNullString, cmdline$, 0&, 0&, 1&, _
NORMAL_PRIORITY_CLASS, 0&, vbNullString, start, proc)

' Wait for the shelled application to finish:
Ret& = WaitForSingleObject(proc.hProcess, INFINITE)
Call GetExitCodeProcess(proc.hProcess, Ret&)
Call CloseHandle(proc.hThread)
Call CloseHandle(proc.hProcess)
ExecCmd = Ret&
End Function

Private Command1_click()
mCheminRes = "notepad.exe " & "C:Monfichier.txt"
retval = ExecCmd(mCheminRes)
end sub





Rombeau Jonathan a écrit :

Je cherche comment imprimer un fichier txt sans devoir l'ouvrir ou du moins
sans devoir lire et retenir cela dans mon application.

Quelqu'un sait-il comment faire pour simplement dire : imprime le fichier
test.txt ?




Avatar
Rombeau Jonathan
J'ai du apporter une petite modification mais cela fonctionne très bien
MERCI BEAUCOUP !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Au fait la modification apportée c'est le $ à cmdline$ qu'il faut retirer à
chaque fois càd 2 fois au total !!

Merci pour tout ...


"christophe-pasde<> @wanadoo.fr>" <"christophe-pasde<> a écrit dans le
message de news: 41814757$0$3591$
Bonjour,
Tu copies ton fichier texte sous c:Monfichier.txt
Tu copies ceci dans une feuille avec un commandbutton.
Et tu clicks sur le bouton.
Normalement l'utilisateur lorsqu'il aura clicker sur le button verra
aparaitre quelque chose dont il sait se servir et imprimer son fichier.

Christophe

Private Type STARTUPINFO
cb As Long
lpReserved As String
lpDesktop As String
lpTitle As String
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Long
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type

Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessID As Long
dwThreadID As Long
End Type

Private Const NORMAL_PRIORITY_CLASS = &H20&
Private Const INFINITE = -1&

Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal _
hHandle As Long, ByVal dwmilliseconds As Long) As Long
Private Declare Function CreateProcessA Lib "kernel32" (ByVal _
lpApplicationName As String, ByVal lpCommandLine As String, ByVal _
lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, _
ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, _
ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As String, _
lpStartupInfo As STARTUPINFO, lpProcessInformation As _
PROCESS_INFORMATION) As Long

Private Declare Function CloseHandle Lib "kernel32" _
(ByVal hObject As Long) As Long

Private Declare Function GetExitCodeProcess Lib "kernel32" _
(ByVal hProcess As Long, lpExitCode As Long) As Long


Private Function ExecCmd(cmdline$)
Dim Ret&
Dim proc As PROCESS_INFORMATION
Dim start As STARTUPINFO

' Initialize the STARTUPINFO structure:
start.cb = Len(start)

' Start the shelled application:
Ret& = CreateProcessA(vbNullString, cmdline$, 0&, 0&, 1&, _
NORMAL_PRIORITY_CLASS, 0&, vbNullString, start, proc)

' Wait for the shelled application to finish:
Ret& = WaitForSingleObject(proc.hProcess, INFINITE)
Call GetExitCodeProcess(proc.hProcess, Ret&)
Call CloseHandle(proc.hThread)
Call CloseHandle(proc.hProcess)
ExecCmd = Ret&
End Function

Private Command1_click()
mCheminRes = "notepad.exe " & "C:Monfichier.txt"
retval = ExecCmd(mCheminRes)
end sub





Rombeau Jonathan a écrit :

Je cherche comment imprimer un fichier txt sans devoir l'ouvrir ou du
moins sans devoir lire et retenir cela dans mon application.

Quelqu'un sait-il comment faire pour simplement dire : imprime le fichier
test.txt ?




Avatar
ng
Salut,

Ou tout simplement avec un ShellExecute() :

Private Declare Function ShellExecute Lib "shell32.dll" Alias
"ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal
lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String,
ByVal nShowCmd As Long) As Long
Const SW_SHOWNORMAL = 1

Private Sub Form_Load()
Call ShellExecute(Me.hwnd, "print", "c:1.txt", vbNullString, "C:",
SW_SHOWNORMAL)
End Sub


--
Nicolas G.
FAQ VB : http://faq.vb.free.fr
API Guide : http://www.allapi.net
Google Groups : http://groups.google.fr/
MZ-Tools : http://www.mztools.com/

Rombeau Jonathan wrote:
Je cherche comment imprimer un fichier txt sans devoir l'ouvrir ou du
moins sans devoir lire et retenir cela dans mon application.

Quelqu'un sait-il comment faire pour simplement dire : imprime le
fichier test.txt ?


Avatar
Rombeau Jonathan
Cela ne fonctionne je précise que je suis sous VB6 !!!


"ng" a écrit dans le message de news:
%
Salut,

Ou tout simplement avec un ShellExecute() :

Private Declare Function ShellExecute Lib "shell32.dll" Alias
"ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal
lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As
String, ByVal nShowCmd As Long) As Long
Const SW_SHOWNORMAL = 1

Private Sub Form_Load()
Call ShellExecute(Me.hwnd, "print", "c:1.txt", vbNullString, "C:",
SW_SHOWNORMAL)
End Sub


--
Nicolas G.
FAQ VB : http://faq.vb.free.fr
API Guide : http://www.allapi.net
Google Groups : http://groups.google.fr/
MZ-Tools : http://www.mztools.com/

Rombeau Jonathan wrote:
Je cherche comment imprimer un fichier txt sans devoir l'ouvrir ou du
moins sans devoir lire et retenir cela dans mon application.

Quelqu'un sait-il comment faire pour simplement dire : imprime le
fichier test.txt ?