您的批评和鼓励都是我把编程无限办好的动力! 您编程时遇到困难,或遇到不顺心的事想发发牢骚尽管到这里来吧! 虽然本网力求全面,但也不能包罗万象,这些我筛选出的优秀网站连接就是对本站最好的补充! 学习编程当然也离不开书本了,这里收集大量编程书籍! 编程无限之源码超市,这里收集的代码令你意想不到的全面! 欢迎光临编程网校,这里专门收集VB/CB入门文章及技术文章! 欢迎光临编程无限!
     
       
 
当前位置:英文资料 >> API
Start Notepad From An Application
  资料类型: API 上传时间: 2001-02-21 阅读次数: 2255



Sometimes it is useful to start notepad to show the readme file for example. This job is pretty easy by following the following code:

Place a CommandButton on a Form (Command1 is created by default).
Place this code in the Declarations Section of a module:
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, lpProcessInformation As PROCESS_INFORMATION) As Long

Declare Function OpenProcess Lib "kernel32.dll" (ByVal dwAccess As Long, ByVal fInherit As Integer, ByVal hObject As Long) As Long

Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long

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

Public Const SYNCHRONIZE = 1048576

Public Const NORMAL_PRIORITY_CLASS = &H20&

Type PROCESS_INFORMATION

hProcess As Long

hThread As Long

dwProcessId As Long

dwThreadId As Long

End Type

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

3. Now, Place This in the Command1_Click Event:

Dim pInfo As PROCESS_INFORMATION
Dim sInfo As STARTUPINFO
Dim sNull As String
Dim lReturn As Long

sInfo.cb = Len(sInfo)

lReturn = CreateProcess(sNull, "notepad.exe c:autoexec.bat", ByVal 0&, ByVal 0&, 1&, NORMAL_PRIORITY_CLASS, ByVal 0&, sNull, sInfo, pInfo)

MsgBox "Notepad has been started. Click OK to end it."

lReturn = TerminateProcess(pInfo.hProcess, 0&)

lReturn = CloseHandle(pInfo.hThread)

lReturn = CloseHandle(pInfo.hProcess)

MsgBox "Notepad has been shut down."


推荐给朋友 点 评( 1 ) 返回前页 关闭此页
   
  本类最热文章排名:
  1.keybd_event
2.How To Get The Machine Name
3.Restart or Exit Windows
4.How To Get The Current Users Name
5.WindowFromPoint
6.SendMessage
7.Startmenu shortcut
8.Improved DoEvents For NT Users
9.SelectObject Function
10.RemoveMenu
   
   
  评论:
  1.要这么麻烦吗,用Shell就不完了
 
 
 

 

关于本站 版权声明 联系方法
编程无限 V4.1 Copyright © 1999-2008 21code.com

京ICP备05006938号