ini dr arsip milis :
Step-by-Step Example
1. Start a new project in Visual Basic. Form1 is created by default.
2. Add the following code to the General Declarations section of Form1:
Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessId As Long
dwThreadId As Long
End Type
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 Declare Function CreateProcess Lib "kernel32" Alias _
"CreateProcessA" (ByVal lpApplicationName As String, ByVal _
lpCommandLine As String, lpProcessAttributes As Any, _
lpThreadAttributes As Any, ByVal bInheritHandles As Long, _
ByVal dwCreationFlags As Long, lpEnvironment As Any, ByVal _
lpCurrentDriectory As String, lpStartupInfo As STARTUPINFO, _
lpProcessInformatio n As PROCESS_INFORMATION ) As Long
Private Declare Function OpenProcess Lib "kernel32.dll" (ByVal _
dwAccess As Long, ByVal fInherit As Integer, ByVal hObject _
As Long) As Long
Private Declare Function TerminateProcess Lib "kernel32" (ByVal _
hProcess As Long, ByVal uExitCode As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal _
hObject As Long) As Long
Const SYNCHRONIZE = 1048576
Const NORMAL_PRIORITY_ CLASS = &H20&
3. Add the following code to the Form1_Click event:
Dim pInfo As PROCESS_INFORMATION
Dim sInfo As STARTUPINFO Dim sNull As String
Dim success
Dim ret
sInfo.cb = Len(sInfo)
success = CreateProcess( sNull, "Calc.exe", ByVal 0&, ByVal 0&, _
1&, NORMAL_PRIORITY_ CLASS, ByVal 0&, sNull, sInfo,
pInfo)
' ProcessID& = Shell("Calc.exe", vbNormalFocus)
' ProcessHandle& = OpenProcess(SYNCHRONIZE, True, ProcessID&)
MsgBox "Calculator has been launched!"
ret = TerminateProcess( pInfo.hProcess, 0&)
ret = CloseHandle( pInfo.hThread)
ret = CloseHandle( pInfo.hProcess)
' ret = TerminateProcess( ProcessHandle&, 0&)
' ret = CloseHandle( ProcessHandle&)
' ret = CloseHandle( ProcessHandle&)
MsgBox "Calculator has terminated!"
4. Press the F5 key to run the program. Click Form1. The Windows Calculator
program launches, and a message tells you so. When you click the OK button on
the MsgBox, the Calculator program terminates, and another message tells you so.
To see how this method works using the Shell and OpenProcess method, change the
commented code into executed code, change the rest of the code into comments
except for the two MsgBox statements.
Silakan di modiv dan dicoba
-----Original Message-----
From: [email protected] [mailto:[EMAIL PROTECTED] Behalf Of
saripudin hidayat
Sent: 03 Maret 2008 15:29
To: Ilmu Komputer Programming; Programmer VB; Wahana Programmer; thebad kalong
Cc: Nando Gurning; Cafe Techno; Wiewie Liu
Subject: [Programmer-VB] Buka File dari textbox
Dear VBers
Saya mempunyai teksboks yang berisi nama sebuah file, misalnya:
surat.doc
anggaran.xls
project.ppt
bagaimana koding VB-nya agar ketika saya keypress enter, file tersebut
langsung terbuka di jendela softwarenya sesuai dengan file ekstensionnya.
Contohnya ekstension .doc langsung terbuka di jendela word. Terima kasih atas
perhatiannya.
Best Regard
Saripudin Hidayat
------------------------------------------------------------------------------
Bergabunglah dengan orang-orang yang berwawasan, di bidang Anda di Yahoo!
Answers