再谈API函数ShellExecute,我看了以前的大富翁离线包,仍不能满意!(200分)

  • 主题发起人 主题发起人 a_fi
  • 开始时间 开始时间
A

a_fi

Unregistered / Unconfirmed
GUEST, unregistred user!
假如执行的exe文件如果既有路径又有参数(就象是dos下的 arj -e c:/a.txt d:/b.arj &lt;注意路径换了、文件名也换了&gt;),诸位大家继续深入探<br>讨一下如何?<br>大家可参阅和结合问题ID:278638及从前的离线包。我们把他汇总以下如何?<br>给最终分数时,我来做吧!<br><br>
 
检索一下,包你找到一大堆类似的问题。
 
ShellExecute 查找与指定文件关联在一起的程序的文件名 <br>返回值 <br>Long,非零表示成功,零表示失败。 <br>参数 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 类型及说明 <br>hwnd Long, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;指定一个窗口的句柄,有时候,windows程序有必要<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;在创 建自己的主窗口前显示一个消息框 <br>lpOperation String, &nbsp; 指定字串“open”来打开lpFlie文档,或指定<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; “Print”来打印它 <br>lpFile String, &nbsp; &nbsp; &nbsp; &nbsp; 想用关联程序打印或打开一个程序名或文件名 <br>lpParameters String, &nbsp; 如lpszFlie是可执行文件,则这个字串包含传递给<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 执行程序的参数 <br>lpDirectory String, &nbsp; &nbsp; 想使用的完整路径 <br>nShowCmd Long, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;定义了如何显示启动程序的常数值。 <br>
 
真是受不了,直接看msdn中的shellexecute帮助吧。<br><br>ShellExecute<br><br><br>HINSTANCE ShellExecute(<br>&nbsp; &nbsp; HWND hwnd, <br>&nbsp; &nbsp; LPCTSTR lpOperation,<br>&nbsp; &nbsp; LPCTSTR lpFile, <br>&nbsp; &nbsp; LPCTSTR lpParameters, <br>&nbsp; &nbsp; LPCTSTR lpDirectory,<br>&nbsp; &nbsp; INT nShowCmd<br>); <br>Opens or prints a specified file. <br><br>Returns a value greater than 32 if successful, or an error value that is less than or equal to 32 otherwise. The following table lists the error values. The return value is cast as an HINSTANCE for backward compatibility with 16-bit Windows applications. 0 &nbsp;The operating system is out of memory or resources. <br>ERROR_FILE_NOT_FOUND &nbsp;The specified file was not found. <br>ERROR_PATH_NOT_FOUND &nbsp;The specified path was not found. <br>ERROR_BAD_FORMAT &nbsp;The .exe file is invalid (non-Win32? .exe or error in .exe image). <br>SE_ERR_ACCESSDENIED &nbsp;The operating system denied access to the specified file. &nbsp;<br>SE_ERR_ASSOCINCOMPLETE &nbsp;The file name association is incomplete or invalid. <br>SE_ERR_DDEBUSY &nbsp;The DDE transaction could not be completed because other DDE transactions were being processed. <br>SE_ERR_DDEFAIL &nbsp;The DDE transaction failed. <br>SE_ERR_DDETIMEOUT &nbsp;The DDE transaction could not be completed because the request timed out. <br>SE_ERR_DLLNOTFOUND &nbsp;The specified dynamic-link library was not found. &nbsp;<br>SE_ERR_FNF &nbsp;The specified file was not found. &nbsp;<br>SE_ERR_NOASSOC &nbsp;There is no application associated with the given file name extension. <br>SE_ERR_OOM &nbsp;There was not enough memory to complete the operation. <br>SE_ERR_PNF &nbsp;The specified path was not found. <br>SE_ERR_SHARE &nbsp;A sharing violation occurred. <br><br>hwnd <br>Window handle to a parent window. This window receives any message boxes that an application produces. For example, an application may report an error by producing a message box. <br>lpOperation <br>Address of a null-terminated string that specifies the operation to perform. The following operation strings are valid: "open" &nbsp;The function opens the file specified by the lpFile parameter. The file can be an executable file or a document file. It can also be a folder. <br>"print" &nbsp;The function prints the file specified by lpFile. The file should be a document file. If the file is an executable file, the function opens the file, as if "open" had been specified. <br>"explore" &nbsp;The function explores the folder specified by lpFile. &nbsp;<br><br>This parameter can be NULL. In that case, the function opens the file specified by lpFile. <br><br>lpFile <br>Address of a null-terminated string that specifies the file to open or print or the folder to open or explore. The function can open an executable file or a document file. The function can print a document file. <br>lpParameters <br>If the lpFile parameter specifies an executable file, lpParameters is an address to a null-terminated string that specifies the parameters to be passed to the application. <br>If lpFile specifies a document file, lpParameters should be NULL. <br>lpDirectory <br>Address of a null-terminated string that specifies the default directory. <br>nShowCmd <br>If lpFile specifies an executable file, nShowCmd specifies how the application is to be shown when it is opened. This parameter can be one of the following values: SW_HIDE &nbsp;Hides the window and activates another window. <br>SW_MAXIMIZE &nbsp;Maximizes the specified window. <br>SW_MINIMIZE &nbsp;Minimizes the specified window and activates the next top-level window in the z-order. <br>SW_RESTORE &nbsp;Activates and displays the window. If the window is minimized or maximized, Windows restores it to its original size and position. An application should specify this flag when restoring a minimized window. <br>SW_SHOW &nbsp;Activates the window and displays it in its current size and position. &nbsp;<br>SW_SHOWDEFAULT &nbsp;Sets the show state based on the SW_ flag specified in theSTARTUPINFO structure passed to theCreateProcess function by the program that started the application. An application should callShowWindow with this flag to set the initial show state of its main window. <br>SW_SHOWMAXIMIZED &nbsp;Activates the window and displays it as a maximized window. <br>SW_SHOWMINIMIZED &nbsp;Activates the window and displays it as a minimized window. <br>SW_SHOWMINNOACTIVE &nbsp;Displays the window as a minimized window. The active window remains active. <br>SW_SHOWNA &nbsp;Displays the window in its current state. The active window remains active. <br>SW_SHOWNOACTIVATE &nbsp;Displays a window in its most recent size and position. The active window remains active. <br>SW_SHOWNORMAL &nbsp;Activates and displays a window. If the window is minimized or maximized, Windows restores it to its original size and position. An application should specify this flag when displaying the window for the first time. <br><br>If lpFile specifies a document file, nShowCmd should be zero. <br><br>You can use this function to open or explore a shell folder. To open a folder, use either of the following calls: <br><br>ShellExecute(handle, NULL, path_to_folder, NULL, NULL, SW_SHOWNORMAL);<br>or <br><br>ShellExecute(handle, "open", path_to_folder, NULL, NULL, SW_SHOWNORMAL);<br>To explore a folder, use the following call: <br><br>ShellExecute(handle, "explore", path_to_folder, NULL, NULL, SW_SHOWNORMAL);<br>If lpOperation is NULL, the function opens the file specified by lpFile. If lpOperation is "open" or "explore", the function will attempt to open or explore the folder. <br><br>To obtain information about the application that is launched as a result of calling ShellExecute, use ShellExecuteEx. <br><br><br>--------------------------------------------------------------------------------<br>
 
ShellExecute(Handle, "open", "d:/tool/arj.exe", "-e c:/a.txt d:/b.arj" , NULL, SW_SHOWNORMAL
 
诸位大富翁:<br>先感谢诸位的好意,但是大家没太明白我的意思:<br>除了可执行文件外,其余的参数(包括可执行文件的自身参数、源文件路径、源文件<br>名、生成文件路径、最终生成文件名等等)都是变量,这些变量是通过用户输入到<br>TEdit控件中或选择来得到的。我贴出源程序大家帮我看一看:<br><br>&nbsp;头文件声明: &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp;AnsiString Lastfilename; //定义进行处理后的文件名为全局变量<br>&nbsp; &nbsp; AnsiString Startfilename;//定义要进行处理的文件名为全局变量<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AnsiString Paragh;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; char *p;<br>&nbsp;源程序:<br><br>&nbsp;Paragh=" +自身参数"+" "+Startfilename+" "+Lastfilename;<br>&nbsp;p=Paragh.c_str();<br>&nbsp;ShellExecute(hwnd,"open","arj.exe",p,NULL,SW_SHOWNORMAL);<br><br>&nbsp;结果:<br>&nbsp; &nbsp;虽然成功调出arj.exe,但是参数p却未成功传递给arj.exe,因此只显示了作<br>者信息!<br>&nbsp;哪位曾做过此类程序,帮帮忙,有源程序发来,感激不尽!<br>&nbsp;大富翁离线浏览包和在线检索我都看了,没人作过这类东东!嗨!命苦~
 
运行 dos 命令还是 WinExec 吧.<br><br>我的例子<br>&nbsp; s := 'Command.com /c ';<br>&nbsp; s := s + 'dir /p c:/windows';<br>&nbsp; WinExec(PChar(s), SW_SHOWNORMAL);<br>
 
非常感谢SuperMMX!但是还是不象我的思路,解决不了.<br><br>我的思路:AnsiString Lastfilename; //定义进行处理后的文件名为全局变量<br>&nbsp; &nbsp; AnsiString Startfilename;//定义要进行处理的文件名为全局变量<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AnsiString Paragh;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; char *p;<br> 里面的Startfilename由用户通过OpenDialog选定,<br>而Lastfilename都是通过Tedit控件由用户来自己键入;这两个都是变量,源程序见上面<br>&nbsp;Paragh=" +自身参数"+" "+Startfilename+" "+Lastfilename;//参数传递给变量<br>&nbsp;p=Paragh.c_str();//将AnsiString类型转换为字符串类型<br>最后调用了<br>ShellExecute(ShellExecute(hwnd,"open","arj.exe",p,NULL,SW_SHOWNORMAL);<br>但结果还是没能成功传递参数,但程序arj已成功调用!<br><br>解决此问题者,单独另加100分,决不食言!<br>&nbsp;
 
char *p;<br>确认p已分配内存.<br>或 char p[MAX_PATH];
 
winexec 运行 dos 程序最好, 参数也简单, 你按照我的写法写一下,<br>注意之间的空格, 还有长文件名要加 " ";<br>String 缺省是 AnsiString, 我没有 arj.exe 要不然替你写好了,<br>要举一反三, shellexecute 有时候也不好用.
 
SuperMMX的方法可行<br>运行Dos程序,用WinExec比用ShellExecute方便<br>运行Windows程序,最好反过来
 
我强烈建议你不要用ARJ,<br>换个dELPHI 的 PKZIP控件会好很多。<br>请你认真考虑。<br>除非你赶时间编程,不然对你自己也是一个提高,<br>程序也不会那么依靠外部的程序
 
这么简单的问题不值200分吧<br>_DosCmd='ARJ A OVT C:/ZK/LIB/*.* -R -Y -V1440'<br>DECLARE INTEGER WinExec IN win32api STRING, INTEGER<br>jk=WinExec(@_DosCmd, 0) <br>以上是在VFP下的编程<br>
 
&nbsp; 首先 arj.exe命令格式:arj.exe &lt;command&gt; &nbsp;&lt;开关参数 &gt; &nbsp;文件参数<br>&nbsp; &nbsp;不能没有命令参数 否则出错<br><br>&nbsp; 》引用 &nbsp;AnsiString Lastfilename; //定义进行处理后的文件名为全局变量<br>&nbsp; &nbsp; AnsiString Startfilename;//定义要进行处理的文件名为全局变量<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AnsiString Paragh; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br><br>&nbsp; &nbsp;char *p; &nbsp;//这里去掉这个定义<br><br> 里面的Startfilename由用户通过OpenDialog选定, <br><br>&nbsp; //注意 此时当前路径转换为 OpenDialog打开文件时的路径 <br>&nbsp; 即 使用执行文件本身的当前路径方式无法找到 ARJ。EXE <br><br>&nbsp;而Lastfilename都是通过Tedit控件由用户来自己键入;这两个都是变量,源程序见上面<br><br>&nbsp;Paragh= '自身参数'+' '+Startfilename+' '+Lastfilename; //参数传递给变量<br>&nbsp; //这里注意 不同命令要求 Startfilename Lastfilename 的顺序可能不一样<br>&nbsp;<br>&nbsp;p=Paragh.c_str();//将AnsiString类型转换为字符串类型最后调用了<br>&nbsp;//这里去掉上面的一句 事实上使用 Pchar() 或者 PAnsiChar() 来实现转换<br><br>&nbsp;ShellExecute(ShellExecute(hwnd,"open","arj.exe",Pchar(Paragh),NULL,SW_SHOWNORMAL);<br>&nbsp;//这里直接使用Pchar() 将Paragh转换为 Pchar 类型<br><br>&nbsp;在上面以往还有一个问题是 arj.exe 必须是支持win9x 长文件名称的版本<br>&nbsp;我专门下载了实验通过了的 <br>&nbsp;试一试吧? 记得给我分啊 &nbsp;:-) 我要做富翁啊 :-)<br><br>&nbsp;如果还不行给我写信 我把源代码给你<br>
 
这是我曾经用的一段程序.应该符合您的要求.<br>procedure TForm1.Button3Click(Sender: TObject);<br>&nbsp;var &nbsp;S:string;<br>begin<br>&nbsp; TEMP := TSTRINGLIST.Create;<br>&nbsp; s:='COMMAND.COM /C nbtstat -A &nbsp;'+pchar(edit1.text)+' &gt;c:/B.txt';<br>&nbsp; WinExec(PChar(s), SW_HIDE);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ~~~~~~~~ <br>end;
 
&nbsp; 没有下文了所
 
Lastfilename: String; //定义进行处理后的文件名为全局变量<br>Startfilename: String;//定义要进行处理的文件名为全局变量<br>Paragh: String;<br>...<br>begin<br>&nbsp;...<br>&nbsp;Paragh:==' 自身参数'+' '+Startfilename+' '+Lastfilename;<br>&nbsp;ShellExecute(Handle,'open','arj.exe',PChar(Paragh),'arj的路径',SW_ShowNormal);<br>&nbsp;...<br>end;
 
非常感谢诸位的热情帮助!<br><br>我用winexec做成功了!<br>本来想总结一下,但是我看到诸位说得都非常好,不必总结了!<br><br>收获很多——遇到问题,怎么办?<br><br>1。上大富翁。<br>2。查以往的问题检索。<br>3。问诸位大富翁。<br><br>最后瓜分!
 
后退
顶部